コード例 #1
0
ファイル: amara_upload.py プロジェクト: rubesovm/KSTools
    if opts.amara == True:
        ytid_to = ytids[i][1]
    else:
        ytid_to = ytids[i][0]

    video_url_from = 'https://www.youtube.com/watch?v=%s' % ytid_from
    video_url_to = 'https://www.youtube.com/watch?v=%s' % ytid_to

    #   PART 1: GETTING THE SUBTITLES
    # set this to false if you want to download only
    # when language is missing on Amara
    download_first = False
    subs = False
    if opts.yt and download_first == True:
        subs = download_yt_subtitles(lang, sub_format, ytid_from)
        if not subs:
            if opts.skip:
                answer = True
            else:
                answer = answer_me("Should I continue with the rest anyway?")
            if answer:
                continue
            else:
                sys.exit(1)

    elif opts.files == True:
        f = open(ytids[i][1], "r")
        subs = f.read()

    elif opts.amara == True:
コード例 #2
0
    # Moved this here due to large number of Amara errors...
    if not video_present:
        amara_response = amara.add_video(video_url, original_video_lang)
        if "id" in amara_response:
            amara_id = amara_response['id']
            amara_title = amara_response['title']
        else:
            print("ERROR: During adding video to Amara. YTID=%s" % ytid)
            continue
        if opts.verbose:
            print("Created video on Amara with AmaraId %s" % amara_id)
            print("%s/cs/videos/%s" % (amara.AMARA_BASE_URL, amara_id))

    # PART 2: GETTING THE SUBTITLES FROM YOUTUBE
    # imported from utils.py
    subs = download_yt_subtitles(opts.lang, sub_format, ytid, TEMP_DIR)

    # PART 3: Creating language on Amara
    if not lang_present:
        r = amara.add_language(amara_id, opts.lang, is_original)

    # PART 4: UPLOADING THE SUBTITLES
    r = amara.upload_subs(amara_id, opts.lang, is_complete, subs, sub_format)
    if not 'version_number' in r:
        print("ERROR: Failed to upload subs to Amara for YTID=%s" % ytid)
        epprint(r)
        continue
    else:
        print("Succesfully uploaded subtitles for YTID=%s AmaraID=%s" %
              (ytid, amara_id))
        uploaded += 1
コード例 #3
0
ファイル: download_subs.py プロジェクト: rubesovm/KSTools
    if opts.video:
        video_download_cmd = "youtube-dl %s" % video_url
        p = Popen(video_download_cmd, shell=True, stdout=PIPE, stderr=PIPE)
        out, err = p.communicate()
        with open("youtubedl.out", 'a') as f:
            f.write(out.decode('UTF-8'))
        if err:
            print(err)
            sys.exit(1)
        else:
            print("Successfully downloaded video from %s" % video_url)

    if opts.youtube:

        subs = download_yt_subtitles(opts.lang, opts.sub_format, ytid, opts.dirname)

    elif opts.amara:

        # TODO: Extract this to utils as well.

        # First, get Amara ID
        amara_response = amara.check_video(video_url)
        if amara_response['meta']['total_count'] == 0:
            print("ERROR: Video is not on Amara! YTID=%s" % ytid)
            sys.exit(1)
        else:
            amara_id =  amara_response['objects'][0]['id']
            amara_title =  amara_response['objects'][0]['title']
            print("Downloading %s subtitles for YTID=%s" % (opts.lang, ytid))
            print("Title: %s" % amara_title)
コード例 #4
0
# Main loop
for i in range(len(ytids)):
    if len(ytids[i]) == 0:
        print("")
        continue
    ytid = ytids[i][0]

    sys.stdout.flush()
    sys.stderr.flush()

    # 1. DOWNLOAD SUBS
    if opts.file_dir is not None:
        subs = read_subs_from_file(ytid, lang, opts.file_dir, SUB_FORMAT)
    elif opts.yt_download:
        backup_dir = "subs_backup_%s" % lang
        subs = download_yt_subtitles(lang, SUB_FORMAT, ytid, backup_dir)
    else:
        subs = download_subs_from_public_amara(amara, ytid, lang)

    # 1.5 Correct common mistakes
    # Remove double spaces between words
    subs = replace_double_spaces(subs)

    # Trying to reduce E 429
    if opts.sleep_int > 0:
        sleep(opts.sleep_int)

    # 2. UPLOAD TO PRIVATE KHAN ACADEMY AMARA
    # Check whether the video is already on Amara
    video_url = 'https://www.youtube.com/watch?v=%s' % ytid
    amara_id_private = None