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 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 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 #4
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
def DownloadTorecSubtitle(search_string, release, dest_dir):
    subtitles_list = []

    downloader = TorecSubtitlesDownloader()
    metadata = downloader.getSubtitleMetaData(search_string)

    for option in metadata.options:
        if release in option.name:
            subtitles_list.append({'page_id'       : metadata.id,
                                   'filename'      : option.name,
                                   'subtitle_id'   : option.id
                                })

    # If there is one match, download it
    if len(subtitles_list) == 1:
        sub = 0
    else:
        print 'Select sub : '

        for i,sub in enumerate(subtitles_list):
          print '%s) %s' % (i, sub['filename'])

        sub = int(raw_input(' > '))

    page_id = subtitles_list[sub]["page_id"]
    subtitle_id = subtitles_list[sub]["subtitle_id"]
    filename = subtitles_list[sub]["filename"]

    downloader = TorecSubtitlesDownloader()
    downloadLink =  downloader.getDownloadLink(page_id, subtitle_id, False)
    (subtitleData, subtitleName) = downloader.download(downloadLink)
    temp_dir = tempfile.mkdtemp()
    file_name = downloader.saveData('%s/%s' % (temp_dir, filename) , subtitleData, True)
    src = os.path.join(temp_dir,file_name)
    dst = os.path.join(dest_dir,file_name)
    log(__name__, "Moving file to %s" % dst)
    shutil.move(src,dst)