Beispiel #1
0
    def test_fetch_subs_skips_existing_languages(self):
        # test that we don't try to get subtitles for languages that already
        # have data in the DB
        self.mock_captions_list.return_value = [
            ('caption-1', 'en', 'English'),
        ]

        existing_version = pipeline.add_subtitles(self.video, 'en', None)
        fetch_subs(self.video_url)
        assert_equal(self.mock_captions_download.call_count, 0)
        assert_equal(
            self.video.subtitle_language('en').get_tip(), existing_version)
Beispiel #2
0
def fetch_subs(video_url_id, user_id=None, team_id=None):
    if team_id is None:
        team = None
    else:
        team = Team.objects.get(id=team_id)
    if user_id is None:
        user = None
    else:
        user = User.objects.get(id=user_id)
    try:
        subfetch.fetch_subs(VideoUrl.objects.get(id=video_url_id), user, team)
    except google.OAuthError:
        logger.exception("Error fetching sutitles")
Beispiel #3
0
    def test_fetch_subs(self):
        self.mock_captions_list.return_value = [
            ('caption-1', 'en', 'English'),
            ('caption-2', 'fr', 'French'),
        ]

        en_subs = storage.SubtitleSet('en')
        en_subs.append_subtitle(100, 200, 'text')
        fr_subs = storage.SubtitleSet('fr')
        fr_subs.append_subtitle(100, 200, 'french text')

        def captions_download(access_token, video_id, language_code):
            if language_code == 'en':
                return en_subs.to_xml()
            elif language_code == 'fr':
                return fr_subs.to_xml()
            else:
                raise ValueError(language_code)

        self.mock_captions_download.side_effect = captions_download

        fetch_subs(self.video_url)
        # check that we called the correct API methods
        assert_equal(self.mock_get_new_access_token.call_args,
                     mock.call(self.account.oauth_refresh_token))

        assert_equal(self.mock_captions_list.call_args,
                     mock.call('test-access-token', self.video_id))
        assert_equal(self.mock_captions_download.call_args_list, [
            mock.call('test-access-token', self.video_id, 'en'),
            mock.call('test-access-token', self.video_id, 'fr'),
        ])
        # check that we created the correct languages
        assert_equal(
            set(l.language_code for l in self.video.all_subtitle_languages()),
            set(['en', 'fr']))
        lang_en = self.video.subtitle_language('en')
        lang_fr = self.video.subtitle_language('fr')
        # check subtitle data
        assert_equal(lang_en.get_tip().get_subtitles().to_xml(),
                     en_subs.to_xml())
        assert_equal(lang_fr.get_tip().get_subtitles().to_xml(),
                     fr_subs.to_xml())
        # check additional data
        assert_equal(lang_en.subtitles_complete, True)
        assert_equal(lang_fr.subtitles_complete, True)
        assert_equal(lang_en.get_tip().origin, ORIGIN_IMPORTED)
        assert_equal(lang_fr.get_tip().origin, ORIGIN_IMPORTED)
        assert_equal(lang_en.get_tip().note, "From youtube")
        assert_equal(lang_fr.get_tip().note, "From youtube")
Beispiel #4
0
    def test_fetch_subs_handles_bcp47_codes(self):
        # youtube uses BCP-47 language codes.  Ensure that we use this code
        # when talking to youtube, but our own internal codes when storing
        # subtitles.
        self.mock_captions_list.return_value = [
            ('caption-1', 'pt-BR', 'Brazilian Portuguese'),
        ]

        subs = storage.SubtitleSet('pt-br')
        subs.append_subtitle(100, 200, 'text')
        self.mock_captions_download.return_value = subs.to_xml()

        fetch_subs(self.video_url, user=self.user)
        assert_equal(self.mock_captions_download.call_args,
                     mock.call('test-access-token', 'caption-1'))

        assert_equal(
            [l.language_code for l in self.video.all_subtitle_languages()],
            ['pt-br'])
Beispiel #5
0
def fetch_subs(video_url_id):
    subfetch.fetch_subs(VideoUrl.objects.get(id=video_url_id))