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