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


Python YouTubeSubtitleControl.transformSubtitleXMLtoSRT方法代碼示例

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


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

示例1: test_transformSubtitleXMLtoSRT_should_parse_youtube_subtitle_xml

# 需要導入模塊: from YouTubeSubtitleControl import YouTubeSubtitleControl [as 別名]
# 或者: from YouTubeSubtitleControl.YouTubeSubtitleControl import transformSubtitleXMLtoSRT [as 別名]
    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,代碼行數:11,代碼來源:TestYouTubeSubtitleControl.py

示例2: test_transformSubtitleXMLtoSRT_should_call_replaceHTMLCodes_for_user_visible_text

# 需要導入模塊: from YouTubeSubtitleControl import YouTubeSubtitleControl [as 別名]
# 或者: from YouTubeSubtitleControl.YouTubeSubtitleControl import transformSubtitleXMLtoSRT [as 別名]
    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,代碼行數:13,代碼來源:TestYouTubeSubtitleControl.py

示例3: test_transformSubtitleXMLtoSRT_should_correctly_recalculate_duration_time_for_text_elements

# 需要導入模塊: from YouTubeSubtitleControl import YouTubeSubtitleControl [as 別名]
# 或者: from YouTubeSubtitleControl.YouTubeSubtitleControl import transformSubtitleXMLtoSRT [as 別名]
    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,代碼行數:16,代碼來源:TestYouTubeSubtitleControl.py

示例4: test_downloadSubtitle_should_call_transformSubtitleXMLtoSRT

# 需要導入模塊: from YouTubeSubtitleControl import YouTubeSubtitleControl [as 別名]
# 或者: from YouTubeSubtitleControl.YouTubeSubtitleControl import transformSubtitleXMLtoSRT [as 別名]
    def test_downloadSubtitle_should_call_transformSubtitleXMLtoSRT(self):
        player = YouTubeSubtitleControl()
        sys.modules["__main__"].core._fetchPage = Mock()
        sys.modules["__main__"].core._fetchPage.return_value = {"status": 200, "content": "nothingness"}

        subtitlesettings = ["true", "2", "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.getSubtitleUrl = Mock()
        player.getSubtitleUrl.return_value = ""
        player.getTranscriptionUrl = Mock()
        player.getTranscriptionUrl.return_value = "something"
        player.transformSubtitleXMLtoSRT = Mock()
        player.transformSubtitleXMLtoSRT.return_value = ""

        player.downloadSubtitle()

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


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