def setup_variables( self ): self.controlId = -1 self.allow_exception = False self.osdb_server = OSDBServer() self.osdb_server.Create() if xbmc.Player().isPlayingVideo(): self.set_filepath( xbmc.Player().getPlayingFile() )
def setup_variables(self): #try: xbox = xbmc.getInfoLabel( "system.xboxversion") xbox = "" if xbox == "": self.set_xbox = False else: self.set_xbox = True LOG(LOG_INFO, "XBOX System: [%s]", xbox) self.controlId = -1 self.allow_exception = False self.osdb_server = OSDBServer() self.osdb_server.Create() self.manuall = False
def setup_variables(self): try: xbox = xbmc.getInfoLabel("system.xboxversion") except: xbox = "" if xbox == "": self.set_xbox = False else: self.set_xbox = True if self.debug: LOG(LOG_INFO, "XBOX detected") self.controlId = -1 self.osdb_server = OSDBServer() self.manuall = False
def setup_variables( self ): try: xbox = xbmc.getInfoLabel( "system.xboxversion") except:xbox = "" if xbox == "": self.set_xbox = False else: self.set_xbox = True if self.debug : LOG( LOG_INFO, "XBOX detected" ) self.controlId = -1 self.osdb_server = OSDBServer() self.manuall = False
def setup_variables(self): # try: xbox = xbmc.getInfoLabel( "system.xboxversion") xbox = "" if xbox == "": self.set_xbox = False else: self.set_xbox = True LOG(LOG_INFO, "XBOX System: [%s]", xbox) self.controlId = -1 self.allow_exception = False self.osdb_server = OSDBServer() self.osdb_server.Create() self.manuall = False
class GUI(xbmcgui.WindowXMLDialog): socket.setdefaulttimeout(10.0) #seconds def __init__(self, *args, **kwargs): pass def set_lang(self, lang1, lang2): self.lang1 = toOpenSubtitlesId(lang1) LOG(LOG_INFO, "Language 1: [%s]", self.lang1) self.lang2 = toOpenSubtitlesId(lang2) LOG(LOG_INFO, "Language 2: [%s]", self.lang2) def set_session(self, session_id): self.session_id = session_id def set_service(self, service): self.service = service LOG(LOG_INFO, "Service used: [%s]", self.service) def set_temp(self, temp): self.set_temp = temp def set_sub_folder(self, sub_folder): self.sub_folder = sub_folder LOG(LOG_INFO, "Subtitle Folder: [%s]", self.sub_folder) def set_filepath(self, path): self.file_original_path = path if not (path.find("special://") > -1): self.file_path = path[path.find(os.sep):len(path)] else: self.file_path = path LOG(LOG_INFO, "File Path: [%s]", self.file_path) def set_filehash(self, hash): LOG(LOG_INFO, "File Hash: [%s]", (hash)) self.file_hash = hash def set_filesize(self, size): LOG(LOG_INFO, "File Size: [%s]", (size)) self.file_size = size def set_searchstring(self, search): LOG(LOG_INFO, "Search String: [%s]", (search)) self.search_string = search def set_subtitles(self, subtitles): self.subtitles = subtitles def onInit(self): LOG(LOG_INFO, "onInit") self.setup_all() if self.service == "OpenSubtitles": self.connThread = threading.Thread(target=self.connect, args=()) self.connThread.start() else: self.connect() def setup_all(self): self.setup_variables() self.getControl(300).setLabel(_(601)) self.getControl(301).setLabel(_(602)) def setup_variables(self): #try: xbox = xbmc.getInfoLabel( "system.xboxversion") xbox = "" if xbox == "": self.set_xbox = False else: self.set_xbox = True LOG(LOG_INFO, "XBOX System: [%s]", xbox) self.controlId = -1 self.allow_exception = False self.osdb_server = OSDBServer() self.osdb_server.Create() self.manuall = False def connect(self): self.getControl(SUBTITLES_LIST).reset() self.getControl(110).setVisible(False) self.getControl(111).setVisible(False) self.getControl(STATUS_LABEL).setLabel(_(646)) if self.service == "OpenSubtitles": self.getControl(110).setVisible(True) ok, msg = self.osdb_server.connect(OSDB_SERVER, "", "") if not ok: self.getControl(STATUS_LABEL).setLabel(_(653)) LOG(LOG_INFO, "Login Failed: [%s]", msg) # label = "" # label2 = "[COLOR=FFFF0000]%s[/COLOR]" % ( _( 611 ) ) # listitem = xbmcgui.ListItem( label,label2 ) # self.getControl( SUBTITLES_LIST ).addItem( listitem ) # label2 = "[COLOR=FF00FF00]%s[/COLOR]" % ( _( 612 ) ) # listitem = xbmcgui.ListItem( label,label2 ) # self.getControl( SUBTITLES_LIST ).addItem( listitem ) self.getControl(STATUS_LABEL).setLabel(_(635)) self.search_subtitles() self.getControl(STATUS_LABEL).setVisible(True) else: self.getControl(STATUS_LABEL).setLabel(_(635)) LOG(LOG_INFO, "Login Sucessful: [%s]", msg) ##self.osdb_server.getlanguages() self.search_subtitles() self.getControl(STATUS_LABEL).setVisible(True) else: self.getControl(111).setVisible(True) self.getControl(STATUS_LABEL).setLabel(_(646)) self.search_subtitles_sub() def search_subtitles(self): ok = False ok2 = False ok3 = False msg = "" self.getControl(STATUS_LABEL).setLabel(_(646)) try: if (len(self.file_path) > 0) and not self.file_original_path.find( "http") > -1 and not self.set_xbox: LOG( LOG_INFO, "Search by hash " + os.path.basename(self.file_original_path)) self.getControl(STATUS_LABEL).setLabel(_(642) % ("...", )) self.set_filehash(hashFile(self.file_original_path)) self.set_filesize(os.path.getsize(self.file_original_path)) try: ok, msg = self.osdb_server.searchsubtitles( self.file_original_path, self.file_hash, self.file_size, self.lang1, self.lang2) #, "en" ) except: ok = False LOG(LOG_INFO, "Hash Search: " + msg) if (len(self.search_string) > 0): LOG(LOG_INFO, "Search by name " + self.search_string) self.getControl(STATUS_LABEL).setLabel(_(642) % ("......", )) ok2, msg2 = self.osdb_server.searchsubtitlesbyname( self.search_string, self.lang1) #, "en" ) LOG(LOG_INFO, "Name Search: " + msg2) ok3, msg3 = self.osdb_server.searchsubtitlesbyname_alt( self.search_string, self.lang2, self.lang1) #, "en" ) LOG(LOG_INFO, "Name 2 Search: " + msg3) self.osdb_server.mergesubtitles() if not ok and not ok2 and not ok3: self.getControl(STATUS_LABEL).setLabel(_(634) % (msg, )) if self.osdb_server.subtitles_list: label = "" label2 = "[COLOR=FFFF0000]%s[/COLOR]" % (_(611)) listitem = xbmcgui.ListItem(label, label2) self.getControl(SUBTITLES_LIST).addItem(listitem) label2 = "[COLOR=FF00FF00]%s[/COLOR]" % (_(612)) listitem = xbmcgui.ListItem(label, label2) self.getControl(SUBTITLES_LIST).addItem(listitem) for item in self.osdb_server.subtitles_list: listitem = xbmcgui.ListItem( label=item["language_name"], label2=item["filename"], iconImage=item["rating"], thumbnailImage=item["language_flag"]) if item["sync"]: listitem.setProperty("sync", "true") else: listitem.setProperty("sync", "false") self.getControl(SUBTITLES_LIST).addItem(listitem) else: label = "" label2 = "[COLOR=FFFF0000]%s[/COLOR]" % (_(611)) listitem = xbmcgui.ListItem(label, label2) self.getControl(SUBTITLES_LIST).addItem(listitem) label2 = "[COLOR=FF00FF00]%s[/COLOR]" % (_(612)) listitem = xbmcgui.ListItem(label, label2) self.getControl(SUBTITLES_LIST).addItem(listitem) movie_title1 = self.search_string.replace("+", " ") self.getControl(STATUS_LABEL).setLabel( _(744) % ( str(len(self.osdb_server.subtitles_list)), movie_title1, )) self.setFocus(self.getControl(SUBTITLES_LIST)) self.getControl(SUBTITLES_LIST).selectItem(0) except Exception, e: error = _(634) % ("search_subtitles:" + str(e)) LOG(LOG_ERROR, error) return False, error
class GUI(xbmcgui.WindowXMLDialog): socket.setdefaulttimeout(10.0) # seconds def __init__(self, *args, **kwargs): pass def set_lang(self, lang1, lang2): self.lang1 = toOpenSubtitlesId(lang1) LOG(LOG_INFO, "Language 1: [%s]", self.lang1) self.lang2 = toOpenSubtitlesId(lang2) LOG(LOG_INFO, "Language 2: [%s]", self.lang2) def set_session(self, session_id): self.session_id = session_id def set_service(self, service): self.service = service LOG(LOG_INFO, "Service used: [%s]", self.service) def set_temp(self, temp): self.set_temp = temp def set_sub_folder(self, sub_folder): self.sub_folder = sub_folder LOG(LOG_INFO, "Subtitle Folder: [%s]", self.sub_folder) def set_filepath(self, path): self.file_original_path = path if not (path.find("special://") > -1): self.file_path = path[path.find(os.sep) : len(path)] else: self.file_path = path LOG(LOG_INFO, "File Path: [%s]", self.file_path) def set_filehash(self, hash): LOG(LOG_INFO, "File Hash: [%s]", (hash)) self.file_hash = hash def set_filesize(self, size): LOG(LOG_INFO, "File Size: [%s]", (size)) self.file_size = size def set_searchstring(self, search): LOG(LOG_INFO, "Search String: [%s]", (search)) self.search_string = search def set_subtitles(self, subtitles): self.subtitles = subtitles def onInit(self): LOG(LOG_INFO, "onInit") self.setup_all() if self.service == "OpenSubtitles": self.connThread = threading.Thread(target=self.connect, args=()) self.connThread.start() else: self.connect() def setup_all(self): self.setup_variables() self.getControl(300).setLabel(_(601)) self.getControl(301).setLabel(_(602)) def setup_variables(self): # try: xbox = xbmc.getInfoLabel( "system.xboxversion") xbox = "" if xbox == "": self.set_xbox = False else: self.set_xbox = True LOG(LOG_INFO, "XBOX System: [%s]", xbox) self.controlId = -1 self.allow_exception = False self.osdb_server = OSDBServer() self.osdb_server.Create() self.manuall = False def connect(self): self.getControl(SUBTITLES_LIST).reset() self.getControl(110).setVisible(False) self.getControl(111).setVisible(False) self.getControl(STATUS_LABEL).setLabel(_(646)) if self.service == "OpenSubtitles": self.getControl(110).setVisible(True) ok, msg = self.osdb_server.connect(OSDB_SERVER, "", "") if not ok: self.getControl(STATUS_LABEL).setLabel(_(653)) LOG(LOG_INFO, "Login Failed: [%s]", msg) # label = "" # label2 = "[COLOR=FFFF0000]%s[/COLOR]" % ( _( 611 ) ) # listitem = xbmcgui.ListItem( label,label2 ) # self.getControl( SUBTITLES_LIST ).addItem( listitem ) # label2 = "[COLOR=FF00FF00]%s[/COLOR]" % ( _( 612 ) ) # listitem = xbmcgui.ListItem( label,label2 ) # self.getControl( SUBTITLES_LIST ).addItem( listitem ) self.getControl(STATUS_LABEL).setLabel(_(635)) self.search_subtitles() self.getControl(STATUS_LABEL).setVisible(True) else: self.getControl(STATUS_LABEL).setLabel(_(635)) LOG(LOG_INFO, "Login Sucessful: [%s]", msg) ##self.osdb_server.getlanguages() self.search_subtitles() self.getControl(STATUS_LABEL).setVisible(True) else: self.getControl(111).setVisible(True) self.getControl(STATUS_LABEL).setLabel(_(646)) self.search_subtitles_sub() def search_subtitles(self): ok = False ok2 = False ok3 = False msg = "" self.getControl(STATUS_LABEL).setLabel(_(646)) try: if (len(self.file_path) > 0) and not self.file_original_path.find("http") > -1 and not self.set_xbox: LOG(LOG_INFO, "Search by hash " + os.path.basename(self.file_original_path)) self.getControl(STATUS_LABEL).setLabel(_(642) % ("...",)) self.set_filehash(hashFile(self.file_original_path)) self.set_filesize(os.path.getsize(self.file_original_path)) try: ok, msg = self.osdb_server.searchsubtitles( self.file_original_path, self.file_hash, self.file_size, self.lang1, self.lang2 ) # , "en" ) except: ok = False LOG(LOG_INFO, "Hash Search: " + msg) if len(self.search_string) > 0: LOG(LOG_INFO, "Search by name " + self.search_string) self.getControl(STATUS_LABEL).setLabel(_(642) % ("......",)) ok2, msg2 = self.osdb_server.searchsubtitlesbyname(self.search_string, self.lang1) # , "en" ) LOG(LOG_INFO, "Name Search: " + msg2) ok3, msg3 = self.osdb_server.searchsubtitlesbyname_alt( self.search_string, self.lang2, self.lang1 ) # , "en" ) LOG(LOG_INFO, "Name 2 Search: " + msg3) self.osdb_server.mergesubtitles() if not ok and not ok2 and not ok3: self.getControl(STATUS_LABEL).setLabel(_(634) % (msg,)) if self.osdb_server.subtitles_list: label = "" label2 = "[COLOR=FFFF0000]%s[/COLOR]" % (_(611)) listitem = xbmcgui.ListItem(label, label2) self.getControl(SUBTITLES_LIST).addItem(listitem) label2 = "[COLOR=FF00FF00]%s[/COLOR]" % (_(612)) listitem = xbmcgui.ListItem(label, label2) self.getControl(SUBTITLES_LIST).addItem(listitem) for item in self.osdb_server.subtitles_list: listitem = xbmcgui.ListItem( label=item["language_name"], label2=item["filename"], iconImage=item["rating"], thumbnailImage=item["language_flag"], ) if item["sync"]: listitem.setProperty("sync", "true") else: listitem.setProperty("sync", "false") self.getControl(SUBTITLES_LIST).addItem(listitem) else: label = "" label2 = "[COLOR=FFFF0000]%s[/COLOR]" % (_(611)) listitem = xbmcgui.ListItem(label, label2) self.getControl(SUBTITLES_LIST).addItem(listitem) label2 = "[COLOR=FF00FF00]%s[/COLOR]" % (_(612)) listitem = xbmcgui.ListItem(label, label2) self.getControl(SUBTITLES_LIST).addItem(listitem) movie_title1 = self.search_string.replace("+", " ") self.getControl(STATUS_LABEL).setLabel(_(744) % (str(len(self.osdb_server.subtitles_list)), movie_title1)) self.setFocus(self.getControl(SUBTITLES_LIST)) self.getControl(SUBTITLES_LIST).selectItem(0) except Exception, e: error = _(634) % ("search_subtitles:" + str(e)) LOG(LOG_ERROR, error) return False, error
class GUI( xbmcgui.WindowXMLDialog ): def __init__( self, *args, **kwargs ): pass def set_filepath( self, path ): LOG( LOG_INFO, "set_filepath" ) self.filepath = path[path.find("/"):len(path)] def onInit( self ): LOG( LOG_INFO, "onInit" ) self.setup_all() if self.settings["username"]: self.getControl( 100 ).setLabel( _( 637 ) % ( self.settings["username"], ) ) ok,msg = self.osdb_server.connect( self.settings["osdb_server"], self.settings["username"], self.settings["password"] ) else: self.getControl( 100 ).setLabel( _( 636 ) ) ok,msg = self.osdb_server.connect( self.settings["osdb_server"], "", "" ) if not ok: self.getControl( 100 ).setLabel( _( 634 ) % ( msg, ) ) else: self.getControl( 100 ).setLabel( _( 635 ) ) self.osdb_server.getlanguages() if self.filepath: self.search_subtitles() else: self.setFocus( self.getControl( 111 ) ) def setup_all( self ): self.setup_variables() self.get_settings() def get_settings( self ): self.settings = Settings().get_settings() def setup_variables( self ): self.controlId = -1 self.allow_exception = False self.osdb_server = OSDBServer() self.osdb_server.Create() if xbmc.Player().isPlayingVideo(): self.set_filepath( xbmc.Player().getPlayingFile() ) def search_subtitles( self ): self.getControl( 100 ).setLabel( _( 642 ) % ( os.path.basename( self.filepath ), ) ) ok,msg = self.osdb_server.searchsubtitles( self.filepath ) if not ok: self.getControl( 100 ).setLabel( _( 634 ) % ( msg, ) ) self.setFocus( self.getControl( 111 ) ) elif self.osdb_server.subtitles_list: for item in self.osdb_server.subtitles_list: self.getControl( 120 ).addItem( xbmcgui.ListItem( item["filename"], item["language_name"], thumbnailImage = item["language_flag"] ) ) self.getControl( 120 ).selectItem( 0 ) self.getControl( 100 ).setLabel( msg ) self.setFocus( self.getControl( 120 ) ) elif msg: self.getControl( 100 ).setLabel( msg ) self.setFocus( self.getControl( 111 ) ) def show_control( self, controlId ): self.getControl( 100 ).setVisible( controlId == 100 ) self.getControl( 120 ).setVisible( controlId == 120 ) page_control = ( controlId == 100 ) try: self.setFocus( self.getControl( controlId + page_control ) ) except: self.setFocus( self.getControl( controlId ) ) def file_download(self, url, dest): dp = xbmcgui.DialogProgress() dp.create( __scriptname__, _( 633 ), os.path.basename(dest) ) urllib.urlretrieve( url, dest, lambda nb, bs, fs, url=url: self._pbhook( nb, bs, fs, url, dp ) ) def _pbhook(self, numblocks, blocksize, filesize, url=None, dp=None): try: percent = min( ( numblocks*blocksize*100 ) / filesize, 100 ) print percent dp.update(percent) except: percent = 100 dp.update( percent ) if dp.iscanceled(): print "Subtitle download cancelled" # need to get this part working dp.close() def downloadsubtitle(self, pos): if self.osdb_server.subtitles_list: filename = self.osdb_server.subtitles_list[pos]["filename"] filename = filename[0:filename.rfind(".")] + ".zip" remote_path = os.path.dirname( self.filepath ) local_path = os.path.dirname( self.settings["subtitles_path"] ) url = self.osdb_server.subtitles_list[pos]["link"] self.getControl( 100 ).setLabel( _( 632 ) % ( filename, ) ) self.file_download( url, os.path.join( local_path, filename ) ) if os.path.exists( os.path.join( local_path, filename ) ): un = unzip.unzip() self.getControl( 100 ).setLabel( _( 631 ) % ( filename, os.path.dirname( local_path ) ) ) un.extract( os.path.join( local_path, filename ), local_path ) if self.settings["save_to_videofile_path"]: self.getControl( 100 ).setLabel( _( 631 ) % ( filename, os.path.dirname( remote_path ), ) ) un.extract( os.path.join( local_path, filename ), remote_path ) self.getControl( 100 ).setLabel( _( 630 ) ) def reset_controls( self ): self.getControl( 100 ).setLabel( "" ) self.getControl( 120 ).reset() def search_dialog( self ): self.reset_controls() dialog = xbmcgui.Dialog() self.filepath = dialog.browse(1, _( 640 ), 'video') self.search_subtitles() def change_settings( self ): self.getControl( 100 ).setVisible( False ) self.getControl( 110 ).setVisible( False ) self.getControl( 120 ).setVisible( False ) import settings settings = settings.GUI( "script-%s-settings.xml" % ( __scriptname__.replace( " ", "_" ), ), os.getcwd(), "Default" ) settings.doModal() ok = False if ( settings.changed ): self.get_settings() if ( settings.restart ): ok = xbmcgui.Dialog().yesno( __scriptname__, _( 240 ), "", _( 241 ) % ( __scriptname__, ), _( 256 ), _( 255 ) ) if ok: self.exit_script( True ) del settings self.getControl( 100 ).setVisible( True ) self.getControl( 110 ).setVisible( True ) self.getControl( 120 ).setVisible( True ) def exit_script( self, restart=False ): self.close() if ( restart ): xbmc.executebuiltin( "XBMC.RunScript(%s)" % ( os.path.join( os.getcwd().replace( ";", "" ), "default.py" ), ) ) def onClick( self, controlId ): if ( self.controlId == 112 ): self.change_settings() elif ( self.controlId == 111 ): self.search_dialog() elif ( self.controlId == 120 ): self.downloadsubtitle( self.getControl( 120 ).getSelectedPosition() ) def onFocus( self, controlId ): self.controlId = controlId def onAction( self, action ): if ( action.getButtonCode() in EXIT_SCRIPT ): self.exit_script()
class GUI( xbmcgui.WindowXMLDialog ): def __init__( self, *args, **kwargs ): pass def set_session(self,session_id): self.session_id = session_id def set_allparam(self, path,search,temp,sub_folder, year,debug): self.debug = debug # debug? self.year = year # Year lang1 = toScriptLang(__settings__.getSetting( "Language1" )) # Full language 1 lang2 = toScriptLang(__settings__.getSetting( "Language2" )) # Full language 2 lang3 = toScriptLang(__settings__.getSetting( "Language3" )) # Full language 2 self.lang1 = toOpenSubtitlesId( lang1 ) # 2 letter language 1 self.lang_two1 = toOpenSubtitles_two(lang1) # 3 letter language 1 self.lang2 = toOpenSubtitlesId( lang2 ) # 2 letter language 2 self.lang_two2 = toOpenSubtitles_two(lang2) # 3 letter language 2 self.lang3 = toOpenSubtitlesId( lang3 ) # 2 letter language 3 self.lang_two3 = toOpenSubtitles_two(lang3) # 3 letter language 3 self.sub_folder = sub_folder # Subtitle download folder self.file_original_path = urllib.unquote ( path ) # Movie Path self.file_path = urllib.unquote( path ) self.set_temp = temp self.search_string1 = unicode(search, 'utf-8') # de-accent Search String self.search_string = unicodedata.normalize('NFKD', unicode(self.search_string1)).encode('ascii','ignore') if (__settings__.getSetting( "fil_name" ) == "true"): # Display Movie name or search string self.file_name = os.path.basename( path ) else: self.file_name = self.search_string.replace("+"," ") if self.year != 0 and self.year != "" : self.file_name = self.file_name + " (" + str(self.year) + ")" #### ---------------------------- Set Service ----------------------------### self.service = "" self.OS = __settings__.getSetting( "OS" ) == "true" if self.OS and ( __settings__.getSetting( "defservice") == "2") : self.service = "OpenSubtitles" self.PN = __settings__.getSetting( "PN" ) == "true" self.username = __settings__.getSetting( "PNuser" ) self.password = __settings__.getSetting( "PNpass" ) if self.PN and len(self.username) > 1 and len(self.password) >1 : if ( __settings__.getSetting( "defservice") == "1"): self.service = "Podnapisi" else: self.PN = False self.SL = __settings__.getSetting( "SL" ) == "true" if self.SL and ( __settings__.getSetting( "defservice") == "0"): self.service = "Sublight" if self.service == "" : if self.PN and len(self.username) > 1 and len(self.password) >1 : self.service = "Podnapisi" else: self.PN = False if self.SL: self.service = "Sublight" if self.OS: self.service = "OpenSubtitles" if not self.SL and not self.OS and not self.PN: import xbmcgui dialog = xbmcgui.Dialog() possibleChoices = ["Sublight", "OpenSubtitles","Podnapisi"] choice = dialog.select( _( 505 ) , possibleChoices) self.service = "" if choice == 0: self.service = "Sublight" self.SL = True if choice == 1: self.service = "OpenSubtitles" self.OS = True if choice == 2: if len(self.username) > 1 and len(self.password) >1 : self.service = "Podnapisi" self.PN = True else: dialog = xbmcgui.Dialog() selected = dialog.ok("OpenSubtitles_OSD", "Podnapisi service requires username and password", "Register at www.podnapisi.net and enter it", "in script settings menu" ) __settings__.openSettings() self.username = __settings__.getSetting( "PNuser" ) self.password = __settings__.getSetting( "PNpass" ) if len(self.username) > 1 and len(self.password) >1 : self.PN = True self.service = "Podnapisi" else: return -1 #### ---------------------------- end set Service ----------------------------### self.mansearch = __settings__.getSetting( "searchstr" ) == "true" # Manual search string?? self.list = [] self.pos = -1 if self.SL : self.pos = self.pos +1 if self.OS : self.pos = self.pos +1 if self.PN : self.pos = self.pos +1 service_num = self.pos if self.mansearch : self.pos = self.pos +1 if self.debug : ## Debug? LOG( LOG_INFO, "Manual Search : [%s]" , self.mansearch ) LOG( LOG_INFO, "Service : [%s]" , self.service ) LOG( LOG_INFO, "SL Service : [%s]" , self.SL ) LOG( LOG_INFO, "PN Service : [%s]" , self.PN ) LOG( LOG_INFO, "OS Service : [%s]" , self.OS ) LOG( LOG_INFO, "Search String: [%s]" , self.search_string ) LOG( LOG_INFO, "Temp?: [%s]" , self.set_temp ) LOG( LOG_INFO, "File Path: [%s]" , self.file_path ) LOG( LOG_INFO, "Year: [%s]" , str(self.year) ) LOG( LOG_INFO, "Subtitle Folder: [%s]" , self.sub_folder ) LOG( LOG_INFO, "Language 1: [%s]" , self.lang1 ) LOG( LOG_INFO, "Language 2: [%s]" , self.lang2 ) LOG( LOG_INFO, "Language 3: [%s]" , self.lang3 ) return service_num #### ---------------------------- End Set All ----------------------------### def set_filehash(self): hashFile(self.file_original_path) self.file_hash = hashFile(self.file_original_path) if self.debug : LOG( LOG_INFO, "File Hash: [%s]" , ( self.file_hash ) ) return self.file_hash def set_filesize( self, size ): if self.debug : LOG( LOG_INFO, "File Size: [%s]" , ( size ) ) self.file_size = size def set_subtitles( self, subtitles ): self.subtitles = subtitles def onInit( self ): if self.debug : LOG( LOG_INFO, "onInit" ) self.setup_all() def setup_all( self ): self.getControl( 300 ).setLabel( _( 601 ) ) self.getControl( 301 ).setLabel( _( 602 ) ) self.setup_variables() self.connect() def setup_variables( self ): try: xbox = xbmc.getInfoLabel( "system.xboxversion") except:xbox = "" if xbox == "": self.set_xbox = False else: self.set_xbox = True if self.debug : LOG( LOG_INFO, "XBOX detected" ) self.controlId = -1 self.osdb_server = OSDBServer() self.manuall = False def connect( self ): self.getControl( SUBTITLES_LIST ).reset() self.osdb_server.Create(self.debug) if self.service == "OpenSubtitles": self.getControl( 111 ).setVisible( False ) self.getControl( 110 ).setVisible( True ) self.connected = True self.getControl( STATUS_LABEL ).setLabel( _( 635 ) ) self.search_subtitles() if self.service == "Sublight": self.getControl( 110 ).setVisible( False ) self.getControl( 111 ).setVisible( True ) self.getControl( STATUS_LABEL ).setLabel( _( 646 ) ) self.search_subtitles_sub() if self.service == "Podnapisi": self.getControl( 110 ).setVisible( False ) self.getControl( 111 ).setVisible( False ) self.getControl( STATUS_LABEL ).setLabel( _( 646 ) ) self.search_subtitles_pod() ###-------------------------- OS search -------------################ def search_subtitles( self ): self.getControl( STATUS_LABEL ).setLabel( _( 646 ) ) ok = False msg = "" if self.file_original_path.find("http") > -1 or self.set_xbox == True : hash_search = False else: hash_search = True try: if hash_search : hashTry = timeout(self.set_filehash, timeout_duration=5) if self.debug : LOG( LOG_INFO, "Search by hash and name " + os.path.basename( self.file_original_path ) ) self.getControl( STATUS_LABEL ).setLabel( _( 642 ) % ( "...", ) ) self.set_filesize ( os.path.getsize( self.file_original_path ) ) try : ok,msg = self.osdb_server.searchsubtitles( self.search_string, hashTry,self.file_size,self.lang1,self.lang2,self.lang3,self.year,hash_search ) except: self.connected = False if self.debug : LOG( LOG_INFO, "Hash and Name Search: " + msg ) else: if self.debug : LOG( LOG_INFO, "Search by Name " + self.file_original_path ) self.getControl( STATUS_LABEL ).setLabel( _( 642 ) % ( "...", ) ) try : ok,msg = self.osdb_server.searchsubtitles( self.search_string, "000000000" ,"000000000",self.lang1,self.lang2,self.lang3,self.year,hash_search ) except: self.connected = False if self.debug : LOG( LOG_INFO, "Name Search: " + msg ) self.osdb_server.mergesubtitles() if not ok: self.getControl( STATUS_LABEL ).setLabel( _( 634 ) % ( msg, ) ) label = "" self.list = [] if self.SL : label2 = "[COLOR=FFFF0000]%s[/COLOR]" % ( _( 610 ) + "Sublight.si" ) listitem = xbmcgui.ListItem( label,label2 ) self.list.append("SL") self.getControl( SUBTITLES_LIST ).addItem( listitem ) if self.PN : label2 = "[COLOR=FFFF0000]%s[/COLOR]" % ( _( 610 ) + "Podnapisi.net" ) listitem = xbmcgui.ListItem( label,label2 ) self.list.append("PN") self.getControl( SUBTITLES_LIST ).addItem( listitem ) if self.mansearch : label2 = "[COLOR=FF00FF00]%s[/COLOR]" % ( _( 612 ) ) listitem = xbmcgui.ListItem( label,label2 ) self.list.append("MN") self.getControl( SUBTITLES_LIST ).addItem( listitem ) if self.osdb_server.subtitles_list: subscounter = 0 for item in self.osdb_server.subtitles_list: listitem = xbmcgui.ListItem( label=item["language_name"], label2=item["filename"], iconImage=item["rating"], thumbnailImage=item["language_flag"] ) if item["sync"]: listitem.setProperty( "sync", "true" ) else: listitem.setProperty( "sync", "false" ) self.list.append(subscounter) subscounter = subscounter + 1 self.getControl( SUBTITLES_LIST ).addItem( listitem ) self.getControl( STATUS_LABEL ).setLabel(( str( len ( self.osdb_server.subtitles_list ) )) + _( 744 ) + '"' + self.file_name + '"' ) self.setFocus( self.getControl( SUBTITLES_LIST ) ) self.getControl( SUBTITLES_LIST ).selectItem( 0 ) except Exception, e: error = _( 634 ) % ( "search_subtitles:" + str ( e ) ) LOG( LOG_ERROR, error ) return False, error
class GUI(xbmcgui.WindowXMLDialog): def __init__(self, *args, **kwargs): pass def set_session(self, session_id): self.session_id = session_id def set_allparam(self, path, search, temp, sub_folder, year, debug): self.debug = debug # debug? self.year = year # Year lang1 = toScriptLang( __settings__.getSetting("Language1")) # Full language 1 lang2 = toScriptLang( __settings__.getSetting("Language2")) # Full language 2 lang3 = toScriptLang( __settings__.getSetting("Language3")) # Full language 2 self.lang1 = toOpenSubtitlesId(lang1) # 2 letter language 1 self.lang_two1 = toOpenSubtitles_two(lang1) # 3 letter language 1 self.lang2 = toOpenSubtitlesId(lang2) # 2 letter language 2 self.lang_two2 = toOpenSubtitles_two(lang2) # 3 letter language 2 self.lang3 = toOpenSubtitlesId(lang3) # 2 letter language 3 self.lang_two3 = toOpenSubtitles_two(lang3) # 3 letter language 3 self.sub_folder = sub_folder # Subtitle download folder self.file_original_path = urllib.unquote(path) # Movie Path self.file_path = urllib.unquote(path) self.set_temp = temp self.search_string1 = unicode(search, 'utf-8') # de-accent Search String self.search_string = unicodedata.normalize( 'NFKD', unicode(self.search_string1)).encode('ascii', 'ignore') if (__settings__.getSetting("fil_name") == "true" ): # Display Movie name or search string self.file_name = os.path.basename(path) else: self.file_name = self.search_string.replace("+", " ") if self.year != 0 and self.year != "": self.file_name = self.file_name + " (" + str(self.year) + ")" #### ---------------------------- Set Service ----------------------------### self.service = "" self.OS = __settings__.getSetting("OS") == "true" if self.OS and (__settings__.getSetting("defservice") == "2"): self.service = "OpenSubtitles" self.PN = __settings__.getSetting("PN") == "true" self.username = __settings__.getSetting("PNuser") self.password = __settings__.getSetting("PNpass") if self.PN and len(self.username) > 1 and len(self.password) > 1: if (__settings__.getSetting("defservice") == "1"): self.service = "Podnapisi" else: self.PN = False self.SL = __settings__.getSetting("SL") == "true" if self.SL and (__settings__.getSetting("defservice") == "0"): self.service = "Sublight" if self.service == "": if self.PN and len(self.username) > 1 and len(self.password) > 1: self.service = "Podnapisi" else: self.PN = False if self.SL: self.service = "Sublight" if self.OS: self.service = "OpenSubtitles" if not self.SL and not self.OS and not self.PN: import xbmcgui dialog = xbmcgui.Dialog() possibleChoices = ["Sublight", "OpenSubtitles", "Podnapisi"] choice = dialog.select(_(505), possibleChoices) self.service = "" if choice == 0: self.service = "Sublight" self.SL = True if choice == 1: self.service = "OpenSubtitles" self.OS = True if choice == 2: if len(self.username) > 1 and len(self.password) > 1: self.service = "Podnapisi" self.PN = True else: dialog = xbmcgui.Dialog() selected = dialog.ok( "OpenSubtitles_OSD", "Podnapisi service requires username and password", "Register at www.podnapisi.net and enter it", "in script settings menu") __settings__.openSettings() self.username = __settings__.getSetting("PNuser") self.password = __settings__.getSetting("PNpass") if len(self.username) > 1 and len(self.password) > 1: self.PN = True self.service = "Podnapisi" else: return -1 #### ---------------------------- end set Service ----------------------------### self.mansearch = __settings__.getSetting( "searchstr") == "true" # Manual search string?? self.list = [] self.pos = -1 if self.SL: self.pos = self.pos + 1 if self.OS: self.pos = self.pos + 1 if self.PN: self.pos = self.pos + 1 service_num = self.pos if self.mansearch: self.pos = self.pos + 1 if self.debug: ## Debug? LOG(LOG_INFO, "Manual Search : [%s]", self.mansearch) LOG(LOG_INFO, "Service : [%s]", self.service) LOG(LOG_INFO, "SL Service : [%s]", self.SL) LOG(LOG_INFO, "PN Service : [%s]", self.PN) LOG(LOG_INFO, "OS Service : [%s]", self.OS) LOG(LOG_INFO, "Search String: [%s]", self.search_string) LOG(LOG_INFO, "Temp?: [%s]", self.set_temp) LOG(LOG_INFO, "File Path: [%s]", self.file_path) LOG(LOG_INFO, "Year: [%s]", str(self.year)) LOG(LOG_INFO, "Subtitle Folder: [%s]", self.sub_folder) LOG(LOG_INFO, "Language 1: [%s]", self.lang1) LOG(LOG_INFO, "Language 2: [%s]", self.lang2) LOG(LOG_INFO, "Language 3: [%s]", self.lang3) return service_num #### ---------------------------- End Set All ----------------------------### def set_filehash(self): hashFile(self.file_original_path) self.file_hash = hashFile(self.file_original_path) if self.debug: LOG(LOG_INFO, "File Hash: [%s]", (self.file_hash)) return self.file_hash def set_filesize(self, size): if self.debug: LOG(LOG_INFO, "File Size: [%s]", (size)) self.file_size = size def set_subtitles(self, subtitles): self.subtitles = subtitles def onInit(self): if self.debug: LOG(LOG_INFO, "onInit") self.setup_all() def setup_all(self): self.getControl(300).setLabel(_(601)) self.getControl(301).setLabel(_(602)) self.setup_variables() self.connect() def setup_variables(self): try: xbox = xbmc.getInfoLabel("system.xboxversion") except: xbox = "" if xbox == "": self.set_xbox = False else: self.set_xbox = True if self.debug: LOG(LOG_INFO, "XBOX detected") self.controlId = -1 self.osdb_server = OSDBServer() self.manuall = False def connect(self): self.getControl(SUBTITLES_LIST).reset() self.osdb_server.Create(self.debug) if self.service == "OpenSubtitles": self.getControl(111).setVisible(False) self.getControl(110).setVisible(True) self.connected = True self.getControl(STATUS_LABEL).setLabel(_(635)) self.search_subtitles() if self.service == "Sublight": self.getControl(110).setVisible(False) self.getControl(111).setVisible(True) self.getControl(STATUS_LABEL).setLabel(_(646)) self.search_subtitles_sub() if self.service == "Podnapisi": self.getControl(110).setVisible(False) self.getControl(111).setVisible(False) self.getControl(STATUS_LABEL).setLabel(_(646)) self.search_subtitles_pod() ###-------------------------- OS search -------------################ def search_subtitles(self): self.getControl(STATUS_LABEL).setLabel(_(646)) ok = False msg = "" if self.file_original_path.find("http") > -1 or self.set_xbox == True: hash_search = False else: hash_search = True try: if hash_search: hashTry = timeout(self.set_filehash, timeout_duration=5) if self.debug: LOG( LOG_INFO, "Search by hash and name " + os.path.basename(self.file_original_path)) self.getControl(STATUS_LABEL).setLabel(_(642) % ("...", )) self.set_filesize(os.path.getsize(self.file_original_path)) try: ok, msg = self.osdb_server.searchsubtitles( self.search_string, hashTry, self.file_size, self.lang1, self.lang2, self.lang3, self.year, hash_search) except: self.connected = False if self.debug: LOG(LOG_INFO, "Hash and Name Search: " + msg) else: if self.debug: LOG(LOG_INFO, "Search by Name " + self.file_original_path) self.getControl(STATUS_LABEL).setLabel(_(642) % ("...", )) try: ok, msg = self.osdb_server.searchsubtitles( self.search_string, "000000000", "000000000", self.lang1, self.lang2, self.lang3, self.year, hash_search) except: self.connected = False if self.debug: LOG(LOG_INFO, "Name Search: " + msg) self.osdb_server.mergesubtitles() if not ok: self.getControl(STATUS_LABEL).setLabel(_(634) % (msg, )) label = "" self.list = [] if self.SL: label2 = "[COLOR=FFFF0000]%s[/COLOR]" % (_(610) + "Sublight.si") listitem = xbmcgui.ListItem(label, label2) self.list.append("SL") self.getControl(SUBTITLES_LIST).addItem(listitem) if self.PN: label2 = "[COLOR=FFFF0000]%s[/COLOR]" % (_(610) + "Podnapisi.net") listitem = xbmcgui.ListItem(label, label2) self.list.append("PN") self.getControl(SUBTITLES_LIST).addItem(listitem) if self.mansearch: label2 = "[COLOR=FF00FF00]%s[/COLOR]" % (_(612)) listitem = xbmcgui.ListItem(label, label2) self.list.append("MN") self.getControl(SUBTITLES_LIST).addItem(listitem) if self.osdb_server.subtitles_list: subscounter = 0 for item in self.osdb_server.subtitles_list: listitem = xbmcgui.ListItem( label=item["language_name"], label2=item["filename"], iconImage=item["rating"], thumbnailImage=item["language_flag"]) if item["sync"]: listitem.setProperty("sync", "true") else: listitem.setProperty("sync", "false") self.list.append(subscounter) subscounter = subscounter + 1 self.getControl(SUBTITLES_LIST).addItem(listitem) self.getControl(STATUS_LABEL).setLabel( (str(len(self.osdb_server.subtitles_list))) + _(744) + '"' + self.file_name + '"') self.setFocus(self.getControl(SUBTITLES_LIST)) self.getControl(SUBTITLES_LIST).selectItem(0) except Exception, e: error = _(634) % ("search_subtitles:" + str(e)) LOG(LOG_ERROR, error) return False, error
class GUI( xbmcgui.WindowXMLDialog ): socket.setdefaulttimeout(10.0) #seconds def __init__( self, *args, **kwargs ): pass def set_filepath( self, path ): LOG( LOG_INFO, "set_filepath [%s]" , ( path ) ) self.file_original_path = path self.file_path = path[path.find(os.sep):len(path)] def set_filehash( self, hash ): LOG( LOG_INFO, "set_filehash [%s]" , ( hash ) ) self.file_hash = hash def set_filesize( self, size ): LOG( LOG_INFO, "set_filesize [%s]" , ( size ) ) self.file_size = size def set_searchstring( self, search ): LOG( LOG_INFO, "set_searchstring [%s]" , ( search ) ) self.search_string = search def onInit( self ): LOG( LOG_INFO, "onInit" ) self.setup_all() if self.file_path or self.search_string: #self.timer = threading.Timer( 0.5, self.connect(), () ) #self.timer.start() self.connThread = threading.Thread( target=self.connect, args=() ) self.connThread.start() def setup_all( self ): self.setup_variables() def setup_variables( self ): self.controlId = -1 self.allow_exception = False self.osdb_server = OSDBServer() self.osdb_server.Create() if xbmc.Player().isPlayingVideo(): self.set_filepath( xbmc.Player().getPlayingFile() ) def connect( self ): self.getControl( LOADING_IMAGE ).setVisible( True ) self.getControl( STATUS_LABEL ).setLabel( _( 646 ) ) ok,msg = self.osdb_server.connect( "", "" ) if not ok: self.getControl( STATUS_LABEL ).setLabel( _( 653 ) ) self.getControl( LOADING_IMAGE ).setVisible( False ) return else: self.getControl( STATUS_LABEL ).setLabel( _( 635 ) ) self.osdb_server.getlanguages() self.search_subtitles() self.getControl( LOADING_IMAGE ).setVisible( False ) self.getControl( STATUS_LABEL ).setVisible( False ) def search_subtitles( self ): try: if ( len( self.file_path ) > 0 ): LOG( LOG_INFO, _( 642 ) % ( os.path.basename( self.file_path ), ) ) self.getControl( STATUS_LABEL ).setLabel( _( 642 ) % ( "...", ) ) #ok,msg = self.osdb_server.searchsubtitlesbyhash( self.file_path )#, "en" ) self.set_filehash( xbmc.getFileHash( self.file_original_path ) ) self.set_filesize( xbmc.getFileSize( self.file_original_path ) ) ok,msg = self.osdb_server.searchsubtitles( self.file_path, self.file_hash, self.file_size )#, "en" ) LOG( LOG_INFO, msg ) if ( len( self.search_string ) > 0 ): LOG( LOG_INFO, _( 642 ) % ( os.path.basename( self.search_string ), ) ) self.getControl( STATUS_LABEL ).setLabel( _( 642 ) % ( "......", ) ) ok2,msg2 = self.osdb_server.searchsubtitlesbyname( self.search_string )#, "en" ) LOG( LOG_INFO, msg2 ) self.osdb_server.mergesubtitles() if not ok and not ok2: self.getControl( STATUS_LABEL ).setLabel( _( 634 ) % ( msg, ) ) elif self.osdb_server.subtitles_list: for item in self.osdb_server.subtitles_list: listitem = xbmcgui.ListItem( label=item["language_name"], label2=item["filename"], iconImage=item["rating"], thumbnailImage=item["language_flag"] ) #self.getControl( SUBTITLES_LIST ).addItem( xbmcgui.ListItem( item["filename"], item["language_name"], iconImage=item["rating"], thumbnailImage = item["language_flag"] ) ) if item["sync"]: listitem.setProperty( "sync", "true" ) else: listitem.setProperty( "sync", "false" ) self.getControl( SUBTITLES_LIST ).addItem( listitem ) # elif msg: # self.getControl( STATUS_LABEL ).setLabel( msg ) self.setFocus( self.getControl( SUBTITLES_LIST ) ) self.getControl( SUBTITLES_LIST ).selectItem( 0 ) except Exception, e: error = _( 634 ) % ( "search_subtitles:" + str ( e ) ) LOG( LOG_ERROR, error ) return False, error