Exemplo n.º 1
0
def fetch_subs_youtube(video_url):
    video_id = video_url.videoid
    channel_id = video_url.owner_username
    if not channel_id:
        logger.warn("fetch_subs() no username: %s", video_url.pk)
        return
    try:
        account = YouTubeAccount.objects.get(channel_id=channel_id)
    except YouTubeAccount.DoesNotExist:
        logger.warn("fetch_subs() no youtube account for %s", channel_id)
        return

    existing_langs = set(
        l.language_code for l in
        video_url.video.newsubtitlelanguage_set.having_versions()
    )

    access_token = google.get_new_access_token(account.oauth_refresh_token)
    captions_list = google.captions_list(access_token, video_id)
    versions = []
    for caption_id, language_code, caption_name in captions_list:
        language_code = convert_language_code(language_code)
        if language_code and language_code not in existing_langs:
            dfxp = google.captions_download(access_token, caption_id)
            try:
                version = pipeline.add_subtitles(video_url.video, language_code, dfxp,
                                       note="From youtube", complete=True,
                                       origin=ORIGIN_IMPORTED)
                versions.append(version)
            except Exception, e:
                logger.error("Exception while importing subtitles " + str(e))
Exemplo n.º 2
0
def fetch_subs_youtube(video_url):
    video_id = video_url.videoid
    channel_id = video_url.owner_username
    if not channel_id:
        logger.warn("fetch_subs() no username: %s", video_url.pk)
        return
    try:
        account = YouTubeAccount.objects.get(channel_id=channel_id)
    except YouTubeAccount.DoesNotExist:
        logger.warn("fetch_subs() no youtube account for %s", channel_id)
        return

    existing_langs = set(
        l.language_code
        for l in video_url.video.newsubtitlelanguage_set.having_versions())

    access_token = google.get_new_access_token(account.oauth_refresh_token)
    captions_list = google.captions_list(access_token, video_id)
    for caption_id, youtube_language_code, caption_name in captions_list:
        language_code = (LanguageCode(youtube_language_code,
                                      'youtube').encode('unisubs'))
        if language_code not in existing_langs:
            dfxp = google.captions_download(access_token, caption_id)
            pipeline.add_subtitles(video_url.video,
                                   language_code,
                                   dfxp,
                                   note="From youtube",
                                   complete=True,
                                   origin=ORIGIN_IMPORTED)
Exemplo n.º 3
0
def fetch_subs_youtube(video_url, user, team):
    video_id = video_url.videoid
    channel_id = video_url.owner_username
    account = find_youtube_account(
        video_id, lookup_youtube_accounts(video_url, user, team))
    if account is None:
        logger.warn("fetch_subs() no available credentials.")
        return
    existing_langs = set(
        l.language_code
        for l in video_url.video.newsubtitlelanguage_set.having_versions())
    access_token = google.get_new_access_token(account.oauth_refresh_token)
    captions_list = google.captions_list(access_token, video_id)
    versions = []
    for caption_id, language_code, caption_name in captions_list:
        language_code = convert_language_code(language_code)
        if language_code and language_code not in existing_langs:
            dfxp = google.captions_download(access_token, caption_id)
            try:
                version = pipeline.add_subtitles(video_url.video,
                                                 language_code,
                                                 dfxp,
                                                 note="From youtube",
                                                 complete=True,
                                                 origin=ORIGIN_IMPORTED)
                versions.append(version)
            except Exception, e:
                logger.error("Exception while importing subtitles " + str(e))