def Search( item ): search_data = [] try: search_data = OSDBServer().searchsubtitles(item) except: log( __name__, "failed to connect to service for subtitle search") xbmc.executebuiltin((u'Notification(%s,%s)' % (__scriptname__ , __language__(32001))).encode('utf-8')) return if search_data != None: search_data.sort(key=lambda x: [not x['MatchedBy'] == 'moviehash', not os.path.splitext(x['SubFileName'])[0] == os.path.splitext(os.path.basename(urllib.unquote(xbmc.Player().getPlayingFile().decode('utf-8'))))[0], not normalizeString(xbmc.getInfoLabel("VideoPlayer.OriginalTitle")).lower() in x['SubFileName'].replace('.',' ').lower(), not x['LanguageName'] == PreferredSub]) for item_data in search_data: ## hack to work around issue where Brazilian is not found as language in XBMC if item_data["LanguageName"] == "Brazilian": item_data["LanguageName"] = "Portuguese (Brazil)" listitem = xbmcgui.ListItem(label = item_data["LanguageName"], label2 = item_data["SubFileName"], iconImage = str(int(round(float(item_data["SubRating"])/2))), thumbnailImage = item_data["ISO639"] ) listitem.setProperty( "sync", ("false", "true")[str(item_data["MatchedBy"]) == "moviehash"] ) listitem.setProperty( "hearing_imp", ("false", "true")[int(item_data["SubHearingImpaired"]) != 0] ) url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s&format=%s" % (__scriptid__, item_data["ZipDownloadLink"], item_data["IDSubtitleFile"], item_data["SubFileName"], item_data["SubFormat"] ) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=listitem,isFolder=False)
def Search(item): search_data = [] try: search_data = OSDBServer().searchsubtitles(item) except: log(__name__, "failed to connect to service for subtitle search") xbmc.executebuiltin( (u'Notification(%s,%s)' % (__scriptname__, __language__(32001))).encode('utf-8')) return if search_data != None: if isinstance(search_data, dict): log(__name__, "received data has a new format, convert it to list") search_data = [v for v in search_data.values()] search_data.sort(key=lambda x: [ not x['MatchedBy'] == 'moviehash', not os.path. splitext(x['SubFileName'])[0] == os.path.splitext( os.path.basename(urllib.unquote(item['file_original_path'])))[ 0], not normalizeString( xbmc.getInfoLabel("VideoPlayer.OriginalTitle")).lower( ) in x['SubFileName'].replace('.', ' ').lower(), not x[ 'LanguageName'] == PreferredSub ]) for item_data in search_data: ## hack to work around issue where Brazilian is not found as language in XBMC if item_data["LanguageName"] == "Brazilian": item_data["LanguageName"] = "Portuguese (Brazil)" if ((item['season'] == item_data['SeriesSeason'] and item['episode'] == item_data['SeriesEpisode']) or (item['season'] == "" and item['episode'] == "" ) ## for file search, season and episode == "" ): listitem = xbmcgui.ListItem( label=item_data["LanguageName"], label2=item_data["SubFileName"], iconImage=str(int(round(float(item_data["SubRating"]) / 2))), thumbnailImage=item_data["ISO639"]) listitem.setProperty( "sync", ("false", "true")[str(item_data["MatchedBy"]) == "moviehash"]) listitem.setProperty( "hearing_imp", ("false", "true")[int(item_data["SubHearingImpaired"]) != 0]) url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s&format=%s" % ( __scriptid__, item_data["ZipDownloadLink"], item_data["IDSubtitleFile"], item_data["SubFileName"], item_data["SubFormat"]) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=False)
def Download(link, url, referer, trdtr): subtitle_list = [] exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"] log(__name__, "Download Using HTTP") s = requests.Session() ua = 'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1' headers = {'User-Agent': ua} referer = 'http://www.titrari.ro/index.php?page=cautare&z1=0&z2=' + referer + '&z3=1&z4=1' s.headers.update({'referer': referer}) link = 'http://www.titrari.ro/get.php?id=' + link file = s.get(link, headers=headers) contentType = file.headers['Content-Disposition'].split(';') Type = 'rar' if contentType[1][-5:] == '.rar"' else 'zip' fname = "%s.%s" % (os.path.join(__temp__, "subtitle"), Type) with open(fname, 'wb') as f: f.write(file.content) extractPath = os.path.join(__temp__, "Extracted") xbmc.executebuiltin("XBMC.Extract(%s, %s)" % (fname, extractPath)) xbmc.sleep(1000) for root, dirs, files in os.walk(extractPath): for file in files: dirfile = os.path.join(root, file) dirfile_with_path_name = normalizeString(os.path.relpath(dirfile, extractPath)) dirname, basename = os.path.split(dirfile_with_path_name) dirname = re.sub(r"[/\\]{1,10}", "-", dirname) dirfile_with_path_name = "(%s) %s" % (dirname, basename) if len(dirname) else basename #new_dirfile = os.path.join(extractPath, safeFilename(dirfile_with_path_name)) if (os.path.splitext(file)[1] in exts): #extension = file[file.rfind('.') + 1:] subtitle_list.append(dirfile) #index += 1 selected = [] #f = open( '/storage/.kodi/temp/files2.py', 'w' ) #f.write( 'url = ' + repr(contentType) + '\n' ) #f.close() if xbmcvfs.exists(subtitle_list[0]): subtitle_list_s = natcasesort(subtitle_list) dialog = xbmcgui.Dialog() sel = dialog.select("%s\n%s" % ('Traducator: ', trdtr), [os.path.basename(x) for x in subtitle_list_s]) if sel >= 0: selected.append(subtitle_list_s[sel]) return selected else: return None else: return None
def Download(link, url, format, trdtr): #headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'} subtitle_list = [] exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"] log(__name__, "Download Using HTTP") ua = 'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1' req = urllib2.Request(link) req.add_header('User-Agent', ua) a = urllib2.urlopen(link) contentType = a.info()['Content-Disposition'].split(';') b = a.read() Type = 'rar' if contentType[1][-4:] == '.rar' else 'zip' fname = "%s.%s" % (os.path.join(__temp__, "subtitle"), Type) with open(fname, 'wb') as f: f.write(b) extractPath = os.path.join(__temp__, "Extracted") xbmc.executebuiltin("XBMC.Extract(%s, %s)" % (fname, extractPath)) xbmc.sleep(1000) for root, dirs, files in os.walk(extractPath): for file in files: dirfile = os.path.join(root, file) dirfile_with_path_name = normalizeString(os.path.relpath(dirfile, extractPath)) dirname, basename = os.path.split(dirfile_with_path_name) dirname = re.sub(r"[/\\]{1,10}", "-", dirname) dirfile_with_path_name = "(%s) %s" % (dirname, basename) if len(dirname) else basename #new_dirfile = os.path.join(extractPath, safeFilename(dirfile_with_path_name)) if (os.path.splitext(file)[1] in exts): #extension = file[file.rfind('.') + 1:] subtitle_list.append(dirfile) #index += 1 selected = [] #f = open( '/storage/.kodi/temp/files2.py', 'w' ) #f.write( 'url = ' + repr(contentType) + '\n' ) #f.close() if xbmcvfs.exists(subtitle_list[0]): subtitle_list_s = sorted(subtitle_list, key=natural_key) dialog = xbmcgui.Dialog() sel = dialog.select("%s\n%s" % ('Traducator: ', trdtr), [os.path.basename(x) for x in subtitle_list_s]) if sel >= 0: selected.append(subtitle_list_s[sel]) return selected else: return None else: return None
return param params = get_params() if params['action'] == 'search' or params['action'] == 'manualsearch': log(__name__, "action '%s' called" % params['action']) item = {} item['temp'] = False item['rar'] = False item['mansearch'] = False item['year'] = xbmc.getInfoLabel("VideoPlayer.Year") # Year item['season'] = str(xbmc.getInfoLabel("VideoPlayer.Season")) # Season item['episode'] = str(xbmc.getInfoLabel("VideoPlayer.Episode")) # Episode item['tvshow'] = normalizeString( xbmc.getInfoLabel("VideoPlayer.TVshowtitle")) # Show item['title'] = normalizeString( xbmc.getInfoLabel( "VideoPlayer.OriginalTitle")) # try to get original title item['file_original_path'] = urllib.unquote( xbmc.Player().getPlayingFile().decode( 'utf-8')) # Full path of a playing file item['3let_language'] = [] #['scc','eng'] item['1let_language'] = [] #['scc','eng'] if 'searchstring' in params: item['mansearch'] = True item['mansearchstr'] = params['searchstring'] for lang in urllib.unquote(params['languages']).decode('utf-8').split(","): if lang == "Portuguese (Brazil)":
param[splitparams[0]]=splitparams[1] return param params = get_params() if params['action'] == 'search' or params['action'] == 'manualsearch': log( __name__, "action '%s' called" % params['action']) item = {} item['temp'] = False item['rar'] = False item['mansearch'] = False item['year'] = xbmc.getInfoLabel("VideoPlayer.Year") # Year item['season'] = str(xbmc.getInfoLabel("VideoPlayer.Season")) # Season item['episode'] = str(xbmc.getInfoLabel("VideoPlayer.Episode")) # Episode item['tvshow'] = normalizeString(xbmc.getInfoLabel("VideoPlayer.TVshowtitle")) # Show item['title'] = normalizeString(xbmc.getInfoLabel("VideoPlayer.OriginalTitle"))# try to get original title item['file_original_path'] = xbmc.Player().getPlayingFile().decode('utf-8') # Full path of a playing file item['3let_language'] = [] #['scc','eng'] PreferredSub = params.get('preferredlanguage') if 'searchstring' in params: item['mansearch'] = True item['mansearchstr'] = params['searchstring'] for lang in urllib.unquote(params['languages']).decode('utf-8').split(","): if lang == "Portuguese (Brazil)": lan = "pob" elif lang == "Greek": lan = "ell" else:
def Search(item): search_data = [] try: search_data = OSDBServer().searchsubtitles(item) except: log(__name__, "failed to connect to service for subtitle search") xbmc.executebuiltin( (u'Notification(%s,%s)' % (__scriptname__, __language__(32001))).encode('utf-8')) return if search_data != None: search_data.sort(key=lambda x: [ not x['MatchedBy'] == 'moviehash', not os.path. splitext(x['SubFileName'])[0] == os.path.splitext( os.path.basename(urllib.unquote(item['file_original_path'])))[ 0], not normalizeString( xbmc.getInfoLabel("VideoPlayer.OriginalTitle")).lower( ) in x['SubFileName'].replace('.', ' ').lower(), not x[ 'LanguageName'] == PreferredSub ]) listitems = [] for item_data in search_data: ## hack to work around issue where Brazilian is not found as language in XBMC if item_data["LanguageName"] == "Brazilian": item_data["LanguageName"] = "Portuguese (Brazil)" if ((item['season'] == item_data['SeriesSeason'] and item['episode'] == item_data['SeriesEpisode']) or (item['season'] == "" and item['episode'] == "" ) ## for file search, season and episode == "" ): listitem = xbmcgui.ListItem( label=item_data["LanguageName"], label2=item_data["SubFileName"], iconImage=str(int(round(float(item_data["SubRating"]) / 2))), thumbnailImage=item_data["ISO639"]) listitem.setProperty( "sync", ("false", "true")[str(item_data["MatchedBy"]) == "moviehash"]) listitem.setProperty( "hearing_imp", ("false", "true")[int(item_data["SubHearingImpaired"]) != 0]) url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s&format=%s" % ( __scriptid__, item_data["ZipDownloadLink"], item_data["IDSubtitleFile"], item_data["SubFileName"], item_data["SubFormat"]) listitems.append(listitem) if (__addon__.getSetting('dualsub_enable') != 'true'): xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=False) if (__addon__.getSetting('dualsub_enable') == 'true'): dialog = xbmcgui.Dialog() ret = dialog.multiselect("Choose a subtitle", [i for i in listitems], useDetails=True) if ret and len(ret) > 0: subs = [] for sub in ret: subs.append({ 'ID': search_data[sub]['IDSubtitleFile'], 'link': search_data[sub]['ZipDownloadLink'], 'filename': search_data[sub]['SubFileName'], 'format': search_data[sub]['SubFormat'] }) payload = json.dumps(subs[:2]) payload = urllib.quote(payload) listitem = xbmcgui.ListItem(label2=__language__(32019)) url = "plugin://%s/?action=download&payload=%s" % ( __scriptid__, payload) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=False)