當前位置: 首頁>>代碼示例>>Python>>正文


Python YouTubeSubtitleControl.YouTubeSubtitleControl類代碼示例

本文整理匯總了Python中YouTubeSubtitleControl.YouTubeSubtitleControl的典型用法代碼示例。如果您正苦於以下問題:Python YouTubeSubtitleControl類的具體用法?Python YouTubeSubtitleControl怎麽用?Python YouTubeSubtitleControl使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了YouTubeSubtitleControl類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_convertSecondsToTimestamp_should_convert

    def test_convertSecondsToTimestamp_should_convert(self):
        player = YouTubeSubtitleControl()

        res = player.convertSecondsToTimestamp(250.43800000000002)
        print repr(res)

        assert(res == "0:04:10.438")
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:7,代碼來源:TestYouTubeSubtitleControl.py

示例2: test_getSubtitleUrl_should_call_fetchPage_with_correct_url

    def test_getSubtitleUrl_should_call_fetchPage_with_correct_url(self):
        player = YouTubeSubtitleControl()
        sys.modules["__main__"].core._fetchPage = Mock()
        sys.modules["__main__"].core._fetchPage.return_value = {"status": 303, "content": ""}

        player.getSubtitleUrl({"videoid": "some_id"})

        sys.modules["__main__"].core._fetchPage.assert_called_with({"link": player.urls["timed_text_index"] % ('some_id')})
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:8,代碼來源:TestYouTubeSubtitleControl.py

示例3: test_transformAnnotationToSSA_should_parse_youtube_annotations_xml

    def test_transformAnnotationToSSA_should_parse_youtube_annotations_xml(self):
        player = YouTubeSubtitleControl()
        sys.modules["__main__"].common.replaceHTMLCodes = Mock()
        sys.modules["__main__"].common.replaceHTMLCodes.side_effect = lambda x: x.encode("ascii", 'ignore')
        sys.modules["__main__"].common.parseDOM.side_effect = [["content TEXT"], ["TEXT"], ["popup"], ["popup"], ["0:00:06.5", "0:01:06.5"], [0], [0], [0], [0], [["snode"]], ["16777215"], ["26777215"], ["36777215"], ["46777215"]]

        (result, style) = player.transformAnnotationToSSA(self.readTestInput("annotationsTest.xml", False).encode("utf-8"))
        print repr(result)
        assert(len(result.split("\r\n")) == 2)
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:9,代碼來源:TestYouTubeSubtitleControl.py

示例4: test_saveSubtitle_should_call_openFile_with_correct_params

    def test_saveSubtitle_should_call_openFile_with_correct_params(self):
        sys.modules["__main__"].xbmc.translatePath.return_value = "tempFilePath"
        sys.modules["__main__"].common.makeUTF8.return_value = "testTitle"
        subtitles = YouTubeSubtitleControl()
        subtitles.getSubtitleFileName = Mock(return_value="testTitle-[someVideoId].ssa")

        subtitles.saveSubtitle("my_subtitle_stream", {"Title": "testTitle", "videoid": "someVideoId", "downloadPath": "downloadFilePath"})

        sys.modules["__main__"].storage.openFile.assert_called_with("tempFilePath/testTitle-[someVideoId].ssa", "w") # was "wb"
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:9,代碼來源:TestYouTubeSubtitleControl.py

示例5: test_getTranscriptionUrl_should_call_return_correct_url

 def test_getTranscriptionUrl_should_call_return_correct_url(self):
     player = YouTubeSubtitleControl()
     sys.modules["__main__"].core._fetchPage = Mock()
     sys.modules["__main__"].core._fetchPage.return_value = {"status": 303, "content": ""}
     sys.modules["__main__"].settings.getSetting = Mock()
     sys.modules["__main__"].settings.getSetting.return_value = "1"
     ret = player.getTranscriptionUrl({"videoid": "some_id", "ttsurl": "http://some.url/transcript"})
     print ret
     assert(ret == "http://some.url/transcript&type=trackformat=1&lang=en&kind=asr&name=&v=some_id&tlang=en")
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:9,代碼來源:TestYouTubeSubtitleControl.py

示例6: test_transformSubtitleXMLtoSRT_should_parse_youtube_subtitle_xml

    def test_transformSubtitleXMLtoSRT_should_parse_youtube_subtitle_xml(self):
        player = YouTubeSubtitleControl()
        sys.modules["__main__"].common.replaceHTMLCodes = Mock()
        sys.modules["__main__"].common.replaceHTMLCodes.side_effect = lambda x: x.encode("ascii", 'ignore')
        sys.modules["__main__"].common.parseDOM.side_effect = [["content"] * 3, ["content"], ["00"], ["10"], ["content1"], ["20"], ["30"], ["content3"], ["40"], ["50"]]

        result = player.transformSubtitleXMLtoSRT(self.readTestInput("subtitleTest.xml", False))

        assert(len(result.split("\r\n")) == 4)
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:9,代碼來源:TestYouTubeSubtitleControl.py

示例7: test_saveSubtitle_should_call_xbmcvfs_translatePath

    def test_saveSubtitle_should_call_xbmcvfs_translatePath(self):
        sys.modules["__main__"].xbmc.translatePath.return_value = "tempFilePath"
        sys.modules["__main__"].common.makeUTF8.return_value = "testTitle"

        subtitles = YouTubeSubtitleControl()
        subtitles.getSubtitleFileName = Mock()

        subtitles.saveSubtitle("my_subtitle_stream", {"Title": "testTitle", "videoid": "someVideoId", "downloadPath": "downloadFilePath"})

        sys.modules["__main__"].xbmc.translatePath.assert_called_with("somepath")
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:10,代碼來源:TestYouTubeSubtitleControl.py

示例8: test_transformAnnotationToSSA_should_call_replaceHTMLCodes_for_user_visible_text

    def test_transformAnnotationToSSA_should_call_replaceHTMLCodes_for_user_visible_text(self):
        player = YouTubeSubtitleControl()
        sys.modules["__main__"].common.replaceHTMLCodes = Mock()
        sys.modules["__main__"].common.replaceHTMLCodes.side_effect = lambda x: x.encode("ascii", 'ignore')
        sys.modules["__main__"].common.parseDOM.side_effect = [["content TEXT"], ["TEXT"], ["bla"], ["bla2"], []]

        result = player.transformAnnotationToSSA(self.readTestInput("annotationsTest.xml", False).encode("utf-8"))
        print repr(result)

        assert(sys.modules["__main__"].common.replaceHTMLCodes.call_count > 0)
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:10,代碼來源:TestYouTubeSubtitleControl.py

示例9: test_addSubtitles_should_wait_for_playback_to_start_before_adding_subtitle

    def test_addSubtitles_should_wait_for_playback_to_start_before_adding_subtitle(self):
        player = YouTubeSubtitleControl()
        player.getSubtitleFileName = Mock(return_value="testTitle-[testid].ssa")
        sys.modules["__main__"].settings.getSetting.return_value = "testDownloadPath"
        sys.modules["__main__"].xbmcvfs.exists.return_value = True
        sys.modules["__main__"].common.makeUTF8.return_value = "testTitle"
        player.addSubtitles({"videoid": "testid", "Title": "testTitle"})

        sys.modules["__main__"].xbmc.Player().isPlaying.assert_called_with()
        sys.modules["__main__"].xbmc.Player().setSubtitles.assert_called_with('testDownloadPath/testTitle-[testid].ssa')
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:10,代碼來源:TestYouTubeSubtitleControl.py

示例10: test_transformSubtitleXMLtoSRT_should_call_replaceHTMLCodes_for_user_visible_text

    def test_transformSubtitleXMLtoSRT_should_call_replaceHTMLCodes_for_user_visible_text(self):
        sys.modules["__main__"].common.parseDOM.side_effect = [["content TEXT"] * 2, ["text"], ["14.017"], ["2.07"], ["text"], ["16.087"], ["2.996"]]
        player = YouTubeSubtitleControl()
        player.simpleReplaceHTMLCodes = Mock()
        player.simpleReplaceHTMLCodes.side_effect = lambda x: x.encode("ascii", 'ignore')

        result = player.transformSubtitleXMLtoSRT(self.readTestInput("subtitleTest.xml", False))

        print repr(result)

        assert(player.simpleReplaceHTMLCodes.call_count > 0)
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:11,代碼來源:TestYouTubeSubtitleControl.py

示例11: test_getSubtitleUrl_should_fall_back_to_english_if_proper_language_code_is_not_found

    def test_getSubtitleUrl_should_fall_back_to_english_if_proper_language_code_is_not_found(self):
        player = YouTubeSubtitleControl()
        sys.modules["__main__"].core._fetchPage = Mock()
        sys.modules["__main__"].core._fetchPage.return_value = {"status": 200, "content": self.readTestInput("timedtextDirectoryTest.xml", False)}
        sys.modules["__main__"].core.getVideoIdStatusFromCache = Mock()
        sys.modules["__main__"].settings.getSetting = Mock()
        sys.modules["__main__"].settings.getSetting.return_value = "2"
        sys.modules["__main__"].common.parseDOM.side_effect = [["en"], ["english"], ["english"]]

        url = player.getSubtitleUrl({"videoid": "some_id"})

        assert(url.find("lang=en") > 0)
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:12,代碼來源:TestYouTubeSubtitleControl.py

示例12: test_downloadSubtitle_should_call_transformSubtitleToSSA

    def test_downloadSubtitle_should_call_transformSubtitleToSSA(self):
        player = YouTubeSubtitleControl()
        sys.modules["__main__"].core._fetchPage = Mock()
        sys.modules["__main__"].core._fetchPage.return_value = {"status": 200, "content": "nothingness"}
        subtitlesettings = ["false", "0", "true"]
        sys.modules["__main__"].settings.getSetting = Mock()
        sys.modules["__main__"].settings.getSetting.side_effect = lambda x: subtitlesettings.pop()
        player.transformAnnotationToSSA = Mock()
        player.transformAnnotationToSSA.return_value = ("", "style")

        player.downloadSubtitle()

        player.transformAnnotationToSSA.assert_called_with("nothingness")
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:13,代碼來源:TestYouTubeSubtitleControl.py

示例13: test_getSubtitleUrl_should_find_url_with_proper_language_code

    def test_getSubtitleUrl_should_find_url_with_proper_language_code(self):
        player = YouTubeSubtitleControl()
        sys.modules["__main__"].core._fetchPage = Mock()
        sys.modules["__main__"].core._fetchPage.return_value = {"status": 200, "content": self.readTestInput("timedtextDirectoryTest.xml", False)}
        sys.modules["__main__"].settings.getSetting = Mock()
        sys.modules["__main__"].settings.getSetting.return_value = "3"
        sys.modules["__main__"].common.parseDOM.side_effect = [["de"], ["german"], ["deutch"]]
        sys.modules["__main__"].core.getVideoIdStatusFromCache = Mock()

        url = player.getSubtitleUrl({"videoid": "some_id"})
        print repr(url)

        assert(url.find("lang=de") > 0)
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:13,代碼來源:TestYouTubeSubtitleControl.py

示例14: test_addSubtitles_should_call_xbmcs_setSubtitles

    def test_addSubtitles_should_call_xbmcs_setSubtitles(self):
        sys.modules["__main__"].settings.getSetting.return_value = "testDownloadPath"
        sys.modules["__main__"].xbmcvfs.exists.return_value = True
        sys.modules["__main__"].common.makeUTF8.return_value = "testTitle"
        player = YouTubeSubtitleControl()
        player.getSubtitleFileName = Mock(return_value="testTitle-[testid].ssa")
        player.downloadSubtitle = Mock()
        player.downloadSubtitle.return_value = True

        player.addSubtitles({"videoid": "testid", "Title": "testTitle"})

        sys.modules["__main__"].xbmcvfs.exists.assert_called_with('testDownloadPath/testTitle-[testid].ssa')
        sys.modules["__main__"].xbmc.Player().setSubtitles.assert_called_with('testDownloadPath/testTitle-[testid].ssa')
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:13,代碼來源:TestYouTubeSubtitleControl.py

示例15: test_transformSubtitleXMLtoSRT_should_correctly_recalculate_duration_time_for_text_elements

    def test_transformSubtitleXMLtoSRT_should_correctly_recalculate_duration_time_for_text_elements(self):
        input = '<?xml version="1.0" encoding="utf-8" ?><transcript>\n\
                <text start="14.017" dur="2.07">first</text>\n\
                <text start="16.087" dur="2.996">second</text>\n\
                </transcript>'
        player = YouTubeSubtitleControl()
        sys.modules["__main__"].common.replaceHTMLCodes = Mock()
        sys.modules["__main__"].common.replaceHTMLCodes.side_effect = lambda x: x.encode("ascii", 'ignore')
        sys.modules["__main__"].common.parseDOM.side_effect = [["content TEXT"] * 2, ["text"], ["14.017"], ["2.07"], ["text"], ["16.087"], ["2.996"]]

        result = player.transformSubtitleXMLtoSRT(input).split("\r\n")

        assert(result[0].find("0:00:16.087,Default") > 0)
        assert(result[1].find("0:00:19.083,Default") > 0)
開發者ID:Liorfru,項目名稱:youtube-xbmc-plugin,代碼行數:14,代碼來源:TestYouTubeSubtitleControl.py


注:本文中的YouTubeSubtitleControl.YouTubeSubtitleControl類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。