def getAllSubtitles(subtitlePageID,languageList,subtitlesList): # Retrieve the subtitles page (html) try: subtitlePage = getURL(BASE_URL + subtitlePageID) except: # Didn't find the page - no such episode? return # Didn't find the page - no such episode? if (not subtitlePage): return # Find subtitles dictionary declaration on page tempStart = subtitlePage.index("subtitles_groups = ") # Look for the following line break tempEnd = subtitlePage.index("\n",subtitlePage.index("subtitles_groups = ")) toExec = "foundSubtitles = "+subtitlePage[tempStart+len("subtitles_groups = "):tempEnd] # Remove junk at the end of the line toExec = toExec[:toExec.rfind("}")+1] # Replace "null" with "None" toExec = toExec.replace("null","None") exec(toExec) log( __name__ ,"Built webpage dictionary") for language in foundSubtitles.keys(): if (twotofull(language) in languageList): for translator in foundSubtitles[language]: for quality in foundSubtitles[language][translator]: for rating in foundSubtitles[language][translator][quality]: subtitlesList.append({'rating': rating, 'sync': False, 'filename': foundSubtitles[language][translator][quality][rating]["subtitle_version"], 'subtitle_id': foundSubtitles[language][translator][quality][rating]["id"], 'language_flag': 'flags/' + language + '.gif', 'language_name': twotofull(language), 'key': foundSubtitles[language][translator][quality][rating]["key"]})
def getAllSubtitles(subtitlePageID,languageList,subtitlesList): # Retrieve the subtitles page (html) try: subtitlePage = getURL(BASE_URL + subtitlePageID) except: # Didn't find the page - no such episode? return # Didn't find the page - no such episode? if (not subtitlePage): return # Find subtitles dictionary declaration on page tempStart = subtitlePage.index("subtitles_groups = ") # Look for the following line break tempEnd = subtitlePage.index("\n",subtitlePage.index("subtitles_groups = ")) toExec = "foundSubtitles = "+subtitlePage[tempStart+len("subtitles_groups = "):tempEnd] # Remove junk at the end of the line toExec = toExec[:toExec.rfind("}")+1] exec(toExec) log( __name__ ,"Built webpage dictionary") for language in foundSubtitles.keys(): if (twotofull(language) in languageList): for translator in foundSubtitles[language]: for quality in foundSubtitles[language][translator]: for rating in foundSubtitles[language][translator][quality]: subtitlesList.append({'rating': rating, 'sync': False, 'filename': foundSubtitles[language][translator][quality][rating]["subtitle_version"], 'subtitle_id': foundSubtitles[language][translator][quality][rating]["id"], 'language_flag': 'flags/' + language + '.gif', 'language_name': twotofull(language), 'key': foundSubtitles[language][translator][quality][rating]["key"]})
def getallsubs(content, title, subtitles_list, file_original_path): for matches in re.finditer(subtitle_pattern, content): jezyk, numer_napisu, wydanie, tytul = matches.groups() if 'other' in jezyk: continue else: jezyk = jezyk link = "%s%s/" % (down_url, numer_napisu) log( __name__ ,"Subtitles found: %s %s (link=%s)" % (tytul, wydanie, link)) obraz_flagi = "flags/%s.gif" % (jezyk) lang = twotofull(jezyk) tytul_pelny = '%s %s' % (tytul, wydanie) wydanie_sclean = wydanie.replace(" ","") wydanie_clean = wydanie_sclean.replace(",",";") wydanie_srednik = '%s;' % (wydanie_clean) for wydania in re.finditer('(.+?);', wydanie_srednik): wydania = wydania.group() wydania_clean = wydania.replace(";","") wydania_upper = wydania_clean.upper() filepatch_upper = file_original_path.upper() if wydania_upper in filepatch_upper: sync_value = True else: sync_value = False subtitles_list.append({'filename': tytul_pelny, 'sync': sync_value, 'link': link, 'language_flag': obraz_flagi, 'language_name': lang,'rating': ""})
def search_subtitles(file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack): #standard input subtitles_list = [] msg = "" if len(file_original_path) > 0: # get file hash hash = get_hash(file_original_path) # do the search languages = get_languages([lang1, lang2, lang3]) params = { 'action': 'search', 'hash': hash } #, 'language': ','.join(languages) url = base_url % urllib.urlencode(params) req = urllib2.Request(url) req.add_header('User-Agent', user_agent) try: # HTTP/1.1 200 response = urllib2.urlopen(req) result = response.readlines() subtitles = result[0].split(',') for subtitle in subtitles: if subtitle in languages: filename = os.path.split(file_original_path)[1] params = { 'action': 'download', 'language': subtitle, 'hash': hash } link = base_url % urllib.urlencode(params) if subtitle == "pt": flag_image = 'flags/pb.gif' else: flag_image = "flags/%s.gif" % subtitle subtitles_list.append({ 'filename': filename, 'link': link, 'language_name': twotofull(subtitle), 'language_id': "0", 'language_flag': flag_image, 'movie': filename, "ID": subtitle, "rating": "10", "format": "srt", "sync": True }) except urllib2.HTTPError, e: # HTTP/1.1 !200 return subtitles_list, "", msg #standard output except urllib2.URLError, e: # Unknown or timeout url log(__name__, "Service did not respond in time, aborting...") msg = _(755) return subtitles_list, "", msg #standard output
def search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack ): # standard input subtitles_list = [] msg = "" if len(file_original_path) > 0: # get file hash hash = get_hash(file_original_path) # do the search languages = get_languages([lang1, lang2, lang3]) params = {"action": "search", "hash": hash} # , 'language': ','.join(languages) url = base_url % urllib.urlencode(params) req = urllib2.Request(url) req.add_header("User-Agent", user_agent) try: # HTTP/1.1 200 response = urllib2.urlopen(req) result = response.readlines() subtitles = result[0].split(",") for subtitle in subtitles: if subtitle in languages: filename = os.path.split(file_original_path)[1] params = {"action": "download", "language": subtitle, "hash": hash} link = base_url % urllib.urlencode(params) if subtitle == "pt": flag_image = "flags/pb.gif" else: flag_image = "flags/%s.gif" % subtitle subtitles_list.append( { "filename": filename, "link": link, "language_name": twotofull(subtitle), "language_id": "0", "language_flag": flag_image, "movie": filename, "ID": subtitle, "rating": "10", "format": "srt", "sync": True, } ) except urllib2.HTTPError, e: # HTTP/1.1 !200 return subtitles_list, "", msg # standard output except urllib2.URLError, e: # Unknown or timeout url log(__name__, "Service did not respond in time, aborting...") msg = _(755) return subtitles_list, "", msg # standard output
def getallsubs(content, title, subtitles_list, file_original_path, stack): nr_lista = 0 wydanie_re = '<td.+?>(.+?)<br />' rozmiar_re = 'Rozmiar pliku: <strong>(.+?)</strong>' ocena_re = 'rednia ocena: (\d\,\d\d)<br />' jezyk_re = '<img src="images/ico_flag_(..)_2.png" alt="' ilosc_plyt_re = '<td.+?style="text-align: center;">[\r\n\t ]+?(\d)[\r\n\t ]+?</td>' wydanie_lista = re.findall(wydanie_re, content) jezyk_lista = re.findall(jezyk_re, content) rozmiar_lista = re.findall(rozmiar_re, content) ocena_lista = re.findall(ocena_re, content) ilosc_plyt_lista = re.findall(ilosc_plyt_re, content) for matches in re.finditer(subtitle_pattern, content): numer_napisu, tytul = matches.groups() wydanie = wydanie_lista[nr_lista] ocena = ocena_lista[nr_lista] jezyk = jezyk_lista[nr_lista] ilosc_plyt = ilosc_plyt_lista[nr_lista] nr_lista +=1 link = "%s%s/" % (down_url, numer_napisu) log( __name__ ,"Subtitles found: %s %s (link=%s)" % (tytul, wydanie, link)) obraz_flagi = "flags/%s.gif" % (jezyk) lang = twotofull(jezyk) tytul_pelny = '%s %s' % (tytul, wydanie) wydanie_sclean = wydanie.replace(" ","") wydanie_clean = wydanie_sclean.replace(",",";") wydanie_srednik = '%s;' % (wydanie_clean) for wydania in re.finditer('(.+?);', wydanie_srednik): wydania = wydania.group() wydania_clean = wydania.replace(";","") wydania_upper = wydania_clean.upper() filepatch_upper = file_original_path.upper() if wydania_upper in filepatch_upper: sync_value = True else: sync_value = False ocena_dot = ocena.replace(",",".") if ocena_dot == '0.00': sub_rating = '0' else: sub_rating = int(round(float(ocena_dot) * 1.666,0)) if stack == True: if ilosc_plyt == '1': log( __name__ ,"Stacked file nonstacked subs") else: subtitles_list.append({'filename': tytul_pelny, 'sync': sync_value, 'link': link, 'language_flag': obraz_flagi, 'language_name': lang,'rating': '%s' % (sub_rating)}) else: if ilosc_plyt == '1': subtitles_list.append({'filename': tytul_pelny, 'sync': sync_value, 'link': link, 'language_flag': obraz_flagi, 'language_name': lang,'rating':'%s' % (sub_rating)}) else: log( __name__ ,"Nonstacked file stacked subs")
def search_subtitles(file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack): #standard input subtitles_list = [] msg = "" lang1 = toOpenSubtitles_two(lang1) lang2 = toOpenSubtitles_two(lang2) lang3 = toOpenSubtitles_two(lang3) querylang = "" if lang1 == 'en' or lang2 == 'en' or lang3 == 'en': querylang = "VO" if lang1 == 'fr' or lang2 == 'fr' or lang3 == 'fr': querylang += "VF" log(__name__, "query language: '%s'" % (querylang)) if (len(file_original_path) > 0) and (len(tvshow) > 0): show = getShortTV(tvshow) if len(show) > 0: searchurl = 'http://' + apiurl + '/subtitles/show/' + show + '.xml?season=' + season + '&episode=' + episode + '&language=' + querylang + '&key=' + apikey log(__name__, "searchurl = '%s'" % (searchurl)) try: # parsing shows from xml dom = minidom.parse(urllib.urlopen(searchurl)) #time.sleep(1) subtitles = dom.getElementsByTagName('subtitle') log(__name__, "nb sub found: '%s'" % (len(subtitles))) for subtitle in subtitles: url = subtitle.getElementsByTagName('url')[0].childNodes[0] url = url.nodeValue filename = subtitle.getElementsByTagName( 'file')[0].childNodes[0] filename = filename.nodeValue language = subtitle.getElementsByTagName( 'language')[0].childNodes[0] language = get_languages(language.nodeValue) rating = subtitle.getElementsByTagName( 'quality')[0].childNodes[0] #rating = rating.nodeValue rating = str(int(round(float(rating.nodeValue) / 5 * 9))) ext = os.path.splitext(filename)[1] #log( __name__ , "file : '%s' ext : '%s'" % (filename,ext)) if ext == '.zip': if len(subtitle.getElementsByTagName('content')) > 0: #log( __name__ , "zip content ('%s')" % (filename)) content = subtitle.getElementsByTagName( 'content')[0] items = content.getElementsByTagName('item') for item in items: if len(item.childNodes) < 1: continue subfile = item.childNodes[0].nodeValue if os.path.splitext(subfile)[1] == '.zip': continue # Not supported yet ;) search_string = "(s%#02de%#02d)|(%d%#02d)|(%dx%#02d)" % ( int(season), int(episode), int(season), int(episode), int(season), int(episode)) queryep = re.search(search_string, subfile, re.I) #log( __name__ , "ep: %s found: %s" % (search_string,queryep)) if queryep == None: continue langs = re.search('\.(VF|VO|en|fr)\..*.{3}$', subfile, re.I) #langs = langs.group(1) #log( __name__ , "detect language... %s" % (subfile)) try: langs = langs.group(1) lang = { "fr": 'fr', "FR": 'fr', "en": 'en', "EN": 'en', "VF": 'fr', "vf": 'fr', "VO": 'en', "vo": 'en' }[langs] #log( __name__ , "language: %s" % (lang)) except: lang = language if lang != lang1 and lang != lang2 and lang != lang3: continue #log( __name__ , "subfile = '%s'" % (subfile)) subtitles_list.append({ 'filename': subfile, 'link': url, 'language_name': twotofull(lang), 'language_id': "0", 'language_flag': 'flags/' + lang + '.gif', "rating": rating, "sync": False }) else: log(__name__, "not valid content! dumping XML...") log(__name__, dom.toxml()) else: #log( __name__ , "sub found ('%s')" % (filename)) subtitles_list.append({ 'filename': filename, 'link': url, 'language_name': twotofull(language), 'language_id': "0", 'language_flag': 'flags/' + language + '.gif', "rating": rating, "sync": False }) except Exception, inst: log(__name__, " Error: %s" % (inst)) return subtitles_list, "", msg #standard output
def search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack ): #standard input subtitles_list = [] msg = "" lang1 = toOpenSubtitles_two(lang1) lang2 = toOpenSubtitles_two(lang2) lang3 = toOpenSubtitles_two(lang3) querylang = "" if lang1 == 'en' or lang2 == 'en' or lang3 == 'en': querylang = "VO" if lang1 == 'fr' or lang2 == 'fr' or lang3 == 'fr': querylang += "VF" log( __name__ , "query language: '%s'" % (querylang)) if (len(file_original_path) > 0) and (len(tvshow) > 0) : show = getShortTV(tvshow) if len(show)>0: searchurl = 'http://' + apiurl + '/subtitles/show/' + show + '.xml?season=' + season + '&episode=' + episode + '&language=' + querylang + '&key=' + apikey log( __name__ , "searchurl = '%s'" % (searchurl)) try: # parsing shows from xml dom = minidom.parse(urllib.urlopen(searchurl)) #time.sleep(1) subtitles = dom.getElementsByTagName('subtitle') log( __name__ , "nb sub found: '%s'" % (len(subtitles))) for subtitle in subtitles: url = subtitle.getElementsByTagName('url')[0].childNodes[0] url = url.nodeValue filename = subtitle.getElementsByTagName('file')[0].childNodes[0] filename = filename.nodeValue language = subtitle.getElementsByTagName('language')[0].childNodes[0] language = get_languages(language.nodeValue) rating = subtitle.getElementsByTagName('quality')[0].childNodes[0] #rating = rating.nodeValue rating = str(int(round(float(rating.nodeValue) / 5 * 9))) ext = os.path.splitext(filename)[1] #log( __name__ , "file : '%s' ext : '%s'" % (filename,ext)) if ext == '.zip': if len(subtitle.getElementsByTagName('content'))>0: #log( __name__ , "zip content ('%s')" % (filename)) content = subtitle.getElementsByTagName('content')[0] items = content.getElementsByTagName('item') for item in items: if len(item.childNodes) < 1 : continue subfile = item.childNodes[0].nodeValue if os.path.splitext(subfile)[1] == '.zip': continue # Not supported yet ;) search_string = "(s%#02de%#02d)|(%d%#02d)|(%dx%#02d)" % (int(season), int(episode),int(season), int(episode),int(season), int(episode)) queryep = re.search(search_string, subfile, re.I) #log( __name__ , "ep: %s found: %s" % (search_string,queryep)) if queryep == None: continue langs = re.search('\.(VF|VO|en|fr)\..*.{3}$',subfile,re.I) #langs = langs.group(1) #log( __name__ , "detect language... %s" % (subfile)) try: langs = langs.group(1) lang = { "fr": 'fr', "FR": 'fr', "en": 'en', "EN": 'en', "VF": 'fr', "vf": 'fr', "VO": 'en', "vo": 'en' }[langs] #log( __name__ , "language: %s" % (lang)) except: lang = language if lang != lang1 and lang != lang2 and lang != lang3: continue #log( __name__ , "subfile = '%s'" % (subfile)) subtitles_list.append({'filename': subfile,'link': url,'language_name': twotofull(lang),'language_id':"0",'language_flag':'flags/' + lang + '.gif',"rating":rating,"sync": False}) else: log( __name__ , "not valid content! dumping XML...") log( __name__ , dom.toxml()) else: #log( __name__ , "sub found ('%s')" % (filename)) subtitles_list.append({'filename': filename,'link': url,'language_name': twotofull(language),'language_id':"0",'language_flag':'flags/' + language + '.gif',"rating":rating,"sync": False}) except Exception, inst: log( __name__ , " Error: %s" % (inst)) return subtitles_list, "", msg #standard output
def getallsubs(content, title, subtitles_list, file_original_path, stack): nr_lista = 0 wydanie_re = '<td.+?>(.+?)<br />' rozmiar_re = 'Rozmiar pliku: <strong>(.+?)</strong>' ocena_re = 'rednia ocena: (\d\,\d\d)<br />' jezyk_re = '<img src="images/ico_flag_(..)_2.png" alt="' ilosc_plyt_re = '<td.+?style="text-align: center;">[\r\n\t ]+?(\d)[\r\n\t ]+?</td>' wydanie_lista = re.findall(wydanie_re, content) jezyk_lista = re.findall(jezyk_re, content) rozmiar_lista = re.findall(rozmiar_re, content) ocena_lista = re.findall(ocena_re, content) ilosc_plyt_lista = re.findall(ilosc_plyt_re, content) for matches in re.finditer(subtitle_pattern, content): numer_napisu, tytul = matches.groups() wydanie = wydanie_lista[nr_lista] ocena = ocena_lista[nr_lista] jezyk = jezyk_lista[nr_lista] ilosc_plyt = ilosc_plyt_lista[nr_lista] nr_lista += 1 link = "%s%s/" % (down_url, numer_napisu) log(__name__, "Subtitles found: %s %s (link=%s)" % (tytul, wydanie, link)) obraz_flagi = "flags/%s.gif" % (jezyk) lang = twotofull(jezyk) tytul_pelny = '%s %s' % (tytul, wydanie) wydanie_sclean = wydanie.replace(" ", "") wydanie_clean = wydanie_sclean.replace(",", ";") wydanie_srednik = '%s;' % (wydanie_clean) for wydania in re.finditer('(.+?);', wydanie_srednik): wydania = wydania.group() wydania_clean = wydania.replace(";", "") wydania_upper = wydania_clean.upper() filepatch_upper = file_original_path.upper() if wydania_upper in filepatch_upper: sync_value = True else: sync_value = False ocena_dot = ocena.replace(",", ".") if ocena_dot == '0.00': sub_rating = '0' else: sub_rating = int(round(float(ocena_dot) * 1.666, 0)) if stack == True: if ilosc_plyt == '1': log(__name__, "Stacked file nonstacked subs") else: subtitles_list.append({ 'filename': tytul_pelny, 'sync': sync_value, 'link': link, 'language_flag': obraz_flagi, 'language_name': lang, 'rating': '%s' % (sub_rating) }) else: if ilosc_plyt == '1': subtitles_list.append({ 'filename': tytul_pelny, 'sync': sync_value, 'link': link, 'language_flag': obraz_flagi, 'language_name': lang, 'rating': '%s' % (sub_rating) }) else: log(__name__, "Nonstacked file stacked subs")