def Download(link, filename): subtitle_list = [] exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"] if link: downloadlink = link log(__name__, "Downloadlink %s" % link) class MyOpener(urllib.FancyURLopener): version = "User-Agent=Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729)" my_urlopener = MyOpener() my_urlopener.addheader('Referer', link) 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) item['season'] = mo.group(2) item['episode'] = mo.group(3)
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).rstrip() item['season'] = mo.group(2) item['episode'] = mo.group(3)