Skip to content

Commit

Permalink
Added storing of Bierdopje show ids to reduce the number of api calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-blobby committed Jan 30, 2011
1 parent 5b10bfd commit 3605df9
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions script.xbmc.subtitles/resources/lib/services/Bierdopje/service.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os, sys, re, xbmc, xbmcgui, string, urllib, ElementTree as XMLTree
from utilities import log

_ = sys.modules[ "__main__" ].__language__

apiurl = "http://api.bierdopje.com/"
apikey = "369C2ED4261DE9C3"
_ = sys.modules[ "__main__" ].__language__
__cwd__ = sys.modules[ "__main__" ].__cwd__
apiurl = "http://api.bierdopje.com/"
apikey = "369C2ED4261DE9C3"
showids_filename = os.path.join( xbmc.translatePath( "special://profile/" ), "addon_data", os.path.basename( __cwd__ ),"bierdopje_show_ids.txt" )

#====================================================================================================================
# Functions
Expand Down Expand Up @@ -49,24 +50,34 @@ def gettextelements(xml, path):
return textelements

def getshowid(showname):
showids = {}
if os.path.isfile(showids_filename):
showids_filedata = file(showids_filename,'r').read()
showids = eval(showids_filedata)
if showname in showids:
log( __name__ ," show id for '%s' is '%s' (from cachefile '%s')" % (showname, showids[showname], showids_filename))
return showids[showname]
response = apicall("GetShowByName",[showname])
if response is not None:
showid = gettextelements(response,"response/showid")
if len(showid) == 1:
log( __name__ ," show id for '%s' is '%s'" % (showname, str(showid[0])) )
showids[showname] = str(showid[0])
file(showids_filename,'w').write(repr(showids))
return str(showid[0])
else:
elif ("'" in showname):
response = apicall("GetShowByName",[string.replace(showname,"'","''")])
if response is not None:
showid = gettextelements(response,"response/showid")
if len(showid) == 1:
log( __name__ ," show id for '%s' is '%s' (replaced ' with '')" % (string.replace(showname,"'","''"), str(showid[0])) )
showids[showname] = str(showid[0])
file(showids_filename,'w').write(repr(showids))
return str(showid[0])
else:
okdialog = xbmcgui.Dialog()
ok = okdialog.ok("Error", "Failed to get a show id from Bierdopje for " + showname)
log( __name__ ," failed to get a show id for '%s'" % showname )

okdialog = xbmcgui.Dialog()
ok = okdialog.ok("Error", "Failed to get a show id from Bierdopje for " + showname)
log( __name__ ," failed to get a show id for '%s'" % showname )


def isexactmatch(subsfile, moviefile):
match = re.match("(.*)\.", moviefile)
Expand Down

0 comments on commit 3605df9

Please sign in to comment.