def Download(link, filename, referer): subtitle_list = [] if not link: return subtitle_list log(__name__, "Downloadlink %s" % link) class MyOpener(urllib.FancyURLopener): version = "Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko" my_urlopener = MyOpener() my_urlopener.addheader('Referer', referer) log(__name__, referer) postparams = None log( __name__, "Fetching subtitles using url '%s' with referer header '%s' and post parameters '%s'" % (link, link, postparams)) response = my_urlopener.open(link, postparams) local_tmp_file = os.path.join(__temp__, "sub.srt") if xbmcvfs.exists(__temp__): shutil.rmtree(__temp__) xbmcvfs.mkdirs(__temp__) try: log(__name__, "Saving subtitles to '%s'" % local_tmp_file) local_file_handle = open(local_tmp_file, "wb") local_file_handle.write(response.read()) local_file_handle.close() subtitle_list.append(local_tmp_file) log(__name__, "=== returning subtitle file %s" % file) except: log(__name__, "Failed to save subtitle to %s" % local_tmp_file) return subtitle_list
def Search(item): log(__name__, item) subs = search_tvshow(item['tvshow'], item['season'], item['episode'], item['2let_language']) for sub in subs: append_subtitle(sub)
if (item['file_original_path'].find("http") > -1): item['temp'] = True elif (item['file_original_path'].find("rar://") > -1): item['rar'] = True item['file_original_path'] = os.path.dirname( item['file_original_path'][6:]) elif (item['file_original_path'].find("stack://") > -1): stackPath = item['file_original_path'].split(" , ") item['file_original_path'] = stackPath[0][8:] # required if tvshow is not indexed/recognized in library if item['tvshow'] == "": log(__name__, "item %s" % item) # replace dots with spaces in title titulo = re.sub(r'\.', ' ', item['title']) log(__name__, "title no dots: %s" % titulo) mo = re.search(r'(.*)[sS](\d+)[eE](\d+)', titulo) #S01E02 like if not mo: mo = re.search(r'(.*)(\d\d)[xX](\d+)', titulo) # old 10x02 style if not mo: mo = re.search(r'(.*)(\d)[xX](\d+)', titulo) # old 1x02 style if not mo: mo = re.search(r'(.*) (\d+)(\d\d)', titulo) # 102 style # split title in tvshow, season and episode if mo: item['tvshow'] = mo.group(1) if item['tvshow'].endswith(' - '): item['tvshow'] = item['tvshow'][:-3]
def Download(link, filename, referer): subtitle_list = [] if not link: return subtitle_list log(__name__, "Downloadlink %s" % link) class MyOpener(urllib.FancyURLopener): version = "Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko" my_urlopener = MyOpener() my_urlopener.addheader('Referer', referer) log(__name__, referer) postparams = None log(__name__, "Fetching subtitles using url '%s' with referer header '%s' and post parameters '%s'" % (link, link, postparams)) response = my_urlopener.open(link, postparams) local_tmp_file = os.path.join(__temp__, "sub.srt") if xbmcvfs.exists(__temp__): shutil.rmtree(__temp__) xbmcvfs.mkdirs(__temp__) try: log(__name__, "Saving subtitles to '%s'" % local_tmp_file) local_file_handle = open(local_tmp_file, "wb") local_file_handle.write(response.read()) local_file_handle.close() subtitle_list.append(local_tmp_file) log(__name__, "=== returning subtitle file %s" % file) except: log(__name__, "Failed to save subtitle to %s" % local_tmp_file) return subtitle_list
item['episode'] = item['episode'][-1:] if ( item['file_original_path'].find("http") > -1 ): item['temp'] = True elif ( item['file_original_path'].find("rar://") > -1 ): item['rar'] = True item['file_original_path'] = os.path.dirname(item['file_original_path'][6:]) elif ( item['file_original_path'].find("stack://") > -1 ): stackPath = item['file_original_path'].split(" , ") item['file_original_path'] = stackPath[0][8:] # required if tvshow is not indexed/recognized in library if item['tvshow'] == "": log(__name__, "item %s" % item) # replace dots with spaces in title titulo = re.sub(r'\.', ' ', item['title']) log(__name__, "title no dots: %s" % titulo) mo = re.search(r'(.*)[sS](\d+)[eE](\d+)', titulo) #S01E02 like if not mo: mo = re.search(r'(.*)(\d\d)[xX](\d+)', titulo) # old 10x02 style if not mo: mo = re.search(r'(.*)(\d)[xX](\d+)', titulo) # old 1x02 style if not mo: mo = re.search(r'(.*) (\d+)(\d\d)', titulo) # 102 style # split title in tvshow, season and episode if mo: item['tvshow'] = mo.group(1) if item['tvshow'].endswith(' - '): item['tvshow'] = item['tvshow'][:-3]