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 (languageTranslate(language, 2, 0) 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': languageTranslate(language, 2, 0), 'key': foundSubtitles[language][translator][quality][rating]["key"]})
def getAllSubtitles(subtitlePageID,languageList,subtitlesList): log( __name__ ,"Get all subtitles") # Retrieve the subtitles page (html) try: subtitlePage = getURL(BASE_URL + str(subtitlePageID).lstrip()) 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 (languageTranslate(language, 2, 0) 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': languageTranslate(language, 2, 0), 'key': foundSubtitles[language][translator][quality][rating]["key"]})
def getAllSubtitles(subtitlePageID,languageList,fname): # Retrieve the subtitles page (html) subs= [] 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 toExec = "foundSubtitles = " + subtitlePage # Remove junk at the end of the line toExec = toExec[:toExec.rfind("}")+1] # Replace "null" with "None" toExec = toExec.replace("null","None") exec(toExec) in globals(), locals() log( __name__ ,"Built webpage dictionary") for language in foundSubtitles.keys(): if (languageTranslate(language, 2, 0) in languageList): for translator in foundSubtitles[language]: for quality in foundSubtitles[language][translator]: for rating in foundSubtitles[language][translator][quality]: title=foundSubtitles[language][translator][quality][rating]["subtitle_version"] Srating=getrating(title,fname) subs.append({'rating': str(Srating), 'sync': Srating>=8, 'filename': title, 'subtitle_id': foundSubtitles[language][translator][quality][rating]["id"], 'language_flag': 'flags/' + language + '.gif', 'language_name': languageTranslate(language, 2, 0), 'key': foundSubtitles[language][translator][quality][rating]["key"], 'notes': re.search('http://www\.sendspace\.com/file/\w+$',foundSubtitles[language][translator][quality][rating]["notes"])}) # sort, to put syncs on top return sorted(subs,key=lambda x: int(float(x['rating'])),reverse=True)
def search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack ): #standard input ok = False msg = "" osdb_server = OSDBServer() osdb_server.create() subtitles_list = [] file_size = "" hashTry = "" language1 = languageTranslate(lang1,0,1) language2 = languageTranslate(lang2,0,1) language3 = languageTranslate(lang3,0,1) if set_temp : hash_search = False file_size = "000000000" SubHash = "000000000000" else: try: file_size, SubHash = xbmc.subHashAndFileSize(file_original_path) log( __name__ ,"xbmc module hash and size") hash_search = True except: file_size = "" SubHash = "" hash_search = False if file_size != "" and SubHash != "": log( __name__ ,"File Size [%s]" % file_size ) log( __name__ ,"File Hash [%s]" % SubHash) if hash_search : log( __name__ ,"Search for [%s] by hash" % (os.path.basename( file_original_path ),)) subtitles_list, session_id = osdb_server.searchsubtitles_pod( SubHash ,language1, language2, language3, stack) if not subtitles_list: log( __name__ ,"Search for [%s] by name" % (os.path.basename( file_original_path ),)) subtitles_list = osdb_server.searchsubtitlesbyname_pod( title, tvshow, season, episode, language1, language2, language3, year, stack ) return subtitles_list, "", "" #standard output
def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, session_id): #standard input subtitle_id = subtitles_list[pos]["subtitle_id"] filename = subtitles_list[pos]["filename"] key = subtitles_list[pos]["key"] # check if need to download subtitle from sendspace if (subtitles_list[pos]["notes"]): # log to sendspace content = getURL(subtitles_list[pos]["notes"].group()) # find download link url = re.search( r'<a id="download_button" href?="(.+sendspace.+\.\w\w\w)" ', content) content = None if (url): url = url.group(1) log( __name__, "%s Fetching subtitles from sendspace.com using url %s" % (debug_pretext, url)) content = getURL(url) archive_name = "rarsubs" + re.search(r'\.\w\w\w$', url).group(0) else: url = BASE_URL + "/" + languageTranslate( subtitles_list[pos]["language_name"], 0, 2) + "/subtitle/download/" + languageTranslate( subtitles_list[pos]["language_name"], 0, 2) + "/" + str(subtitle_id) + "/?v=" + filename + "&key=" + key log(__name__, "%s Fetching subtitles using url %s" % (debug_pretext, url)) # Get the intended filename (don't know if it's zip or rar) archive_name = getURLfilename(url) # Get the file content using geturl() content = getURL(url) subs_file = "" if content: local_tmp_file = os.path.join(tmp_sub_dir, archive_name) log(__name__, "%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file)) try: local_file_handle = open(local_tmp_file, "wb") local_file_handle.write(content) local_file_handle.close() except: log( __name__, "%s Failed to save subtitles to '%s'" % (debug_pretext, local_tmp_file)) # Extract the zip file and find the new sub/srt file subs_file = extractAndFindSub(tmp_sub_dir, local_tmp_file) # Standard output - # True iff the file is packed as zip: addon will automatically unpack it. # language of subtitles, # Name of subtitles file if not packed (or if we unpacked it ourselves) return False, subtitles_list[pos]["language_name"], subs_file
def search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack ): #standard input subtitles_list = [] msg = "" searchstring_notclean = "" searchstring = "" global israr israr = os.path.abspath(file_original_path) israr = os.path.split(israr) israr = israr[0].split(os.sep) israr = string.split(israr[-1], '.') israr = string.lower(israr[-1]) if len(tvshow) == 0: if 'rar' in israr and searchstring is not None: if 'cd1' in string.lower(title) or 'cd2' in string.lower(title) or 'cd3' in string.lower(title): dirsearch = os.path.abspath(file_original_path) dirsearch = os.path.split(dirsearch) dirsearch = dirsearch[0].split(os.sep) if len(dirsearch) > 1: searchstring_notclean = dirsearch[-3] searchstring = xbmc.getCleanMovieTitle(dirsearch[-3]) searchstring = searchstring[0] else: searchstring = title else: searchstring = title elif 'cd1' in string.lower(title) or 'cd2' in string.lower(title) or 'cd3' in string.lower(title): dirsearch = os.path.abspath(file_original_path) dirsearch = os.path.split(dirsearch) dirsearch = dirsearch[0].split(os.sep) if len(dirsearch) > 1: searchstring_notclean = dirsearch[-2] searchstring = xbmc.getCleanMovieTitle(dirsearch[-2]) searchstring = searchstring[0] else: #We are at the root of the drive!!! so there's no dir to lookup only file# title = os.path.split(file_original_path) searchstring = title[-1] else: if title == "": title = os.path.split(file_original_path) searchstring = title[-1] else: searchstring = title if len(tvshow) > 0: searchstring = "%s S%#02dE%#02d" % (tvshow, int(season), int(episode)) log( __name__ ,"%s Search string = %s" % (debug_pretext, searchstring)) msgnote(debug_pretext,__language__(30153), 6000) getallsubs(searchstring, languageTranslate(lang1,0,3), lang1, file_original_path, subtitles_list, searchstring_notclean) getallsubs(searchstring, languageTranslate(lang2,0,3), lang2, file_original_path, subtitles_list, searchstring_notclean) getallsubs(searchstring, languageTranslate(lang3,0,3), lang3, file_original_path, subtitles_list, searchstring_notclean) return subtitles_list, "", msg #standard output
def getAllSubtitles(subtitlePageID, languageList, fname): # Retrieve the subtitles page (html) subs = [] 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 toExec = "foundSubtitles = " + subtitlePage # Remove junk at the end of the line toExec = toExec[:toExec.rfind("}") + 1] # Replace "null" with "None" toExec = toExec.replace("null", "None") exec(toExec) in globals(), locals() log(__name__, "Built webpage dictionary") for language in foundSubtitles.keys(): if (languageTranslate(language, 2, 0) in languageList): for translator in foundSubtitles[language]: for quality in foundSubtitles[language][translator]: for rating in foundSubtitles[language][translator][ quality]: title = foundSubtitles[language][translator][quality][ rating]["subtitle_version"] Srating = getrating(title, fname) subs.append({ 'rating': str(Srating), 'sync': Srating >= 8, 'filename': title, 'subtitle_id': foundSubtitles[language][translator][quality] [rating]["id"], 'language_flag': 'flags/' + language + '.gif', 'language_name': languageTranslate(language, 2, 0), 'key': foundSubtitles[language][translator][quality] [rating]["key"], 'notes': re.search( 'http://www\.sendspace\.com/file/\w+$', foundSubtitles[language][translator][quality] [rating]["notes"]) }) # sort, to put syncs on top return sorted(subs, key=lambda x: int(float(x['rating'])), reverse=True)
def download_subtitles (subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, session_id): #standard input subtitle_id = subtitles_list[pos][ "subtitle_id" ] filename = subtitles_list[pos][ "filename" ] key = subtitles_list[pos][ "key" ] url = BASE_URL + "/subtitle/download/"+languageTranslate(subtitles_list[pos][ "language_name" ], 0, 2)+"/"+str(subtitle_id)+"/?v="+filename+"&key="+key log( __name__ ,"%s Fetching subtitles using url %s" % (debug_pretext, url)) # Get the intended filename (don't know if it's zip or rar) archive_name = getURLfilename(url) # Get the file content using geturl() content = getURL(url) subs_file = None if content: local_tmp_file = os.path.join(tmp_sub_dir, archive_name) log( __name__ ,"%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file)) try: local_file_handle = open(local_tmp_file, "wb") local_file_handle.write(content) local_file_handle.close() except: log( __name__ ,"%s Failed to save subtitles to '%s'" % (debug_pretext, local_tmp_file)) # Extract the zip file and find the new sub/srt file subs_file = extractAndFindSub(tmp_sub_dir,local_tmp_file) # Standard output - # True iff the file is packed as zip: addon will automatically unpack it. # language of subtitles, # Name of subtitles file if not packed (or if we unpacked it ourselves) return False, subtitles_list[pos][ "language_name" ], subs_file
def search_subtitles(file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack): #standard input service_languages = ['Spanish', 'English', 'Catalan'] config_languages = [lang1, lang2, lang3] subtitles_list = [] msg = "" # Check if searching for tv show or movie if tvshow: if ((lang1 in service_languages) or (lang2 in service_languages) or (lang3 in service_languages)): config_languages[:] = unique(config_languages) for language in config_languages: getallsubs(languageTranslate(language, 0, 2), language, file_original_path, subtitles_list, tvshow, season, episode) subtitles_list = clean_subtitles_list(subtitles_list) else: msg = "Won't work, subtitulos.es is only for Spanish, English and Catalan subtitles!" else: msg = "Subtitulos.es is only for TV Shows subtitles!" return subtitles_list, "", msg #standard output
def getAllTVSubtitles(fname,subtitlePageID,languageList,season,episode): # Retrieve the subtitles page (html) subs= [] subtitlePage = getURL(BASE_URL + "viewseries.php?id=" + subtitlePageID + "&m=subtitles#") # Retrieve the requested season foundSeasons = re.findall(TV_SEASON_PATTERN, subtitlePage) for (season_link,season_num) in foundSeasons: if (season_num == season): # Retrieve the requested episode subtitlePage = getURL(BASE_URL + "viewseries.php?id=" + subtitlePageID + "&m=subtitles&s="+str(season_link)) foundEpisodes = re.findall(TV_EPISODE_PATTERN, subtitlePage) for (episode_link,episode_num) in foundEpisodes: if (episode_num == episode): subtitlePage = getURL(BASE_URL + "viewseries.php?id=" + subtitlePageID + "&m=subtitles&s="+str(season_link)+"&e="+str(episode_link)) # Create a list of all subtitles found on page foundSubtitles = re.findall(COMBINED, subtitlePage) for (fid,language,title,fid2,language2,title2) in foundSubtitles: log( __name__ ,"%s Is sendspace?: %s" % (debug_pretext, bool(fid2 and len(fid2)>0))) # Create Dictionery for XBMC Gui if(fid2 and len(fid2)>0): fid=fid2 language=language2 title=title2 # Check if the subtitles found match one of our languages was selected # by the user if (sratimToScript(language) in languageList): rating=getrating(title,fname) subs.append({'rating': str(rating), 'sync': rating>=8, 'filename': title, 'subtitle_id': fid, 'language_flag': 'flags/' + \ languageTranslate(sratimToScript(language),0,2) + \ '.gif', 'language_name': sratimToScript(language), 'sendspace': (fid2 and len(fid2)>0)}) # sort, to put syncs on top return sorted(subs,key=lambda x: int(float(x['rating'])),reverse=True)
def getAllSubtitles(fname, subtitlePageID, languageList): # Retrieve the subtitles page (html) subs = [] subtitlePage = getURL(BASE_URL + "getajax.php?moviedetailssubtitles=" + subtitlePageID[1:]) # Create a list of all subtitles found on page foundSubtitles = re.findall(COMBINED, subtitlePage) for (fid, language, title, fid2, language2, title2) in foundSubtitles: log(__name__, "%s Is sendspace?: %s" % (debug_pretext, bool(fid2 and len(fid2) > 0))) # Create Dictionery for XBMC Gui if fid2 and len(fid2) > 0: fid = fid2 language = language2 title = title2 # Check if the subtitles found match one of our languages was selected # by the user if sratimToScript(language) in languageList: rating = getrating(title, fname) subs.append( { "rating": str(rating), "sync": rating >= 8, "filename": title, "subtitle_id": fid, "language_flag": "flags/" + languageTranslate(sratimToScript(language), 0, 2) + ".gif", "language_name": sratimToScript(language), "sendspace": (fid2 and len(fid2) > 0), } ) return sorted(subs, key=lambda x: int(float(x["rating"])), reverse=True)
def download_subtitles (subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, session_id): #standard input subtitle_id = subtitles_list[pos][ "subtitle_id" ] filename = subtitles_list[pos][ "filename" ] key = subtitles_list[pos][ "key" ] url = BASE_URL + "/subtitle/download/"+languageTranslate(subtitles_list[pos][ "language_name" ], 0, 2)+"/"+str(subtitle_id)+"/?v="+filename+"&key="+key log( __name__ ,"%s Fetching subtitles using url %s" % (debug_pretext, url)) # Get the intended filename (don't know if it's zip or rar) archive_name = getURLfilename(url) # Get the file content using geturl() content = getURL(url) subs_file = "" if content: local_tmp_file = os.path.join(tmp_sub_dir, archive_name) log( __name__ ,"%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file)) try: local_file_handle = open(local_tmp_file, "wb") local_file_handle.write(content) local_file_handle.close() except: log( __name__ ,"%s Failed to save subtitles to '%s'" % (debug_pretext, local_tmp_file)) # Extract the zip file and find the new sub/srt file subs_file = extractAndFindSub(tmp_sub_dir,local_tmp_file) # Standard output - # True iff the file is packed as zip: addon will automatically unpack it. # language of subtitles, # Name of subtitles file if not packed (or if we unpacked it ourselves) return False, subtitles_list[pos][ "language_name" ], subs_file
def getAllSubtitles(fname, subtitlePageID, languageList): # Retrieve the subtitles page (html) subs = [] subtitlePage = getURL(BASE_URL + "view.php?id=" + subtitlePageID + "&m=subtitles#") # Create a list of all subtitles found on page foundSubtitles = re.findall(COMBINED, subtitlePage) for (fid, language, title, fid2, language2, title2) in foundSubtitles: log( __name__, "%s Is sendspace?: %s" % (debug_pretext, bool(fid2 and len(fid2) > 0))) #Create Dictionery for XBMC Gui if (fid2 and len(fid2) > 0): fid = fid2 language = language2 title = title2 # Check if the subtitles found match one of our languages was selected # by the user if (sratimToScript(language) in languageList): rating = getrating(title, fname) subs.append({'rating': str(rating), 'sync': rating>=8, 'filename': title, 'subtitle_id': fid, 'language_flag': 'flags/' + \ languageTranslate(sratimToScript(language),0,2) + \ '.gif', 'language_name': sratimToScript(language), 'sendspace': (fid2 and len(fid2)>0)}) return sorted(subs, key=lambda x: int(float(x['rating'])), reverse=True)
def get_languages(languages): subdb_languages = [] for language in languages: code = languageTranslate(language,0,2) if code == 'pb': code = 'pt' subdb_languages.append(code) return subdb_languages
def get_languages(languages): subdb_languages = [] for language in languages: code = languageTranslate(language, 0, 2) if code == 'pb': code = 'pt' subdb_languages.append(code) return subdb_languages
def search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack ): #standard input msg = "" subtitles_list = [] search_url = "http://api.titlovi.com/xml_get_api.ashx?x-dev_api_id=%s&keyword=%s&uiculture=en" languages = [lang1, lang2, lang3] if len(tvshow) > 0: # TvShow search_string = ("%s S%.2dE%.2d" % (tvshow, int(season), int(episode),) ).replace(" ","+") else: # Movie or not in Library if str(year) == "": # Not in Library title, year = xbmc.getCleanMovieTitle( title ) else: # Movie in Library year = year title = title search_string = title.replace(" ","+") log( __name__ , "Search String [ %s ]" % (search_string,)) subtitles = minidom.parseString( geturl(search_url % ( base64.b64decode(KEY)[::-1], search_string)) ).getElementsByTagName("subtitle") if subtitles: url_base = "http://en.titlovi.com/downloads/default.ashx?type=1&mediaid=%s" for subtitle in subtitles: lang = subtitle.getElementsByTagName("language")[0].firstChild.data if lang == "rs": lang = "sr" if lang == "ba": lang = "bs" if lang == "si": lang = "sl" lang_full = languageTranslate(lang, 2,0) if lang_full in languages: sub_id = subtitle.getElementsByTagName("url")[0].firstChild.data movie = subtitle.getElementsByTagName("safeTitle")[0].firstChild.data if subtitle.getElementsByTagName("release")[0].firstChild: filename = "%s - %s" % (movie, subtitle.getElementsByTagName("release")[0].firstChild.data) else: filename = movie rating = int(float(subtitle.getElementsByTagName("score")[0].firstChild.data)*2) flag_image = "flags/%s.gif" % lang link = url_base % sub_id.split("-")[-1].replace("/","") subtitles_list.append({'filename' :filename, 'link' :link, 'language_name':lang_full, 'language_id' :lang, 'language_flag':flag_image, 'movie' :movie, 'rating' :str(rating), 'sync' :False }) subtitles_list = sorted(subtitles_list, compare_columns) return subtitles_list, "", msg #standard output
def _search(self, title, filepath, langs, season, episode, tvshow, year): file_original_path = filepath and filepath or "" title = title and title or file_original_path season = season if season else "" episode = episode if episode else "" tvshow = tvshow if tvshow else "" year = year if year else "" if len(langs) > 3: self.log.info('more then three languages provided, only first three will be selected') if len(langs) == 0: self.log.info('no languages provided will use default ones') lang1 = self.lang1 lang2 = self.lang2 lang3 = self.lang3 elif len(langs) == 1: lang1 = lang2= lang3 = languageTranslate(langs[0],2,0) elif len(langs) == 2: lang1 = lang3 = languageTranslate(langs[0],2,0) lang2 = languageTranslate(langs[1],2,0) elif len(langs) == 3: lang1 = languageTranslate(langs[0],2,0) lang2 = languageTranslate(langs[1],2,0) lang3 = languageTranslate(langs[2],2,0) self.log.info('using langs %s %s %s'%(toString(lang1), toString(lang2), toString(lang3))) self.module.settings_provider = self.settings_provider # Standard output - # subtitles list # session id (e.g a cookie string, passed on to download_subtitles), # message to print back to the user # return subtitlesList, "", msg subtitles_list, session_id, msg = self.module.search_subtitles(file_original_path, title, tvshow, year, season, episode, set_temp=False, rar=False, lang1=lang1, lang2=lang2, lang3=lang3, stack=None) return {'list':subtitles_list, 'session_id':session_id, 'msg':msg}
def SearchSubtitles (self, key): subtitles = [] q_url = "http://gom.gomtv.com/jmdb/search.html?key=%s" %key log(__name__, "search subtitle at %s" %q_url) # main page req = urllib2.Request(q_url) req.add_header("User-Agent", self.agent_str) html = urllib2.urlopen(req).read() if "<div id='search_failed_smi'>" in html: log(__name__, "no result found") return [] elif "<script>location.href" in html: log(__name__, "redirected") if "key=';</script>" in html: log(__name__, "fail to search with given key") return [] q_url = self.parseRedirectionPage(html) req = urllib2.Request(q_url) req.add_header("User-Agent", self.agent_str) html = urllib2.urlopen(req).read() # regular search result page soup = BeautifulSoup(html) subtitles = [] for row in soup.find("table",{"class":"smi_list"}).findAll("tr")[1:]: a_node = row.find("a") if a_node is None: continue title = a_node.text url = self.root_url + a_node["href"] if title.startswith(u"[한글]"): langlong = "Korean" title = title[4:] elif title.startswith(u"[영문]"): langlong = "English" title = title[4:] else: # [통합] langlong = "Korean" langshort = languageTranslate(langlong, 0, 2) subtitles.append( { "link" : url, "filename" : title, "ID" : key, "format" : "smi", "sync" : True, "rating" : "0", "language_name" : langlong, "language_flag" : "flags/%s.gif" %langshort } ) return subtitles
def getAllSubtitles(subtitlePageID,languageList,subtitlesList): # Retrieve the subtitles page (html) subtitlePage = getURL(BASE_URL + "view.php?id=" + subtitlePageID + "&m=subtitles#") # Create a list of all subtitles found on page foundSubtitles = re.findall(SUBTITLE_LIST_PATTERN, subtitlePage) for (fid,language,title) in foundSubtitles: # Check if the subtitles found match one of our languages was selected # by the user if (sratimToScript(language) in languageList): subtitlesList.append({'rating': '0', 'sync': False, 'filename': title, 'subtitle_id': fid, 'language_flag': 'flags/' + \ languageTranslate(sratimToScript(language),0,2) + \ '.gif', 'language_name': sratimToScript(language)})
def pageDownload(self, MainID, MainIDNumber, Page): # Log the page download attempt. self.Log("Message: Retrieving page [%s] for Movie[%s], Id[%s]." % (Page, MainID["title"], MainID["id"])) Response = self._urlopen("http://minister.legendas.tv/util/carrega_legendas_busca/page:%s/id_filme:%s" % (Page, MainID["id"])) if not re.findall(regex_1, Response, re.IGNORECASE | re.DOTALL): self.Log("Error: Failed retrieving page [%s] for Movie[%s], Id[%s]." % (Page, MainID["title"], MainID["id"])) else: for x, content in enumerate(re.findall(regex_1, Response, re.IGNORECASE | re.DOTALL), start=1): LanguageName, LanguageFlag, LanguagePreference = "", "", 0 download_id = content[0] title = self._UNICODE(content[1]) release = self._UNICODE(content[1]) rating = content[2] lang = self._UNICODE(content[3]) if re.search("Portugu.s-BR", lang): LanguageId = "pb" elif re.search("Portugu.s-PT", lang): LanguageId = "pt" elif re.search("Ingl.s", lang): LanguageId = "en" elif re.search("Espanhol", lang): LanguageId = "es" elif re.search("Franc.s", lang): LanguageId = "fr" else: continue for Preference, LangName in self.Languages: if LangName == languageTranslate(LanguageId, 2, 0): LanguageName = LangName LanguageFlag = "flags/%s.gif" % LanguageId LanguagePreference = Preference break if not LanguageName: continue self.DownloadsResults.append({ "main_id_number": int(MainIDNumber), "page": int(Page), "position": int(x), "title": title, "filename": release, "language_name": LanguageName, "ID": download_id, "format": "srt", "sync": False, "rating":rating, "language_flag": LanguageFlag, "language_preference": int(LanguagePreference) }) self.Log("Message: Retrieved [%s] results for page [%s], Movie[%s], Id[%s]." % (x, Page, MainID["title"], MainID["id"]))
def getallsubs(response_url, content, language, title, subtitles_list, search_string): for matches in re.finditer(subtitle_pattern, content, re.IGNORECASE | re.DOTALL): languagefound = matches.group(3) if languagefound == to_subscene_lang(language): link = main_url + matches.group(1) languageshort = languageTranslate(language,0,2) filename = matches.group(4) hearing_imp = len(matches.group(5)) > 0 if search_string != "": log( __name__ , "string.lower(filename) = >" + string.lower(filename) + "<" ) log( __name__ , "string.lower(search_string) = >" + string.lower(search_string) + "<" ) if string.find(string.lower(filename),string.lower(search_string)) > -1: log( __name__ ,"%s Subtitles found: %s, %s" % (debug_pretext, languagefound, filename)) subtitles_list.append({'rating': '0', 'movie': title, 'filename': filename, 'sync': False, 'link': link, 'language_flag': 'flags/' + languageshort + '.gif', 'language_name': language, 'hearing_imp': hearing_imp}) else: log( __name__ ,"%s Subtitles found: %s, %s" % (debug_pretext, languagefound, filename)) subtitles_list.append({'rating': '0', 'movie': title, 'filename': filename, 'sync': False, 'link': link, 'language_flag': 'flags/' + languageshort + '.gif', 'language_name': language, 'hearing_imp': hearing_imp})
def getAllTVSubtitles(fname, subtitlePageID, languageList, season, episode): # Retrieve the subtitles page (html) subs = [] subtitlePage = getURL(BASE_URL + "viewseries.php?id=" + subtitlePageID + "&m=subtitles#") # Retrieve the requested season foundSeasons = re.findall(TV_SEASON_PATTERN, subtitlePage) for (season_link, season_num) in foundSeasons: if (season_num == season): # Retrieve the requested episode subtitlePage = getURL(BASE_URL + "viewseries.php?id=" + subtitlePageID + "&m=subtitles&s=" + str(season_link)) foundEpisodes = re.findall(TV_EPISODE_PATTERN, subtitlePage) for (episode_link, episode_num) in foundEpisodes: if (episode_num == episode): subtitlePage = getURL(BASE_URL + "viewseries.php?id=" + subtitlePageID + "&m=subtitles&s=" + str(season_link) + "&e=" + str(episode_link)) # Create a list of all subtitles found on page foundSubtitles = re.findall(COMBINED, subtitlePage) for (fid, language, title, fid2, language2, title2) in foundSubtitles: log( __name__, "%s Is sendspace?: %s" % (debug_pretext, bool(fid2 and len(fid2) > 0))) # Create Dictionery for XBMC Gui if (fid2 and len(fid2) > 0): fid = fid2 language = language2 title = title2 # Check if the subtitles found match one of our languages was selected # by the user if (sratimToScript(language) in languageList): rating = getrating(title, fname) subs.append({'rating': str(rating), 'sync': rating>=8, 'filename': title, 'subtitle_id': fid, 'language_flag': 'flags/' + \ languageTranslate(sratimToScript(language),0,2) + \ '.gif', 'language_name': sratimToScript(language), 'sendspace': (fid2 and len(fid2)>0)}) # sort, to put syncs on top return sorted(subs, key=lambda x: int(float(x['rating'])), reverse=True)
def download_subtitles (subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, session_id): #standard input subtitle_id = subtitles_list[pos][ "subtitle_id" ] filename = subtitles_list[pos][ "filename" ] key = subtitles_list[pos][ "key" ] # check if need to download subtitle from sendspace if(subtitles_list[pos]["notes"]): # log to sendspace content = getURL(subtitles_list[pos]["notes"].group()) # find download link url = re.search(r'<a id="download_button" href?="(.+sendspace.+\.\w\w\w)" ', content) content = None if (url): url = url.group(1) log( __name__ ,"%s Fetching subtitles from sendspace.com using url %s" % (debug_pretext, url)) content = getURL(url) archive_name = "rarsubs" + re.search(r'\.\w\w\w$',url).group(0) else: url = BASE_URL + "/" + languageTranslate(subtitles_list[pos][ "language_name" ], 0, 2)+"/subtitle/download/"+languageTranslate(subtitles_list[pos][ "language_name" ], 0, 2)+"/"+str(subtitle_id)+"/?v="+filename+"&key="+key log( __name__ ,"%s Fetching subtitles using url %s" % (debug_pretext, url)) # Get the intended filename (don't know if it's zip or rar) archive_name = getURLfilename(url) # Get the file content using geturl() content = getURL(url) subs_file = "" if content: local_tmp_file = os.path.join(tmp_sub_dir, archive_name) log( __name__ ,"%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file)) try: local_file_handle = open(local_tmp_file, "wb") local_file_handle.write(content) local_file_handle.close() except: log( __name__ ,"%s Failed to save subtitles to '%s'" % (debug_pretext, local_tmp_file)) # Extract the zip file and find the new sub/srt file subs_file = extractAndFindSub(tmp_sub_dir,local_tmp_file) # Standard output - # True iff the file is packed as zip: addon will automatically unpack it. # language of subtitles, # Name of subtitles file if not packed (or if we unpacked it ourselves) return False, subtitles_list[pos][ "language_name" ], subs_file
def getAllTVSubtitles(fname, subtitlePageID, languageList, season, episode): # Retrieve the subtitles page (html) subs = [] subtitlePage = getURL(BASE_URL + "viewseries.php?id=" + subtitlePageID + "&m=subtitles#") # Retrieve the requested season foundSeasons = re.findall(TV_SEASON_PATTERN, subtitlePage) for (season_link, season_num) in foundSeasons: if season_num == season: # Retrieve the requested episode subtitlePage = getURL(BASE_URL + "getajax.php?seasonid=" + str(season_link)) foundEpisodes = re.findall(TV_EPISODE_PATTERN, subtitlePage) for (episode_link, episode_num) in foundEpisodes: if episode_num == episode: subtitlePage = getURL(BASE_URL + "getajax.php?episodedetails=" + str(episode_link)) # Create a list of all subtitles found on page foundSubtitles = re.findall(COMBINED, subtitlePage) for (fid, language, title, fid2, language2, title2) in foundSubtitles: log(__name__, "%s Is sendspace?: %s" % (debug_pretext, bool(fid2 and len(fid2) > 0))) # Create Dictionery for XBMC Gui if fid2 and len(fid2) > 0: fid = fid2 language = language2 title = title2 # Check if the subtitles found match one of our languages was selected # by the user if sratimToScript(language) in languageList: rating = getrating(title, fname) subs.append( { "rating": str(rating), "sync": rating >= 8, "filename": title, "subtitle_id": fid, "language_flag": "flags/" + languageTranslate(sratimToScript(language), 0, 2) + ".gif", "language_name": sratimToScript(language), "sendspace": (fid2 and len(fid2) > 0), } ) # sort, to put syncs on top return sorted(subs, key=lambda x: int(float(x["rating"])), reverse=True)
def search_subtitles(file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack): #standard input msg = "" subtitles_list = [] websvc = CineastWebService() title = title.strip() if tvshow: # TvShow log(__name__, "search TVshow with " + tvshow) for result in websvc.searchTvSubtitlesByTitle(tvshow): subtitle = {"format": "smi", "sync": True} subtitle['link'] = result['link'] subtitle['filename'] = result['title'] rating = 0 if season == result['season']: rating += 3 if episode == result['episode']: rating += 3 subtitle['rating'] = str(rating) subtitle['language_name'] = result['language'] subtitle['language_flag'] = "flags/%s.gif" % languageTranslate( result['language'], 0, 2) subtitles_list.append(subtitle) elif title: # Movie srch_title = title query = re.match("^(.*)\(([^\)]*)\)$", title) if query: srch_title = query.group(2).strip() # English title log(__name__, "search Movie with " + srch_title) for result in websvc.searchMovieSubtitlesByTitle(srch_title): subtitle = {"format": "smi", "sync": True} subtitle['link'] = result['link'] subtitle['filename'] = result['title'] subtitle['rating'] = "6" if file_original_path.find( result['relgrp']) > 0 else "0" subtitle['language_name'] = result['language'] subtitle['language_flag'] = "flags/%s.gif" % result[ 'language'][:2].lower() subtitles_list.append(subtitle) else: msg = _(800) 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 ok = False msg = "" subtitles_list = [] languages = {} for lang in (lang1,lang2,lang3): languages[lang]=languageTranslate(lang,0,2) d = timeout(set_filehash, args=(file_original_path, rar), timeout_duration=15) for lang,language in languages.items(): str = "http://napiprojekt.pl/unit_napisy/dl.php?l="+language.upper()+"&f="+d.hexdigest()+"&t="+f(d.hexdigest())+"&v=dreambox&kolejka=false&nick=&pass=&napios="+os.name subs=urllib.urlopen(str).read() if subs[0:4]!='NPc0': flag_image = "flags/%s.gif" % (language,) s={'filename':title,'link':subs,"language_name":lang,"language_flag":flag_image,"language_id":language,"ID":0,"sync":True, "format":"srt", "rating": "" } subtitles_list.append(s) return subtitles_list, "", "" #standard output
def getallsubs(response_url, content, language, title, subtitles_list, search_string): for matches in re.finditer(subtitle_pattern, content, re.IGNORECASE | re.DOTALL): languagefound = matches.group(3) if languagefound == to_subscene_lang(language): link = main_url + matches.group(1) languageshort = languageTranslate(language,0,2) filename = matches.group(4) hearing_imp = (matches.group(5) == "a41") rating = '0' if matches.group(2) == "bad-icon": continue if matches.group(2) == "positive-icon": rating = '5' if search_string != "": log( __name__ , "string.lower(filename) = >" + string.lower(filename) + "<" ) log( __name__ , "string.lower(search_string) = >" + string.lower(search_string) + "<" ) if string.find(string.lower(filename),string.lower(search_string)) > -1: log( __name__ ,"%s Subtitles found: %s, %s" % (debug_pretext, languagefound, filename)) subtitles_list.append({'rating': rating, 'movie': title, 'filename': filename, 'sync': False, 'link': link, 'language_flag': 'flags/' + languageshort + '.gif', 'language_name': language, 'hearing_imp': hearing_imp}) else: log( __name__ ,"%s Subtitles found: %s, %s" % (debug_pretext, languagefound, filename)) subtitles_list.append({'rating': rating, 'movie': title, 'filename': filename, 'sync': False, 'link': link, 'language_flag': 'flags/' + languageshort + '.gif', 'language_name': language, 'hearing_imp': hearing_imp})
def search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack ): # standard input msg = "" subtitles_list = [] websvc = CineastWebService() title = title.strip() if tvshow: # TvShow log(__name__, "search TVshow with " + tvshow) for result in websvc.searchTvSubtitlesByTitle(tvshow): subtitle = {"format": "smi", "sync": True} subtitle["link"] = result["link"] subtitle["filename"] = result["title"] rating = 0 if season == result["season"]: rating += 3 if episode == result["episode"]: rating += 3 subtitle["rating"] = str(rating) subtitle["language_name"] = result["language"] subtitle["language_flag"] = "flags/%s.gif" % languageTranslate(result["language"], 0, 2) subtitles_list.append(subtitle) elif title: # Movie srch_title = title query = re.match("^(.*)\(([^\)]*)\)$", title) if query: srch_title = query.group(2).strip() # English title log(__name__, "search Movie with " + srch_title) for result in websvc.searchMovieSubtitlesByTitle(srch_title): subtitle = {"format": "smi", "sync": True} subtitle["link"] = result["link"] subtitle["filename"] = result["title"] subtitle["rating"] = "6" if file_original_path.find(result["relgrp"]) > 0 else "0" subtitle["language_name"] = result["language"] subtitle["language_flag"] = "flags/%s.gif" % result["language"][:2].lower() subtitles_list.append(subtitle) else: msg = _(800) return subtitles_list, "", msg # standard output
def getAllSubtitles(fname,subtitlePageID,languageList): # Retrieve the subtitles page (html) subs= [] subtitlePage = getURL(BASE_URL + "view.php?id=" + subtitlePageID + "&m=subtitles#") # Create a list of all subtitles found on page foundSubtitles = re.findall(COMBINED, subtitlePage) for (fid,language,title,fid2,language2,title2) in foundSubtitles: log( __name__ ,"%s Is sendspace?: %s" % (debug_pretext, bool(fid2 and len(fid2)>0))) #Create Dictionery for XBMC Gui if(fid2 and len(fid2)>0): fid=fid2 language=language2 title=title2 # Check if the subtitles found match one of our languages was selected # by the user if (sratimToScript(language) in languageList): rating=getrating(title,fname) subs.append({'rating': str(rating), 'sync': rating>=8, 'filename': title, 'subtitle_id': fid, 'language_flag': 'flags/' + \ languageTranslate(sratimToScript(language),0,2) + \ '.gif', 'language_name': sratimToScript(language), 'sendspace': (fid2 and len(fid2)>0)}) return sorted(subs,key=lambda x: int(float(x['rating'])),reverse=True)
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': languageTranslate(subtitle, 2,0),'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 __init__(self, tmp_path, download_path, settings=None, settings_provider=None, captcha_cb=None, delay_cb=None, message_cb=None): assert self.module is not None, 'you have to provide xbmc-subtitles module' logo = os.path.join(os.path.dirname(self.module.__file__), 'logo.png') BaseSeeker.__init__(self, tmp_path, download_path, settings, settings_provider, logo) self.module.captcha_cb = captcha_cb self.module.delay_cb = delay_cb self.module.message_cb = message_cb # xbmc-subtitles module can use maximum of three different languages # we will fill default languages from supported langs in case no languages # were provided. If provider has more than 3 supported languages this just # gets first three languages in supported_langs list, so most of the time its # best to pass languages which will be used for searching if len(self.supported_langs) ==1: self.lang1 = self.lang2 = self.lang3 = languageTranslate(self.supported_langs[0],2,0) elif len(self.supported_langs) ==2: self.lang1 = languageTranslate(self.supported_langs[0],2,0) self.lang2 = languageTranslate(self.supported_langs[1],2,0) self.lang3 = self.lang1 else: self.lang1 = languageTranslate(self.supported_langs[0],2,0) self.lang2 = languageTranslate(self.supported_langs[1],2,0) self.lang3 = languageTranslate(self.supported_langs[2],2,0)
def pageDownload(self, MainID, MainIDNumber, Page): # Log the page download attempt. self.Log("Message: Retrieving page [%s] for Movie[%s], Id[%s]." % (Page, MainID["title"], MainID["id"])) Response = self._urlopen( "http://minister.legendas.tv/util/carrega_legendas_busca/page:%s/id_filme:%s" % (Page, MainID["id"])) if not re.findall(regex_1, Response, re.IGNORECASE | re.DOTALL): self.Log( "Error: Failed retrieving page [%s] for Movie[%s], Id[%s]." % (Page, MainID["title"], MainID["id"])) else: for x, content in enumerate(re.findall(regex_1, Response, re.IGNORECASE | re.DOTALL), start=1): LanguageName, LanguageFlag, LanguagePreference = "", "", 0 download_id = content[0] title = self._UNICODE(content[1]) release = self._UNICODE(content[1]) rating = content[2] lang = self._UNICODE(content[3]) if re.search("Portugu.s-BR", lang): LanguageId = "pb" elif re.search("Portugu.s-PT", lang): LanguageId = "pt" elif re.search("Ingl.s", lang): LanguageId = "en" elif re.search("Espanhol", lang): LanguageId = "es" elif re.search("Franc.s", lang): LanguageId = "fr" else: continue for Preference, LangName in self.Languages: if LangName == languageTranslate(LanguageId, 2, 0): LanguageName = LangName LanguageFlag = "flags/%s.gif" % LanguageId LanguagePreference = Preference break if not LanguageName: continue self.DownloadsResults.append({ "main_id_number": int(MainIDNumber), "page": int(Page), "position": int(x), "title": title, "filename": release, "language_name": LanguageName, "ID": download_id, "format": "srt", "sync": False, "rating": rating, "language_flag": LanguageFlag, "language_preference": int(LanguagePreference) }) self.Log( "Message: Retrieved [%s] results for page [%s], Movie[%s], Id[%s]." % (x, Page, MainID["title"], MainID["id"]))
def SearchSubtitles(self, sessionId, videoHash, title, year, season, episode,language1, language2, language3): title = SaxUtils.escape(title) # Build request XML... requestXML = """<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <SearchSubtitles3 xmlns="http://www.sublight.si/"> <session>%s</session> <videoHash>%s</videoHash> <title>%s</title> %s %s %s <languages> %s %s %s </languages> <genres> <Genre>Movie</Genre> <Genre>Cartoon</Genre> <Genre>Serial</Genre> <Genre>Documentary</Genre> <Genre>Other</Genre> <Genre>Unknown</Genre> </genres> <rateGreaterThan xsi:nil="true" /> </SearchSubtitles3> </soap:Body> </soap:Envelope>""" % ( sessionId, videoHash, title, ( "<year>%s</year>" % year, "<year xsi:nil=\"true\" />" ) [ year == "" ], ( "<season>%s</season>" % season, "<season xsi:nil=\"true\" />" ) [ season == "" ], ( "<episode>%s</episode>" % episode, "<episode xsi:nil=\"true\" />" ) [ episode == "" ], "<SubtitleLanguage>%s</SubtitleLanguage>" % language1, ( "<SubtitleLanguage>%s</SubtitleLanguage>" % language2, "" ) [ language2 == "None" ], ( "<SubtitleLanguage>%s</SubtitleLanguage>" % language3, "" ) [ language3 == "None" ] ) # Call SOAP service... resultXML = self.SOAP_POST (self.SOAP_SUBTITLES_API_URL, self.SEARCH_SUBTITLES_ACTION, requestXML) # Parse result resultDoc = xml.dom.minidom.parseString(resultXML) xmlUtils = XmlUtils() result = xmlUtils.getText(resultDoc, "SearchSubtitles3Result") subtitles = [] if (result == "true") : # Releases... releases = dict() releaseNodes = resultDoc.getElementsByTagName("Release") if releaseNodes != None : for releaseNode in releaseNodes : subtitleID = xmlUtils.getText( releaseNode, "SubtitleID" ) releaseName = xmlUtils.getText( releaseNode, "Name" ) if releaseName > "" : releases[ subtitleID ] = releaseName # Subtitles... subtitleNodes = resultDoc.getElementsByTagName("Subtitle") for subtitleNode in subtitleNodes: title = xmlUtils.getText( subtitleNode, "Title" ) year = xmlUtils.getText( subtitleNode, "Year" ) try: release = releases.get( subtitleID, ("%s (%s)" % ( title, year ) ) ) except : release = "%s (%s)" % ( title, year ) language = xmlUtils.getText( subtitleNode, "Language" ) subtitleID = xmlUtils.getText( subtitleNode, "SubtitleID" ) mediaType = xmlUtils.getText( subtitleNode, "MediaType" ) numberOfDiscs = xmlUtils.getText( subtitleNode, "NumberOfDiscs" ) downloads = xmlUtils.getText( subtitleNode, "Downloads" ) isLinked = xmlUtils.getText( subtitleNode, "IsLinked" ) rate = float(xmlUtils.getText( subtitleNode, "Rate" )) if language == "SerbianLatin": language = "Serbian" if isLinked == "true": linked = True else: linked = False if len(language) > 1: flag_image = "flags/%s.gif" % (languageTranslate(language,0,2)) else: flag_image = "-.gif" subtitles.append( { "title" : title, "year" : year, "filename" : release, "language_name" : language, "ID" : subtitleID, "mediaType" : mediaType, "numberOfDiscs" : numberOfDiscs, "downloads" : downloads, "sync" : linked, "rating" : str(int(round(rate*2))), "language_flag" :flag_image } ) # Return value return subtitles
def getallsubs(searchstring, languageshort, languagelong, file_original_path, subtitles_list, searchstring_notclean): page = 1 cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) #Grabbing login and pass from xbmc settings username = __addon__.getSetting("euTuser") password = __addon__.getSetting("euTpass") login_data = urllib.urlencode({'uid': username, 'pwd': password}) #This is where you are logged in resp = opener.open('http://eutorrents.ph/index.php?page=login', login_data) #log( __name__ ,"%s Getting '%s' ..." % (debug_pretext, resp)) url = main_url + "subtitles.php?action=search&language=" + languageshort + "&pages=" + str( page) + "&search=" + urllib.quote_plus(searchstring) content = opener.open(url) content = content.read() content = content.decode('latin1') #log( __name__ ,"%s CONTENT: '%s'" % (debug_pretext, content)) #log( __name__ ,"%s Getting '%s' subs ..." % (debug_pretext, languageshort)) while re.search(subtitle_pattern, content, re.IGNORECASE | re.DOTALL) and page < 6: for matches in re.finditer(subtitle_pattern, content, re.IGNORECASE | re.DOTALL): hits = matches.group(5) id = matches.group(4) uploader = string.strip(matches.group(2)) downloads = int(matches.group(5)) / 10 if (downloads > 10): downloads = 10 filename = string.strip(matches.group(1)) desc = string.strip(matches.group(1)) #Remove new lines on the commentaries filename = re.sub('\n', ' ', filename) desc = re.sub('\n', ' ', desc) uploader = re.sub('\n', ' ', uploader) #Remove HTML tags on the commentaries filename = re.sub(r'<[^<]+?>', '', filename) uploader = re.sub(r'<[^<]+?>', '', uploader) desc = re.sub(r'<[^<]+?>|[~]', '', desc) #Find filename on the comentaries to show sync label using filename or dirname (making it global for further usage) global filesearch filesearch = os.path.abspath(file_original_path) #For DEBUG only uncomment next line #log( __name__ ,"%s abspath: '%s'" % (debug_pretext, filesearch)) filesearch = os.path.split(filesearch) #For DEBUG only uncomment next line #log( __name__ ,"%s path.split: '%s'" % (debug_pretext, filesearch)) dirsearch = filesearch[0].split(os.sep) #For DEBUG only uncomment next line #log( __name__ ,"%s dirsearch: '%s'" % (debug_pretext, dirsearch)) dirsearch_check = string.split(dirsearch[-1], '.') #For DEBUG only uncomment next line #log( __name__ ,"%s dirsearch_check: '%s'" % (debug_pretext, dirsearch_check)) if (searchstring_notclean != ""): sync = False if re.search(searchstring_notclean, desc): sync = True else: if (string.lower(dirsearch_check[-1]) == "rar") or (string.lower(dirsearch_check[-1]) == "cd1") or (string.lower( dirsearch_check[-1]) == "cd2"): sync = False if len(dirsearch) > 1 and dirsearch[1] != '': if re.search(filesearch[1][:len(filesearch[1]) - 4], desc) or re.search(dirsearch[-2], desc): sync = True else: if re.search(filesearch[1][:len(filesearch[1]) - 4], desc): sync = True else: sync = False if len(dirsearch) > 1 and dirsearch[1] != '': if re.search(filesearch[1][:len(filesearch[1]) - 4], desc) or re.search(dirsearch[-1], desc): sync = True else: if re.search(filesearch[1][:len(filesearch[1]) - 4], desc): sync = True filename = filename + " " + "(sent by: " + uploader + ")" + " " + hits + "hits" subtitles_list.append({ 'rating': str(downloads), 'filename': filename, 'uploader': uploader, 'desc': desc, 'sync': sync, 'hits': hits, 'id': id, 'language_flag': 'flags/' + languageTranslate(languageshort, 3, 2) + '.gif', 'language_name': languagelong }) page = page + 1 url = main_url + "subtitles.php?action=search&language=" + languageshort + "&pages=" + str( page) + "&search=" + urllib.quote_plus(searchstring) content = opener.open(url) content = content.read() content = content.decode('latin1') ### ANNOYING ### # if subtitles_list == []: # msgnote(debug_pretext,"No sub in " + languagelong + "!", 2000) # msgnote(debug_pretext,"Try manual or parent dir!", 2000) # elif subtitles_list != []: # lst = str(subtitles_list) # if languagelong in lst: # msgnote(debug_pretext,"Found sub(s) in " + languagelong + ".", 2000) # else: # msgnote(debug_pretext,"No sub in " + languagelong + "!", 2000) # msgnote(debug_pretext,"Try manual or parent dir!", 2000) # Bubble sort, to put syncs on top for n in range(0, len(subtitles_list)): for i in range(1, len(subtitles_list)): temp = subtitles_list[i] if subtitles_list[i]["sync"] > subtitles_list[i - 1]["sync"]: subtitles_list[i] = subtitles_list[i - 1] subtitles_list[i - 1] = temp
def search_subtitles(file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack): #standard input subtitles_list = [] msg = "" searchstring_notclean = "" searchstring = "" global israr israr = os.path.abspath(file_original_path) israr = os.path.split(israr) israr = israr[0].split(os.sep) israr = string.split(israr[-1], '.') israr = string.lower(israr[-1]) if len(tvshow) == 0: if 'rar' in israr and searchstring is not None: if 'cd1' in string.lower(title) or 'cd2' in string.lower( title) or 'cd3' in string.lower(title): dirsearch = os.path.abspath(file_original_path) dirsearch = os.path.split(dirsearch) dirsearch = dirsearch[0].split(os.sep) if len(dirsearch) > 1: searchstring_notclean = dirsearch[-3] searchstring = xbmc.getCleanMovieTitle(dirsearch[-3]) searchstring = searchstring[0] else: searchstring = title else: searchstring = title elif 'cd1' in string.lower(title) or 'cd2' in string.lower( title) or 'cd3' in string.lower(title): dirsearch = os.path.abspath(file_original_path) dirsearch = os.path.split(dirsearch) dirsearch = dirsearch[0].split(os.sep) if len(dirsearch) > 1: searchstring_notclean = dirsearch[-2] searchstring = xbmc.getCleanMovieTitle(dirsearch[-2]) searchstring = searchstring[0] else: #We are at the root of the drive!!! so there's no dir to lookup only file# title = os.path.split(file_original_path) searchstring = title[-1] else: if title == "": title = os.path.split(file_original_path) searchstring = title[-1] else: searchstring = title if len(tvshow) > 0: searchstring = "%s S%#02dE%#02d" % (tvshow, int(season), int(episode)) log(__name__, "%s Search string = %s" % (debug_pretext, searchstring)) msgnote(debug_pretext, __language__(30153), 6000) getallsubs(searchstring, languageTranslate(lang1, 0, 3), lang1, file_original_path, subtitles_list, searchstring_notclean) getallsubs(searchstring, languageTranslate(lang2, 0, 3), lang2, file_original_path, subtitles_list, searchstring_notclean) getallsubs(searchstring, languageTranslate(lang3, 0, 3), lang3, file_original_path, subtitles_list, searchstring_notclean) return subtitles_list, "", msg #standard output
def lang2_opensubtitles(lang): lang = lang_titulky2xbmclang(lang) return languageTranslate(lang, 0, 2)
def getallsubs(content, title, subtitles_list, file_original_path, stack, lang1, lang2, lang3): soup = BeautifulSoup(content) subs = soup("tr") sub_str = str(subs[1:]) first_row = True languages_map = {'Polski': 'pl', 'Angielski': 'en', 'Niemiecki': 'de'} for row in subs[1:]: sub_number_re = 'a href=\"/download/(\d+)/\"><strong>' title_re = '<a href="/download/\d+?/"><strong>(.+?)</strong></a>' release_re = '<td>(.+?)<br />|<td.+?>(.+?)<br />' rating_re = 'rednia ocena: (\d\,\d\d)<br />' lang_re = 'zyk:.+?alt="(.+?)"' disc_amount_re = '<td.+?style="text-align: center;">[\r\n\t ]+?(\d)[\r\n\t ]+?</td>' video_file_size_re = 'Rozmiar pliku: <strong>(\d+?)</strong>' video_file_size_re_multi = 'Rozmiar pliku:<br />- CD1: <strong>(\d+?)</strong>' archive_re = '<a href="/download/archiwum/(\d+?)/">' row_str = str(row) archive = re.findall(archive_re, row_str) if len(archive) == 0: if first_row == True: sub_number = re.findall(sub_number_re, row_str) subtitle = re.findall(title_re, row_str) release = re.findall(release_re, row_str) disc_amount = re.findall(disc_amount_re, row_str) first_row = False else: file_size, SubHash = hashFile(file_original_path, False) if disc_amount[0] > '1': video_file_size = re.findall(video_file_size_re_multi, row_str) else: video_file_size = re.findall(video_file_size_re, row_str) if len(video_file_size) == 0: video_file_size.append('0') sync_value = False else: video_file_size = unicode(video_file_size[0], "UTF-8") video_file_size = video_file_size.replace(u"\u00A0", "") if file_size == video_file_size: sync_value = True else: sync_value = False rating = re.findall(rating_re, row_str) language = re.findall(lang_re, row_str) if language[0] in languages_map: language = [languages_map[language[0]]] else: language = [] if len(language) > 0: first_row = True link = "%s%s/" % (down_url, sub_number[0]) log( __name__, "Subtitles found: %s %s (link=%s)" % (subtitle[0], release, link)) flag_pic = "flags/%s.gif" % (language[0]) lang = languageTranslate(language[0], 2, 0) if lang == lang1 or lang == lang2 or lang == lang3: for rel in re.findall("\'(.*?)\'", str(release)): rel = rel.replace(",", ":").replace(" ", "") if len(rel) > 1: rel_semicolon = "%s;" % (rel) for rel_sync in re.findall( '(.+?);', rel_semicolon): if rel_sync.upper( ) in file_original_path.upper(): sync_value = True filename_release = "%s - %s" % (subtitle[0], rel_semicolon) rating_dot = rating[0].replace(",", ".") if rating_dot == '0.00': sub_rating = '0' else: sub_rating = int( round(float(rating_dot) * 1.666, 0)) if stack == False: if disc_amount[0] > '1': log(__name__, "Nonstacked video file - stacked subs") else: subtitles_list.append({ 'filename': filename_release, 'sync': sync_value, 'link': link, 'language_flag': flag_pic, 'language_name': lang, 'rating': '%s' % (sub_rating) }) else: if disc_amount[0] > '1': subtitles_list.append({ 'filename': filename_release, 'sync': sync_value, 'link': link, 'language_flag': flag_pic, 'language_name': lang, 'rating': '%s' % (sub_rating) }) else: log(__name__, "Stacked video file - nonstacked subs") else: continue else: continue
def SearchSubtitlesFromTitle (self, searchString,key): subtitles = [] subtitles = [] q_url = "http://gom.gomtv.com/jmdb/search.html?key=%s" %key log(__name__, "search subtitle at %s" %q_url) # main page req = urllib2.Request(q_url) req.add_header("User-Agent", self.agent_str) html = urllib2.urlopen(req).read() if "<div id='search_failed_smi'>" in html: log(__name__, "no result found") return [] elif "<script>location.href" in html: log(__name__, "redirected") if "key=';</script>" in html: log(__name__, "fail to search with given key") return [] q_url = self.parseRedirectionPage(html) req = urllib2.Request(q_url) req.add_header("User-Agent", self.agent_str) html = urllib2.urlopen(req).read() elif "<script>top.location.replace" in html: log(__name__, "redirected") if "key=';</script>" in html: log(__name__, "fail to search with given key") return [] q_url = self.parseRedirectionPage(html) req = urllib2.Request(q_url) req.add_header("User-Agent", self.agent_str) html = urllib2.urlopen(req).read() # regular search result page soup = BeautifulSoup(html) subtitles = [] for row in soup.find("table",{"class":"tbl_lst"}).findAll("tr")[1:]: a_node = row.find("a") if a_node is None: continue title = a_node.text lang_node_string = row.find("span",{"class":"txt_clr3"}).string url = self.root_url + a_node["href"] if u"한글" in lang_node_string: langlong = "Korean" elif u"영문" in lang_node_string: langlong = "English" else: # [통합] langlong = "Korean" langshort = languageTranslate(langlong, 0, 2) subtitles.append( { "link" : url, "filename" : title, "ID" : key, "format" : "smi", "sync" : True, "rating" : "0", "language_name" : langlong, "language_flag" : "flags/%s.gif" %langshort } ) q_url = "http://gom.gomtv.com/main/index.html?ch=subtitles&pt=l&menu=subtitles&lang=0&sValue=%s" %searchString print q_url log(__name__, "search subtitle at %s" %q_url) # main page req = urllib2.Request(q_url) req.add_header("User-Agent", self.agent_str) html = urllib2.urlopen(req).read() if "<div id='search_failed_smi'>" in html: log(__name__, "no result found") return [] elif "<script>location.href" in html: log(__name__, "redirected") if "key=';</script>" in html: log(__name__, "fail to search with given key") return [] q_url = self.parseRedirectionPage(html) req = urllib2.Request(q_url) req.add_header("User-Agent", self.agent_str) html = urllib2.urlopen(req).read() elif "<script>top.location.replace" in html: log(__name__, "redirected") if "key=';</script>" in html: log(__name__, "fail to search with given key") return [] q_url = self.parseRedirectionPage(html) req = urllib2.Request(q_url) req.add_header("User-Agent", self.agent_str) html = urllib2.urlopen(req).read() # regular search result page soup = BeautifulSoup(html) for row in soup.find("table",{"class":"tbl_lst"}).findAll("tr")[1:]: if row is None: continue a_node = row.find("a") if a_node is None: continue title = a_node.text lang_node_string = row.find("span",{"class":"txt_clr3"}).string url = self.root_url + a_node["href"] if u"한글" in lang_node_string: langlong = "Korean" elif u"영문" in lang_node_string: langlong = "English" else: # [통합] langlong = "Korean" langshort = languageTranslate(langlong, 0, 2) subtitles.append( { "link" : url, "filename" : title, "ID" : key, "format" : "smi", "sync" : False, "rating" : "0", "language_name" : langlong, "language_flag" : "flags/%s.gif" %langshort } ) return subtitles
def search_subtitles(file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack): #standard input subtitles_list = [] msg = "" lang1 = languageTranslate(lang1, 0, 2) lang2 = languageTranslate(lang2, 0, 2) lang3 = languageTranslate(lang3, 0, 2) 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)) lang_priorities = [] for lang in [lang1, lang2, lang3]: if lang not in lang_priorities: lang_priorities.append(lang) if (len(file_original_path) > 0) and (len(tvshow) > 0): shows = getShortTV(tvshow) if shows: for show in shows: 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 for show '%s': '%s'" % (show, 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': languageTranslate(lang, 2, 0), 'language_index': lang_priorities.index(lang), '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': languageTranslate(language, 2, 0), 'language_index': lang_priorities.index(language), '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 msg = "" subtitles_list = [] search_url = "http://api.titlovi.com/xml_get_api.ashx?x-dev_api_id=%s&keyword=%s&uiculture=en" languages = [lang1, lang2, lang3] if len(tvshow) > 0: # TvShow search_string = ("%s S%.2dE%.2d" % ( tvshow, int(season), int(episode), )).replace(" ", "+") else: # Movie or not in Library if str(year) == "": # Not in Library title, year = xbmc.getCleanMovieTitle(title) else: # Movie in Library year = year title = title search_string = title.replace(" ", "+") log(__name__, "Search String [ %s ]" % (search_string, )) subtitles = minidom.parseString( geturl(search_url % (base64.b64decode(KEY)[::-1], search_string))).getElementsByTagName("subtitle") if subtitles: url_base = "http://en.titlovi.com/downloads/default.ashx?type=1&mediaid=%s" for subtitle in subtitles: lang = subtitle.getElementsByTagName("language")[0].firstChild.data if lang == "rs": lang = "sr" if lang == "ba": lang = "bs" if lang == "si": lang = "sl" lang_full = languageTranslate(lang, 2, 0) if lang_full in languages: sub_id = subtitle.getElementsByTagName( "url")[0].firstChild.data movie = subtitle.getElementsByTagName( "safeTitle")[0].firstChild.data if subtitle.getElementsByTagName("release")[0].firstChild: filename = "%s - %s" % (movie, subtitle.getElementsByTagName( "release")[0].firstChild.data) else: filename = movie rating = int( float( subtitle.getElementsByTagName("score") [0].firstChild.data) * 2) flag_image = "flags/%s.gif" % lang link = url_base % sub_id.split("-")[-1].replace("/", "") subtitles_list.append({ 'filename': filename, 'link': link, 'language_name': lang_full, 'language_id': lang, 'language_flag': flag_image, 'movie': movie, 'rating': str(rating), 'sync': False }) subtitles_list = sorted(subtitles_list, compare_columns) 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': languageTranslate(subtitle, 2, 0), '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(self, title=None, filepath=None, langs=None, season=None, episode=None, tvshow=None, year=None): """ returns found subtitles dict {'list': [{'filename':str,'language_name':str,'sync':bool},{..},..], 'provider':provider instance} raises SubtitlesSearchError """ assert title is not None or filepath is not None or tvshow is not None, 'title or filepath needs to be provided' self.log.info("search - title: %s, filepath: %s, langs: %s, season: %s, episode: %s, tvshow: %s, year: %s" % ( str(title), str(filepath), str(langs), str(season), str(episode), str(tvshow), str(year))) start_time = time.time() if langs is None: langs = [] valid_langs = langs[:] for l in langs: if l not in self.supported_langs: valid_langs.remove(l) self.log.info('this language is not supported by this provider - "%s"!' % languageTranslate(l,2,0)) try: subtitles = self._search(title, filepath, valid_langs, season, episode, tvshow, year) except socket.timeout as e: self.log.error("timeout error occured: %s" % (str(e))) e = SubtitlesSearchError(SubtitlesErrors.TIMEOUT_ERROR, "timeout!") e.provider = self.id raise except SubtitlesSearchError as e: self.log.error("search error occured: %s" % str(e)) e.provider = self.id raise e except Exception as e: self.log.error("unknown search error occured: %s" % str(e)) err = SubtitlesSearchError(SubtitlesErrors.UNKNOWN_ERROR, str(e)) err.provider = self.id err.wrapped_error = e raise err subtitles['id'] = self.id subtitles['time'] = time.time() - start_time subtitles['params'] ={ 'title':title, 'filepath':filepath, 'langs':langs, 'year':year, 'tvshow':tvshow, 'season':season, 'episode':episode} subtitles.setdefault('list', []) self.log.info("search finished, found %d subtitles in %.2fs" % (len(subtitles['list']), subtitles['time'])) return subtitles
def getallsubs(searchstring, languageshort, languagelong, file_original_path, subtitles_list, searchstring_notclean): page = 1 cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) # Grabbing login and pass from xbmc settings username = __addon__.getSetting("euTuser") password = __addon__.getSetting("euTpass") login_data = urllib.urlencode({"uid": username, "pwd": password}) # This is where you are logged in resp = opener.open("http://eutorrents.ph/index.php?page=login", login_data) # log( __name__ ,"%s Getting '%s' ..." % (debug_pretext, resp)) url = ( main_url + "subtitles.php?action=search&language=" + languageshort + "&pages=" + str(page) + "&search=" + urllib.quote_plus(searchstring) ) content = opener.open(url) content = content.read() content = content.decode("latin1") # log( __name__ ,"%s CONTENT: '%s'" % (debug_pretext, content)) # log( __name__ ,"%s Getting '%s' subs ..." % (debug_pretext, languageshort)) while re.search(subtitle_pattern, content, re.IGNORECASE | re.DOTALL) and page < 6: for matches in re.finditer(subtitle_pattern, content, re.IGNORECASE | re.DOTALL): hits = matches.group(5) id = matches.group(4) uploader = string.strip(matches.group(2)) downloads = int(matches.group(5)) / 10 if downloads > 10: downloads = 10 filename = string.strip(matches.group(1)) desc = string.strip(matches.group(1)) # Remove new lines on the commentaries filename = re.sub("\n", " ", filename) desc = re.sub("\n", " ", desc) uploader = re.sub("\n", " ", uploader) # Remove HTML tags on the commentaries filename = re.sub(r"<[^<]+?>", "", filename) uploader = re.sub(r"<[^<]+?>", "", uploader) desc = re.sub(r"<[^<]+?>|[~]", "", desc) # Find filename on the comentaries to show sync label using filename or dirname (making it global for further usage) global filesearch filesearch = os.path.abspath(file_original_path) # For DEBUG only uncomment next line # log( __name__ ,"%s abspath: '%s'" % (debug_pretext, filesearch)) filesearch = os.path.split(filesearch) # For DEBUG only uncomment next line # log( __name__ ,"%s path.split: '%s'" % (debug_pretext, filesearch)) dirsearch = filesearch[0].split(os.sep) # For DEBUG only uncomment next line # log( __name__ ,"%s dirsearch: '%s'" % (debug_pretext, dirsearch)) dirsearch_check = string.split(dirsearch[-1], ".") # For DEBUG only uncomment next line # log( __name__ ,"%s dirsearch_check: '%s'" % (debug_pretext, dirsearch_check)) if searchstring_notclean != "": sync = False if re.search(searchstring_notclean, desc): sync = True else: if ( (string.lower(dirsearch_check[-1]) == "rar") or (string.lower(dirsearch_check[-1]) == "cd1") or (string.lower(dirsearch_check[-1]) == "cd2") ): sync = False if len(dirsearch) > 1 and dirsearch[1] != "": if re.search(filesearch[1][: len(filesearch[1]) - 4], desc) or re.search(dirsearch[-2], desc): sync = True else: if re.search(filesearch[1][: len(filesearch[1]) - 4], desc): sync = True else: sync = False if len(dirsearch) > 1 and dirsearch[1] != "": if re.search(filesearch[1][: len(filesearch[1]) - 4], desc) or re.search(dirsearch[-1], desc): sync = True else: if re.search(filesearch[1][: len(filesearch[1]) - 4], desc): sync = True filename = filename + " " + "(sent by: " + uploader + ")" + " " + hits + "hits" subtitles_list.append( { "rating": str(downloads), "filename": filename, "uploader": uploader, "desc": desc, "sync": sync, "hits": hits, "id": id, "language_flag": "flags/" + languageTranslate(languageshort, 3, 2) + ".gif", "language_name": languagelong, } ) page = page + 1 url = ( main_url + "subtitles.php?action=search&language=" + languageshort + "&pages=" + str(page) + "&search=" + urllib.quote_plus(searchstring) ) content = opener.open(url) content = content.read() content = content.decode("latin1") ### ANNOYING ### # if subtitles_list == []: # msgnote(debug_pretext,"No sub in " + languagelong + "!", 2000) # msgnote(debug_pretext,"Try manual or parent dir!", 2000) # elif subtitles_list != []: # lst = str(subtitles_list) # if languagelong in lst: # msgnote(debug_pretext,"Found sub(s) in " + languagelong + ".", 2000) # else: # msgnote(debug_pretext,"No sub in " + languagelong + "!", 2000) # msgnote(debug_pretext,"Try manual or parent dir!", 2000) # Bubble sort, to put syncs on top for n in range(0, len(subtitles_list)): for i in range(1, len(subtitles_list)): temp = subtitles_list[i] if subtitles_list[i]["sync"] > subtitles_list[i - 1]["sync"]: subtitles_list[i] = subtitles_list[i - 1] subtitles_list[i - 1] = temp
def getallsubs(content, title, subtitles_list, file_original_path, stack, lang1, lang2, lang3): soup = BeautifulSoup(content) subs = soup("tr") sub_str = str(subs[1:]) first_row = True languages_map = {'Polski': 'pl', 'Angielski': 'en', 'Niemiecki': 'de'} for row in subs[1:]: sub_number_re = 'a href=\"/download/(\d+)/\"><strong>' title_re = '<a href="/download/\d+?/"><strong>(.+?)</strong></a>' release_re = '<td>(.+?)<br />|<td.+?>(.+?)<br />' rating_re = 'rednia ocena: (\d\,\d\d)<br />' lang_re = 'zyk:.+?alt="(.+?)"' disc_amount_re = '<td.+?style="text-align: center;">[\r\n\t ]+?(\d)[\r\n\t ]+?</td>' video_file_size_re = 'Rozmiar pliku: <strong>(\d+?)</strong>' video_file_size_re_multi = 'Rozmiar pliku:<br />- CD1: <strong>(\d+?)</strong>' archive_re = '<a href="/download/archiwum/(\d+?)/">' row_str = str(row) archive = re.findall(archive_re, row_str) if len(archive) == 0: if first_row == True: sub_number = re.findall(sub_number_re, row_str) subtitle = re.findall(title_re, row_str) release = re.findall(release_re, row_str) disc_amount = re.findall(disc_amount_re, row_str) first_row = False else: file_size, SubHash = hashFile(file_original_path, False) if disc_amount[0] > '1': video_file_size = re.findall(video_file_size_re_multi, row_str) else: video_file_size = re.findall(video_file_size_re, row_str) if len(video_file_size) == 0: video_file_size.append('0') sync_value = False else: video_file_size = unicode(video_file_size[0], "UTF-8") video_file_size = video_file_size.replace(u"\u00A0", "") if file_size == video_file_size: sync_value = True else: sync_value = False rating = re.findall(rating_re, row_str) language = re.findall(lang_re, row_str) if language[0] in languages_map: language = [languages_map[language[0]]] else: language = [] if len(language) > 0: first_row = True link = "%s%s/" % (down_url, sub_number[0]) log( __name__ ,"Subtitles found: %s %s (link=%s)" % (subtitle[0], release, link)) flag_pic = "flags/%s.gif" % (language[0]) lang = languageTranslate(language[0],2,0) if lang == lang1 or lang == lang2 or lang == lang3: for rel in re.findall("\'(.*?)\'", str(release)): rel = rel.replace(",",":").replace(" ","") if len(rel) > 1: rel_semicolon = "%s;" % (rel) for rel_sync in re.findall('(.+?);', rel_semicolon): if rel_sync.upper() in file_original_path.upper(): sync_value = True filename_release = "%s - %s" % (subtitle[0], rel_semicolon) rating_dot = rating[0].replace(",",".") if rating_dot == '0.00': sub_rating = '0' else: sub_rating = int(round(float(rating_dot) * 1.666,0)) if stack == False: if disc_amount[0] > '1': log( __name__ ,"Nonstacked video file - stacked subs") else: subtitles_list.append({'filename': filename_release, 'sync': sync_value, 'link': link, 'language_flag': flag_pic, 'language_name': lang,'rating': '%s' % (sub_rating)}) else: if disc_amount[0] > '1': subtitles_list.append({'filename': filename_release, 'sync': sync_value, 'link': link, 'language_flag': flag_pic, 'language_name': lang,'rating': '%s' % (sub_rating)}) else: log( __name__ ,"Stacked video file - nonstacked subs") else: continue else: continue
def search(self, title=None, filepath=None, langs=None, season=None, episode=None, tvshow=None, year=None): """ returns found subtitles dict {'list': [{'filename':str,'language_name':str,'sync':bool},{..},..], 'provider':provider instance} raises SubtitlesSearchError """ assert title is not None or filepath is not None or tvshow is not None, 'title or filepath needs to be provided' self.log.info("search - title: %s, filepath: %s, langs: %s, season: %s, episode: %s, tvshow: %s, year: %s" % ( str(title), str(filepath), str(langs), str(season), str(episode), str(tvshow), str(year))) start_time = time.time() if langs is None: langs = [] valid_langs = langs[:] for l in langs: if l not in self.supported_langs: valid_langs.remove(l) self.log.info('this language is not supported by this provider - "%s"!' % languageTranslate(l,2,0)) try: subtitles = self._search(title, filepath, valid_langs, season, episode, tvshow, year) except socket.timeout as e: self.log.error("timeout error occured: %s" % (str(e))) e = SubtitlesSearchError(SubtitlesErrors.TIMEOUT_ERROR, "timeout!") e.provider = self.id raise e except SubtitlesSearchError as e: self.log.error("search error occured: %s" % str(e)) e.provider = self.id raise e except Exception as e: self.log.error("unknown search error occured: %s" % str(e)) err = SubtitlesSearchError(SubtitlesErrors.UNKNOWN_ERROR, str(e)) err.provider = self.id err.wrapped_error = e raise err subtitles['id'] = self.id subtitles['time'] = time.time() - start_time subtitles['params'] ={ 'title':title, 'filepath':filepath, 'langs':langs, 'year':year, 'tvshow':tvshow, 'season':season, 'episode':episode} self.log.info("search finished, found %d subtitles in %.2fs" % (len(subtitles['list']), subtitles['time'])) return subtitles
def SearchSubtitles(self, sessionId, videoHash, title, year, season, episode, language1, language2, language3): title = SaxUtils.escape(title) # Build request XML... requestXML = """<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <SearchSubtitles3 xmlns="http://www.sublight.si/"> <session>%s</session> <videoHash>%s</videoHash> <title>%s</title> %s %s %s <languages> %s %s %s </languages> <genres> <Genre>Movie</Genre> <Genre>Cartoon</Genre> <Genre>Serial</Genre> <Genre>Documentary</Genre> <Genre>Other</Genre> <Genre>Unknown</Genre> </genres> <rateGreaterThan xsi:nil="true" /> </SearchSubtitles3> </soap:Body> </soap:Envelope>""" % ( sessionId, videoHash, title, ("<year>%s</year>" % year, "<year xsi:nil=\"true\" />")[year == ""], ("<season>%s</season>" % season, "<season xsi:nil=\"true\" />")[season == ""], ("<episode>%s</episode>" % episode, "<episode xsi:nil=\"true\" />")[episode == ""], "<SubtitleLanguage>%s</SubtitleLanguage>" % language1, ("<SubtitleLanguage>%s</SubtitleLanguage>" % language2, "")[language2 == "None"], ("<SubtitleLanguage>%s</SubtitleLanguage>" % language3, "")[language3 == "None"]) # Call SOAP service... resultXML = self.SOAP_POST(self.SOAP_SUBTITLES_API_URL, self.SEARCH_SUBTITLES_ACTION, requestXML) # Parse result resultDoc = xml.dom.minidom.parseString(resultXML) xmlUtils = XmlUtils() result = xmlUtils.getText(resultDoc, "SearchSubtitles3Result") subtitles = [] if (result == "true"): # Releases... releases = dict() releaseNodes = resultDoc.getElementsByTagName("Release") if releaseNodes != None: for releaseNode in releaseNodes: subtitleID = xmlUtils.getText(releaseNode, "SubtitleID") releaseName = xmlUtils.getText(releaseNode, "Name") if releaseName > "": releases[subtitleID] = releaseName # Subtitles... subtitleNodes = resultDoc.getElementsByTagName("Subtitle") for subtitleNode in subtitleNodes: title = xmlUtils.getText(subtitleNode, "Title") year = xmlUtils.getText(subtitleNode, "Year") try: release = releases.get(subtitleID, ("%s (%s)" % (title, year))) except: release = "%s (%s)" % (title, year) language = xmlUtils.getText(subtitleNode, "Language") subtitleID = xmlUtils.getText(subtitleNode, "SubtitleID") mediaType = xmlUtils.getText(subtitleNode, "MediaType") numberOfDiscs = xmlUtils.getText(subtitleNode, "NumberOfDiscs") downloads = xmlUtils.getText(subtitleNode, "Downloads") isLinked = xmlUtils.getText(subtitleNode, "IsLinked") rate = float(xmlUtils.getText(subtitleNode, "Rate")) if language == "SerbianLatin": language = "Serbian" if isLinked == "true": linked = True else: linked = False if len(language) > 1: flag_image = "flags/%s.gif" % (languageTranslate( language, 0, 2)) else: flag_image = "-.gif" subtitles.append({ "title": title, "year": year, "filename": release, "language_name": language, "ID": subtitleID, "mediaType": mediaType, "numberOfDiscs": numberOfDiscs, "downloads": downloads, "sync": linked, "rating": str(int(round(rate * 2))), "language_flag": flag_image }) # Return value return subtitles
def lng_short2flag(lang): return languageTranslate(lng_short2long(lang), 0, 2)
def search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack ): #standard input subtitles_list = [] msg = "" lang1 = languageTranslate(lang1,0,2) lang2 = languageTranslate(lang2,0,2) lang3 = languageTranslate(lang3,0,2) 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': languageTranslate(lang,2,0),'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': languageTranslate(language,2,0),'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 lang2_opensubtitles(lang): lang = lang_titulky2xbmclang(lang) return languageTranslate(lang,0,2)