• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python transcripts_utils.download_youtube_subs函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中xmodule.video_module.transcripts_utils.download_youtube_subs函数的典型用法代码示例。如果您正苦于以下问题:Python download_youtube_subs函数的具体用法?Python download_youtube_subs怎么用?Python download_youtube_subs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了download_youtube_subs函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: replace_transcripts

def replace_transcripts(request):
    """
    Replaces all transcripts with youtube ones.

    Downloads subtitles from youtube and replaces all transcripts with downloaded ones.

    Returns: status `Success` and resulted item.sub value or status `Error` and HTTP 400.
    """
    response = {'status': 'Error', 'subs': ''}

    try:
        __, videos, item = _validate_transcripts_data(request)
    except TranscriptsRequestValidationException as e:
        return error_response(response, e.message)

    youtube_id = videos['youtube']
    if not youtube_id:
        return error_response(response, 'YouTube id {} is not presented in request data.'.format(youtube_id))

    try:
        download_youtube_subs({1.0: youtube_id}, item, settings)
    except GetTranscriptsFromYouTubeException as e:
        return error_response(response, e.message)

    item.sub = youtube_id
    item.save_with_metadata(request.user)
    response = {'status': 'Success',  'subs': item.sub}
    return JsonResponse(response)
开发者ID:BeiLuoShiMen,项目名称:edx-platform,代码行数:28,代码来源:transcripts_ajax.py


示例2: test_video_with_subs_and_transcript_index_dictionary

    def test_video_with_subs_and_transcript_index_dictionary(self):
        """
        Test index dictionary of a video module with
        YouTube subtitles and German transcript uploaded by a user.
        """
        xml_data_sub_transcript = '''
            <video display_name="Test Video"
                   youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
                   show_captions="false"
                   download_track="false"
                   sub="OEoXaMPEzfM"
                   start_time="00:00:01"
                   download_video="false"
                   end_time="00:01:00">
              <source src="http://www.example.com/source.mp4"/>
              <track src="http://www.example.com/track"/>
              <handout src="http://www.example.com/handout"/>
              <transcript language="ge" src="subs_grmtran1.srt" />
            </video>
        '''

        descriptor = instantiate_descriptor(data=xml_data_sub_transcript)
        download_youtube_subs('OEoXaMPEzfM', descriptor, settings)
        save_to_store(SRT_FILEDATA, "subs_grmtran1.srt", 'text/srt', descriptor.location)
        self.assertEqual(descriptor.index_dictionary(), {
            "content": {
                "display_name": "Test Video",
                "transcript_en": YOUTUBE_SUBTITLES,
                "transcript_ge": "sprechen sie deutsch? Ja, ich spreche Deutsch",
            },
            "content_type": "Video"
        })
开发者ID:Edraak,项目名称:edx-platform,代码行数:32,代码来源:test_video.py


示例3: test_success_downloading_subs

    def test_success_downloading_subs(self):

        response = textwrap.dedent("""<?xml version="1.0" encoding="utf-8" ?>
                <transcript>
                    <text start="0" dur="0.27"></text>
                    <text start="0.27" dur="2.45">Test text 1.</text>
                    <text start="2.72">Test text 2.</text>
                    <text start="5.43" dur="1.73">Test text 3.</text>
                </transcript>
        """)
        good_youtube_sub = 'good_id_2'
        self.clear_sub_content(good_youtube_sub)

        with patch('xmodule.video_module.transcripts_utils.requests.get') as mock_get:
            mock_get.return_value = Mock(status_code=200, text=response, content=response)
            # Check transcripts_utils.GetTranscriptsFromYouTubeException not thrown
            transcripts_utils.download_youtube_subs(good_youtube_sub, self.course, settings)

        mock_get.assert_any_call('http://video.google.com/timedtext', params={'lang': 'en', 'v': 'good_id_2'})

        # Check asset status after import of transcript.
        filename = 'subs_{0}.srt.sjson'.format(good_youtube_sub)
        content_location = StaticContent.compute_location(self.course.id, filename)
        self.assertTrue(contentstore().find(content_location))

        self.clear_sub_content(good_youtube_sub)
开发者ID:chiragrawal94,项目名称:openedx,代码行数:26,代码来源:test_transcripts_utils.py


示例4: test_video_with_youtube_subs_index_dictionary

    def test_video_with_youtube_subs_index_dictionary(self):
        """
        Test index dictionary of a video module with YouTube subtitles.
        """
        xml_data_sub = '''
            <video display_name="Test Video"
                   youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
                   show_captions="false"
                   download_track="false"
                   sub="OEoXaMPEzfM"
                   start_time="00:00:01"
                   download_video="false"
                   end_time="00:01:00">
              <source src="http://www.example.com/source.mp4"/>
              <track src="http://www.example.com/track"/>
              <handout src="http://www.example.com/handout"/>
            </video>
        '''

        descriptor = instantiate_descriptor(data=xml_data_sub)
        download_youtube_subs('OEoXaMPEzfM', descriptor, settings)
        self.assertEqual(descriptor.index_dictionary(), {
            "content": {
                "display_name": "Test Video",
                "transcript_en": YOUTUBE_SUBTITLES
            },
            "content_type": "Video"
        })
开发者ID:Edraak,项目名称:edx-platform,代码行数:28,代码来源:test_video.py


示例5: test_fail_downloading_subs

    def test_fail_downloading_subs(self, mock_get):

        mock_get.return_value = Mock(status_code=404, text='Error 404')

        bad_youtube_sub = 'BAD_YOUTUBE_ID2'
        self.clear_sub_content(bad_youtube_sub)

        with self.assertRaises(transcripts_utils.GetTranscriptsFromYouTubeException):
            transcripts_utils.download_youtube_subs(bad_youtube_sub, self.course, settings)
开发者ID:cpennington,项目名称:edx-platform,代码行数:9,代码来源:test_transcripts_utils.py


示例6: test_downloading_subs_using_transcript_name

    def test_downloading_subs_using_transcript_name(self, mock_get):
        """
        Download transcript using transcript name in url
        """
        good_youtube_sub = 'good_id_2'
        self.clear_sub_content(good_youtube_sub)

        transcripts_utils.download_youtube_subs(good_youtube_sub, self.course, settings)
        mock_get.assert_any_call(
            'http://video.google.com/timedtext',
            params={'lang': 'en', 'v': 'good_id_2', 'name': 'Custom'}
        )
开发者ID:cpennington,项目名称:edx-platform,代码行数:12,代码来源:test_transcripts_utils.py


示例7: replace_transcripts

def replace_transcripts(request):
    """
    Downloads subtitles from youtube and replaces edx transcripts in DS with youtube ones.

    Returns:
        status `Success` and resulted `edx_video_id` value
        Or error on validation failures.
    """
    error, validated_data = validate_transcripts_request(request, include_yt=True)
    youtube_id = validated_data['youtube']
    if error:
        response = error_response({}, error)
    elif not youtube_id:
        response = error_response({}, _(u'YouTube ID is required.'))
    else:
        # 1. Download transcript from YouTube.
        try:
            video = validated_data['video']
            transcript_content = download_youtube_subs(youtube_id, video, settings)
        except GetTranscriptsFromYouTubeException as e:
            return error_response({}, text_type(e))

        # 2. Link a video to video component if its not already linked to one.
        edx_video_id = link_video_to_component(video, request.user)

        # 3. Upload YT transcript to DS for the linked video ID.
        success = save_video_transcript(edx_video_id, Transcript.SJSON, transcript_content, language_code=u'en')
        if success:
            response = JsonResponse({'edx_video_id': edx_video_id, 'status': 'Success'}, status=200)
        else:
            response = error_response({}, _('There is a problem with the YouTube transcript file.'))

    return response
开发者ID:cpennington,项目名称:edx-platform,代码行数:33,代码来源:transcripts_ajax.py


示例8: test_fail_downloading_subs

    def test_fail_downloading_subs(self, mock_get):

        mock_get.return_value = Mock(status_code=404, text="Error 404")

        bad_youtube_sub = "BAD_YOUTUBE_ID2"
        self.clear_sub_content(bad_youtube_sub)

        with self.assertRaises(transcripts_utils.GetTranscriptsFromYouTubeException):
            transcripts_utils.download_youtube_subs(bad_youtube_sub, self.course, settings)

        # Check asset status after import of transcript.
        filename = "subs_{0}.srt.sjson".format(bad_youtube_sub)
        content_location = StaticContent.compute_location(self.course.id, filename)
        with self.assertRaises(NotFoundError):
            contentstore().find(content_location)

        self.clear_sub_content(bad_youtube_sub)
开发者ID:hastexo,项目名称:edx-platform,代码行数:17,代码来源:test_transcripts_utils.py


示例9: test_downloading_subs_using_transcript_name

    def test_downloading_subs_using_transcript_name(self, mock_get):
        """
        Download transcript using transcript name in url
        """
        good_youtube_sub = "good_id_2"
        self.clear_sub_content(good_youtube_sub)

        transcripts_utils.download_youtube_subs(good_youtube_sub, self.course, settings)
        mock_get.assert_any_call(
            "http://video.google.com/timedtext", params={"lang": "en", "v": "good_id_2", "name": "Custom"}
        )

        # Check asset status after import of transcript.
        filename = "subs_{0}.srt.sjson".format(good_youtube_sub)
        content_location = StaticContent.compute_location(self.course.id, filename)
        self.assertTrue(contentstore().find(content_location))

        self.clear_sub_content(good_youtube_sub)
开发者ID:hastexo,项目名称:edx-platform,代码行数:18,代码来源:test_transcripts_utils.py


示例10: test_downloading_subs_using_transcript_name

    def test_downloading_subs_using_transcript_name(self, mock_get):
        """
        Download transcript using transcript name in url
        """
        good_youtube_sub = 'good_id_2'
        self.clear_sub_content(good_youtube_sub)

        transcripts_utils.download_youtube_subs(good_youtube_sub, self.course, settings)
        mock_get.assert_any_call(
            'http://video.google.com/timedtext',
            params={'lang': 'en', 'v': 'good_id_2', 'name': 'Custom'}
        )

        # Check asset status after import of transcript.
        filename = 'subs_{0}.srt.sjson'.format(good_youtube_sub)
        content_location = StaticContent.compute_location(self.course.id, filename)
        self.assertTrue(contentstore().find(content_location))

        self.clear_sub_content(good_youtube_sub)
开发者ID:chiragrawal94,项目名称:openedx,代码行数:19,代码来源:test_transcripts_utils.py


示例11: test_success_downloading_chinese_transcripts

    def test_success_downloading_chinese_transcripts(self):

        # Disabled 11/14/13
        # This test is flakey because it performs an HTTP request on an external service
        # Re-enable when `requests.get` is patched using `mock.patch`
        raise SkipTest

        good_youtube_sub = "j_jEn79vS3g"  # Chinese, utf-8
        self.clear_sub_content(good_youtube_sub)

        # Check transcripts_utils.GetTranscriptsFromYouTubeException not thrown
        transcripts_utils.download_youtube_subs(good_youtube_sub, self.course, settings)

        # Check assets status after importing subtitles.
        for subs_id in good_youtube_subs.values():
            filename = "subs_{0}.srt.sjson".format(subs_id)
            content_location = StaticContent.compute_location(self.course.id, filename)
            self.assertTrue(contentstore().find(content_location))

        self.clear_sub_content(good_youtube_sub)
开发者ID:hastexo,项目名称:edx-platform,代码行数:20,代码来源:test_transcripts_utils.py


示例12: test_fail_downloading_subs

    def test_fail_downloading_subs(self, mock_get):

        mock_get.return_value = Mock(status_code=404, text='Error 404')

        bad_youtube_subs = {
            0.5: 'BAD_YOUTUBE_ID1',
            1.0: 'BAD_YOUTUBE_ID2',
            2.0: 'BAD_YOUTUBE_ID3'
        }
        self.clear_subs_content(bad_youtube_subs)
        with self.assertRaises(transcripts_utils.GetTranscriptsFromYouTubeException):
            transcripts_utils.download_youtube_subs(bad_youtube_subs, self.course, settings)

        # Check assets status after importing subtitles.
        for subs_id in bad_youtube_subs.values():
            filename = 'subs_{0}.srt.sjson'.format(subs_id)
            content_location = StaticContent.compute_location(
                self.org, self.number, filename
            )
            with self.assertRaises(NotFoundError):
                contentstore().find(content_location)

        self.clear_subs_content(bad_youtube_subs)
开发者ID:SPRIME01,项目名称:edx-platform,代码行数:23,代码来源:test_transcripts_utils.py


示例13: json_update_videos

def json_update_videos(request, locations):
    """
    Updates the captions of a given list of videos and returns the status of the
    videos in json format

    request: the incoming request to update the videos
    locations: list of locations of videos to be updated
    """
    results = []
    for key_string in locations:
        key = UsageKey.from_string(key_string)
        try:
            #update transcripts
            item = modulestore().get_item(key)
            download_youtube_subs(item.youtube_id_1_0, item, settings)

            # Once transcripts downloaded, show subs are present from youtube
            item.sub = item.youtube_id_1_0
            manage_video_subtitles_save(item, request.user)

            #get new status
            videos = {'youtube': item.youtube_id_1_0}
            html5 = {}
            for url in item.html5_sources:
                name = os.path.splitext(url.split('/')[-1])[0]
                html5[name] = 'html5'
            videos['html5'] = html5
            captions_dict = get_transcripts_presence(videos, item)
            captions_dict.update({'location': key_string})
            results.append(captions_dict)

        except GetTranscriptsFromYouTubeException as e:
            log.debug(e)
            results.append({'location': key_string, 'command': e})

    return JsonResponse(results)
开发者ID:caesar2164,项目名称:edx-platform,代码行数:36,代码来源:captions.py


示例14: test_index_dictionary

    def test_index_dictionary(self):
        xml_data = '''
            <video display_name="Test Video"
                   youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
                   show_captions="false"
                   download_track="false"
                   start_time="00:00:01"
                   download_video="false"
                   end_time="00:01:00">
              <source src="http://www.example.com/source.mp4"/>
              <track src="http://www.example.com/track"/>
              <handout src="http://www.example.com/handout"/>
            </video>
        '''
        descriptor = instantiate_descriptor(data=xml_data)
        self.assertEqual(descriptor.index_dictionary(), {
            "content": {"display_name": "Test Video"},
            "content_type": "Video"
        })

        xml_data_sub = '''
            <video display_name="Test Video"
                   youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
                   show_captions="false"
                   download_track="false"
                   sub="OEoXaMPEzfM"
                   start_time="00:00:01"
                   download_video="false"
                   end_time="00:01:00">
              <source src="http://www.example.com/source.mp4"/>
              <track src="http://www.example.com/track"/>
              <handout src="http://www.example.com/handout"/>
            </video>
        '''

        descriptor = instantiate_descriptor(data=xml_data_sub)
        download_youtube_subs('OEoXaMPEzfM', descriptor, settings)
        self.assertEqual(descriptor.index_dictionary(), {
            "content": {
                "display_name": "Test Video",
                "transcript_en": (
                    "LILA FISHER: Hi, welcome to Edx. I'm Lila Fisher, an Edx fellow helping to put together these"
                    "courses. As you know, our courses are entirely online. So before we start learning about the"
                    "subjects that brought you here, let's learn about the tools that you will use to navigate through"
                    "the course material. Let's start with what is on your screen right now. You are watching a video"
                    "of me talking. You have several tools associated with these videos. Some of them are standard"
                    "video buttons, like the play Pause Button on the bottom left. Like most video players, you can see"
                    "how far you are into this particular video segment and how long the entire video segment is."
                    "Something that you might not be used to is the speed option. While you are going through the"
                    "videos, you can speed up or slow down the video player with these buttons. Go ahead and try that"
                    "now. Make me talk faster and slower. If you ever get frustrated by the pace of speech, you can"
                    "adjust it this way. Another great feature is the transcript on the side. This will follow along"
                    "with everything that I am saying as I am saying it, so you can read along if you like. You can"
                    "also click on any of the words, and you will notice that the video jumps to that word. The video"
                    "slider at the bottom of the video will let you navigate through the video quickly. If you ever"
                    "find the transcript distracting, you can toggle the captioning button in order to make it go away"
                    "or reappear. Now that you know about the video player, I want to point out the sequence navigator."
                    "Right now you're in a lecture sequence, which interweaves many videos and practice exercises. You"
                    "can see how far you are in a particular sequence by observing which tab you're on. You can"
                    "navigate directly to any video or exercise by clicking on the appropriate tab. You can also"
                    "progress to the next element by pressing the Arrow button, or by clicking on the next tab. Try"
                    "that now. The tutorial will continue in the next video."
                )
            },
            "content_type": "Video"
        })

        xml_data_sub_transcript = '''
            <video display_name="Test Video"
                   youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
                   show_captions="false"
                   download_track="false"
                   sub="OEoXaMPEzfM"
                   start_time="00:00:01"
                   download_video="false"
                   end_time="00:01:00">
              <source src="http://www.example.com/source.mp4"/>
              <track src="http://www.example.com/track"/>
              <handout src="http://www.example.com/handout"/>
              <transcript language="ge" src="subs_grmtran1.srt" />
            </video>
        '''

        descriptor = instantiate_descriptor(data=xml_data_sub_transcript)
        save_to_store(SRT_FILEDATA, "subs_grmtran1.srt", 'text/srt', descriptor.location)
        self.assertEqual(descriptor.index_dictionary(), {
            "content": {
                "display_name": "Test Video",
                "transcript_en": (
                    "LILA FISHER: Hi, welcome to Edx. I'm Lila Fisher, an Edx fellow helping to put together these"
                    "courses. As you know, our courses are entirely online. So before we start learning about the"
                    "subjects that brought you here, let's learn about the tools that you will use to navigate through"
                    "the course material. Let's start with what is on your screen right now. You are watching a video"
                    "of me talking. You have several tools associated with these videos. Some of them are standard"
                    "video buttons, like the play Pause Button on the bottom left. Like most video players, you can see"
                    "how far you are into this particular video segment and how long the entire video segment is."
                    "Something that you might not be used to is the speed option. While you are going through the"
                    "videos, you can speed up or slow down the video player with these buttons. Go ahead and try that"
                    "now. Make me talk faster and slower. If you ever get frustrated by the pace of speech, you can"
                    "adjust it this way. Another great feature is the transcript on the side. This will follow along"
#.........这里部分代码省略.........
开发者ID:akbargumbira,项目名称:Labster.EdX,代码行数:101,代码来源:test_video.py



注:本文中的xmodule.video_module.transcripts_utils.download_youtube_subs函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python transcripts_utils.generate_srt_from_sjson函数代码示例发布时间:2022-05-26
下一篇:
Python video_module.VideoDescriptor类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap