本文整理汇总了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)
示例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)
示例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)
示例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")