def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder,
                       session_id):  #standard input
    page_id = subtitles_list[pos]["page_id"]
    subtitle_id = subtitles_list[pos]["subtitle_id"]

    icon = os.path.join(__cwd__, "icon.png")
    delay = 20
    download_wait = delay
    downloader = TorecSubtitlesDownloader()
    # Wait the minimal time needed for retrieving the download link
    for i in range(int(download_wait)):
        downloadLink = downloader.getDownloadLink(page_id, subtitle_id, False)
        if (downloadLink != None):
            break
        line2 = "download will start in %i seconds" % (delay, )
        xbmc.executebuiltin("XBMC.Notification(%s,%s,1000,%s)" %
                            (__scriptname__, line2, icon))
        delay -= 1
        time.sleep(1)

    log(__name__, "Downloading subtitles from '%s'" % downloadLink)
    (subtitleData, subtitleName) = downloader.download(downloadLink)

    log(__name__, "Saving subtitles to '%s'" % zip_subs)
    downloader.saveData(zip_subs, subtitleData, False)

    return True, "Hebrew", ""  #standard output
def search_subtitles(file_original_path, title, tvshow, year, season, episode,
                     set_temp, rar, lang1, lang2, lang3,
                     stack):  #standard input
    # Build an adequate string according to media type
    if tvshow:
        search_string = "%s S%02dE%02d" % (tvshow, int(season), int(episode))
    else:
        search_string = title

    subtitles_list = []
    msg = ""
    downloader = TorecSubtitlesDownloader()
    metadata = downloader.getSubtitleMetaData(search_string)
    if metadata != None:
        for option in metadata.options:
            subtitles_list.append({
                'page_id': metadata.id,
                'filename': option.name,
                'language_flag': "flags/he.gif",
                'language_name': "Hebrew",
                'subtitle_id': option.id,
                'sync': False,
                'rating': "0",
            })

    return subtitles_list, "", msg
Beispiel #3
0
def search(item):
    best_match_id = None
    downloader = TorecSubtitlesDownloader()

    try:
        search_string = build_search_string(item)
        search_data = downloader.getSubtitleMetaData(search_string)

        log(__name__, "search_data=%s" % str(search_data))
        if search_data != None:
            best_match_id = downloader.getBestMatchID(
                os.path.basename(item['file_original_path']), search_data)
    except:
        log(__name__, "failed to connect to service for subtitle search")
        xbmc.executebuiltin(
            (u'Notification(%s,%s)' %
             (__scriptname__, __language__(32001))).encode('utf-8'))
        return

    list_items = []
    if search_data != None:
        for item_data in search_data.options:
            listitem = xbmcgui.ListItem(
                label="Hebrew",
                label2=item_data.name,
                iconImage="0",
                thumbnailImage="he",
            )

            url = "plugin://%s/?action=download&page_id=%s&subtitle_id=%s&filename=%s" % (
                __scriptid__, search_data.id, item_data.id, item_data.name)

            if best_match_id != None and item_data.id == best_match_id:
                listitem.setProperty("sync", "true")
                list_items.insert(0, (
                    url,
                    listitem,
                    False,
                ))
            else:
                list_items.append((
                    url,
                    listitem,
                    False,
                ))

    xbmcplugin.addDirectoryItems(handle=int(sys.argv[1]), items=list_items)
def download(sub_id, option_id, filename, stack=False):
    result = None
    subtitle_list = []
    exts = [".srt", ".sub"]
    downloader = TorecSubtitlesDownloader()
    start_time = time.time()

    delete_old_subs()

    try:
        result = downloader.get_download_link(sub_id, option_id)
    except Exception as e:
        log(__name__,"failed to connect to service for subtitle download %s" % e)
        return subtitle_list
        
    if result is not None:
        log(__name__, "Downloading subtitles from '%s'" % result)
        
        (subtitle_data, subtitle_name) = downloader.download(result)
        (file_name, file_ext) = os.path.splitext(subtitle_name)
        archive_file = os.path.join(__temp__, "Torec%s" % file_ext)
        with open(archive_file, "wb") as subFile:
            subFile.write(subtitle_data)

        xbmc.executebuiltin(
            ('XBMC.Extract("%s","%s")' % (archive_file, __temp__,)
             ).encode('utf-8'), True)

        for file_ in xbmcvfs.listdir(__temp__)[1]:
            ufile = file_.decode('utf-8')
            log(__name__, "file=%s" % ufile)
            file_ = os.path.join(__temp__, ufile)
            if os.path.splitext(ufile)[1] in exts:
                convert_to_utf(file_)
                subtitle_list.append(file_)
      
    log(__name__, "Overall download took %f" % (time.time() - start_time))
    return subtitle_list
Beispiel #5
0
def download(page_id, subtitle_id, filename, stack=False):
    subtitle_list = []
    exts = [".srt", ".sub"]

    delay = 20
    download_wait = delay
    downloader = TorecSubtitlesDownloader()

    try:
        # Wait the minimal time needed for retrieving the download link
        for i in range(int(download_wait)):
            result = downloader.getDownloadLink(page_id, subtitle_id, False)
            if (result != None):
                break
            log(__name__, "download will start in %i seconds" % (delay, ))
            delay -= 1
            time.sleep(1)
    except:
        log(__name__, "failed to connect to service for subtitle download")
        return subtitle_list

    if result != None:
        log(__name__, "Downloading subtitles from '%s'" % result)

        (subtitleData, subtitleName) = downloader.download(result)

        zip = os.path.join(__temp__, "Torec.zip")
        downloader.saveData(zip, subtitleData)

        for file in xbmcvfs.listdir(__temp__)[1]:
            log(__name__, "file=%s" % file)
            file = os.path.join(__temp__, file)
            if (os.path.splitext(file)[1] in exts):
                subtitle_list.append(file)

    return subtitle_list
Beispiel #6
0
 def setUpClass(self):
     self.downloader = TorecSubtitlesDownloader()
def search(item):
    best_match_id = None
    downloader = TorecSubtitlesDownloader()
    subtitles_options = None
    
    start_time = time.time()

    try:
        search_start_time = time.time()
        
        if (item['mansearch'] == False):
            if item['tvshow'] != "":
                subtitles_options = downloader.search_tvshow(item['tvshow'], item['season'], item['episode'])
            else:              
                title, year = xbmc.getCleanMovieTitle(item['title'])
                subtitles_options = downloader.search_movie(title)
        else:
            item['tvshow'], item['season'], item['episode'] = check_and_parse_if_title_is_TVshow(item['title'])
            if (item['tvshow'] == "NotTVShow"):
                item['title'] = item['title'].replace("%20", "%2b") # " " to "+"
                title, year = xbmc.getCleanMovieTitle(item['title'])
                subtitles_options = downloader.search_movie(title)
            else:
                subtitles_options = downloader.search_tvshow(item['tvshow'], int(item['season']), int(item['episode']))
                                    
        log(__name__, "search took %f" % (time.time() - search_start_time))
    except Exception as e:
        log(
            __name__,
            "failed to connect to service for subtitle search %s" % e
        )
        xbmc.executebuiltin(
            (u'Notification(%s,%s)' % (__scriptname__, __language__(32001))
             ).encode('utf-8'))
        return
    
    list_items = []
    if subtitles_options:
        best_match_option_id = downloader.get_best_match_id(
            os.path.basename(item['file_original_path']), subtitles_options
        )

        for item_data in subtitles_options:
            listitem = xbmcgui.ListItem(
                label="Hebrew", label2=item_data.name, iconImage="0",
                thumbnailImage="he"
            )
            url = (
                "plugin://%s/?action=download&sub_id=%s&option_id="
                "%s&filename=%s" % (
                    __scriptid__, item_data.sub_id, item_data.option_id, item_data.name
                )
            )

            if item_data.option_id == best_match_option_id:
                log(
                    __name__, "Found most relevant option to be : %s" %
                              item_data.name
                )
                listitem.setProperty("sync", "true")
                list_items.insert(0, (url, listitem, False,))
            else:
                list_items.append((url, listitem, False,))

    xbmcplugin.addDirectoryItems(handle=int(sys.argv[1]), items=list_items)
    log(__name__, "Overall search took %f" % (time.time() - start_time))