def search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3 ): #standard input
       
    ok = False
    msg = ""
    hash_search = False
    osdb_server = OSDBServer()
    osdb_server.create()    
    subtitles_list = []
    file_size = ""
    hashTry = ""
    language1 = twotoone(toOpenSubtitles_two(lang1))
    language2 = twotoone(toOpenSubtitles_two(lang2))
    language3 = twotoone(toOpenSubtitles_two(lang3))  
    if set_temp : 
      hash_search = False      
    else:
      try:
        hashTry = timeout(set_filehash, args=(file_original_path, rar), timeout_duration=5)
        file_size = os.path.getsize( file_original_path )
        hash_search = True
      except: 
        hash_search = False 
    
    if file_size != "": log( __name__ ,"File Size [%s]" % file_size )
    if hashTry != "":   log( __name__ ,"File Hash [%s]" % hashTry)
    if hash_search :
      log( __name__ ,"Search for [%s] by hash" % (os.path.basename( file_original_path ),))
      subtitles_list, session_id = osdb_server.searchsubtitles_pod( hashTry ,language1, language2, language3)
    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 )
    return subtitles_list, "", "" #standard output
def query_Film(name, file_original_path,year, langs):
    sublinks = []
    name = urllib.quote(name.replace(" ", "_"))
    searchurl = "%s/film/%s_(%s)-Download" %(self_host,name, str(year))
    socket.setdefaulttimeout(5)
    page = urllib2.urlopen(searchurl)
    content = page.read()
    content = content.replace("The safer, easier way", "The safer, easier way \" />")
    soup = BeautifulSoup(content)
    for subs in soup("td", {"class":"NewsTitle", "colspan" : "3"}):
      try:
        langs_html = subs.findNext("td", {"class" : "language"})
        fullLanguage = str(langs_html).split('class="language">')[1].split('&nbsp;<a')[0].replace("\n","")
        subteams = self_release_pattern.match(str(subs.contents[1])).groups()[0].lower()
        file_name = os.path.basename(file_original_path).lower()
        if (file_name.find(str(subteams))) > -1:
          hashed = True
        else:
          hashed = False  
        try:
          lang = toOpenSubtitles_two(fullLanguage)
        except:
          lang = ""
        statusTD = langs_html.findNext("td")
        status = statusTD.find("strong").string.strip()
        link = "%s%s"%(self_host,statusTD.findNext("td").find("a")["href"])
        if status == "Completed" and (lang in langs) :
            sublinks.append({'filename':"%s-%s" %(name.replace("_", ".").title(),subteams ),'link':link,'language_name':fullLanguage,'language_id':lang,'language_flag':"flags/%s.gif" % (lang,),'movie':"movie","ID":"subtitle_id","rating":"0","format":"srt","sync":hashed})
      except:
        pass
    return sublinks    
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/"+toOpenSubtitles_two(subtitles_list[pos][ "language_name" ])+"/"+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
Exemple #4
0
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/"+toOpenSubtitles_two(subtitles_list[pos][ "language_name" ])+"/"+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
Exemple #5
0
def getallsubs(content, language, search_string, season, episode):
    i = 0
    for matches in re.finditer(subtitle_pattern, content, re.IGNORECASE | re.DOTALL):
        i = i + 1
        title_found = unescape(string.rstrip(matches.group(2)))
        log( __name__ , title_found )
        log( __name__ , search_string )
        if string.find(string.lower(title_found),string.lower(search_string)) > -1:
            subtitle_id    = matches.group(1)
            year_found     = matches.group(3)
            season_episode_found = string.rstrip(matches.group(4))
            filename = title_found
            languageshort = toOpenSubtitles_two(language)
            match = re.match(subinfo_pattern, matches.group(5), re.IGNORECASE | re.DOTALL)
            if match:
                description = match.group(1)
                filename = filename + ' ' + description
            if len(season) > 0:
                season_episode = 'Sezona' + season + ' Epizoda' + episode
                if season_episode == season_episode_found:
                    subtitles_list.append({'rating': '0', 'sync': False, 'filename': filename, 'subtitle_id': subtitle_id, 'language_flag': 'flags/' + languageshort+ '.gif', 'language_name': language})
                    log( __name__ ,"%s Subtitles found: %s (id = %s)" % (debug_pretext, filename, subtitle_id))
            else:
                if len(season_episode_found) == 0:
                    subtitles_list.append({'rating': '0', 'sync': False, 'filename': filename, 'subtitle_id': subtitle_id, 'language_flag': 'flags/' + languageshort+ '.gif', 'language_name': language})
                    log( __name__ ,"%s Subtitles found: %s (id = %s)" % (debug_pretext, filename, subtitle_id))
Exemple #6
0
def getAllTVSubtitles(subtitlePageID, languageList, subtitlesList, season,
                      episode):
    # Retrieve the subtitles page (html)
    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(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/' + \
                                                  toOpenSubtitles_two(sratimToScript(language)) + \
                                                  '.gif', 'language_name': sratimToScript(language)})
Exemple #7
0
def search_subtitles(file_original_path, title, tvshow, year, season, episode,
                     set_temp, rar, lang1, lang2, lang3):  #standard input

    ok = False
    msg = ""
    subtitles_list = []
    languages = {}
    for lang in (lang1, lang2, lang3):
        languages[lang] = toOpenSubtitles_two(lang)

    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 query_TvShow(name, season, episode, file_original_path, langs):
    sublinks = []
    name = name.lower().replace(" ", "_").replace("$#*!","shit").replace("'","") # need this for $#*! My Dad Says and That 70s show
    searchurl = "%s/serie/%s/%s/%s/addic7ed" %(self_host, name, season, episode)
    socket.setdefaulttimeout(3)
    page = urllib2.urlopen(searchurl)
    content = page.read()
    content = content.replace("The safer, easier way", "The safer, easier way \" />")
    soup = BeautifulSoup(content)
    for subs in soup("td", {"class":"NewsTitle", "colspan" : "3"}):
      try:  
        langs_html = subs.findNext("td", {"class" : "language"})
        fullLanguage = str(langs_html).split('class="language">')[1].split('&nbsp;<a')[0].replace("\n","")
        subteams = self_release_pattern.match(str(subs.contents[1])).groups()[0].lower()
        file_name = os.path.basename(file_original_path).lower()
        if (file_name.find(str(subteams))) > -1:
          hashed = True
        else:
          hashed = False
        try:
          lang = toOpenSubtitles_two(fullLanguage)
        except:
          lang = ""
        statusTD = langs_html.findNext("td")
        status = statusTD.find("strong").string.strip()
        link = "%s%s"%(self_host,statusTD.findNext("td").find("a")["href"])
        if status == "Completed" and (lang in langs) :
            sublinks.append({'filename':"%s.S%.2dE%.2d-%s" %(name.replace("_", ".").title(), int(season), int(episode),subteams ),'link':link,'language_name':fullLanguage,'language_id':lang,'language_flag':"flags/%s.gif" % (lang,),'movie':"movie","ID":"subtitle_id","rating":"0","format":"srt","sync":hashed})
      except:
        print "Error"
        pass      
    return sublinks
def getallsubs(content, language, search_string, season, episode):
    i = 0
    for matches in re.finditer(subtitle_pattern, content, re.IGNORECASE | re.DOTALL):
        i = i + 1
        title_found = unescape(string.rstrip(matches.group(2)))
        log( __name__ , title_found )
        log( __name__ , search_string )
        if string.find(string.lower(title_found),string.lower(search_string)) > -1:
            subtitle_id    = matches.group(1)
            year_found     = matches.group(3)
            season_episode_found = string.rstrip(matches.group(4))
            filename = title_found
            languageshort = toOpenSubtitles_two(language)
            match = re.match(subinfo_pattern, matches.group(5), re.IGNORECASE | re.DOTALL)
            if match:
                description = match.group(1)
                filename = filename + ' ' + description
            if len(season) > 0:
                season_episode = 'Sezona' + season + ' Epizoda' + episode
                if season_episode == season_episode_found:
                    subtitles_list.append({'rating': '0', 'sync': False, 'filename': filename, 'subtitle_id': subtitle_id, 'language_flag': 'flags/' + languageshort+ '.gif', 'language_name': language})
                    log( __name__ ,"%s Subtitles found: %s (id = %s)" % (debug_pretext, filename, subtitle_id))
            else:
                if len(season_episode_found) == 0:
                    subtitles_list.append({'rating': '0', 'sync': False, 'filename': filename, 'subtitle_id': subtitle_id, 'language_flag': 'flags/' + languageshort+ '.gif', 'language_name': language})
                    log( __name__ ,"%s Subtitles found: %s (id = %s)" % (debug_pretext, filename, subtitle_id))
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 = twotoone(toOpenSubtitles_two(lang1))
    language2 = twotoone(toOpenSubtitles_two(lang2))
    language3 = twotoone(toOpenSubtitles_two(lang3))
    if set_temp:
        hash_search = False
    else:
        try:
            try:
                file_size, hashTry = xbmc.subHashAndFileSize(
                    file_original_path)
                log(__name__, "xbmc module hash and size")
            except:
                hashTry = timeout(set_filehash,
                                  args=(file_original_path, rar),
                                  timeout_duration=5)
                file_size = str(os.path.getsize(file_original_path))
            hash_search = True
        except:
            hash_search = False

    if file_size != "": log(__name__, "File Size [%s]" % file_size)
    if hashTry != "": log(__name__, "File Hash [%s]" % hashTry)
    if hash_search:
        log(
            __name__, "Search for [%s] by hash" %
            (os.path.basename(file_original_path), ))
        subtitles_list, session_id = osdb_server.searchsubtitles_pod(
            hashTry, 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
Exemple #11
0
def get_languages(languages):
    subdb_languages = []
    for language in languages:
        code = toOpenSubtitles_two(language)
        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 ): #standard input
    subtitles_list = []
    langs = []
    langs.append(toOpenSubtitles_two(lang1))
    if lang1 != lang2:
      langs.append(toOpenSubtitles_two(lang2))
    if lang3 != lang1 and lang3 != lang2:
      langs.append(toOpenSubtitles_two(lang3))
    msg = ""
    log( __name__ ,"Title = %s" %  title)
    if len(tvshow) == 0: # TV Shows
        subtitles_list = query_Film(title, file_original_path,year, langs)
    else:
        subtitles_list = query_TvShow(tvshow, str(season), str(episode),file_original_path, langs)
        if( len ( subtitles_list ) > 0 ):
            subtitles_list = sorted(subtitles_list, compare_columns)
    return subtitles_list, "", msg #standard output
Exemple #13
0
def get_languages(languages):
	subdb_languages = []
	for language in languages:
		code = toOpenSubtitles_two(language)
		if code == 'pb':
			code = 'pt'
		subdb_languages.append(code)
	return subdb_languages
Exemple #14
0
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 = toOpenSubtitles_two(language)
            filename = matches.group(4)
            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
                    })
            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
                })
Exemple #15
0
def getAllSubtitles(subtitlePageID, languageList, subtitlesList):
    # Retrieve the subtitles page (html)
    subtitlePage = getURL(BASE_URL + "subtitles.php?mid=" + subtitlePageID)
    # 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/' + \
                                  toOpenSubtitles_two(sratimToScript(language)) + \
                                  '.gif', 'language_name': sratimToScript(language)})
Exemple #16
0
def getAllSubtitles(subtitlePageID,languageList,subtitlesList):
    # Retrieve the subtitles page (html)
    subtitlePage = getURL(BASE_URL + "subtitles.php?mid=" + subtitlePageID)
    # 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/' + \
                                  toOpenSubtitles_two(sratimToScript(language)) + \
                                  '.gif', 'language_name': sratimToScript(language)})
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 = toOpenSubtitles_two(language)
            filename   = matches.group(4)
            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})
            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})
def getAllSubtitles(subtitlePageID, languageList, subtitlesList):
    # Retrieve the subtitles page (html)
    subtitlePage = getURL(BASE_URL + "subtitles.php?mid=" + subtitlePageID)
    # 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/" + toOpenSubtitles_two(sratimToScript(language)) + ".gif",
                    "language_name": sratimToScript(language),
                }
            )
Exemple #19
0
def search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3 ): #standard input
       
    ok = False
    msg = ""    
    subtitles_list = []    
    languages = {}
    for lang in (lang1,lang2,lang3):
        languages[lang]=toOpenSubtitles_two(lang)
        
    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 getAllTVSubtitles(subtitlePageID,languageList,subtitlesList,season,episode):
    # Retrieve the subtitles page (html)
    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(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/' + \
                                                  toOpenSubtitles_two(sratimToScript(language)) + \
                                                  '.gif', 'language_name': sratimToScript(language)})
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
Exemple #22
0
  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" % (toOpenSubtitles_two(language))
        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       
Exemple #23
0
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 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" % (toOpenSubtitles_two(language))
                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 lang2_opensubtitles(lang):
    lang = lang_titulky2xbmclang(lang)
    return toOpenSubtitles_two(lang)
def lang2_opensubtitles(lang):
	lang = lang_titulky2xbmclang(lang)
	return toOpenSubtitles_two(lang)