[mtv] Convert to new subtitles system
This commit is contained in:
parent
b9b42f2ea0
commit
0af25f784b
2 changed files with 23 additions and 19 deletions
|
@ -20,6 +20,7 @@ from youtube_dl.extractor import (
|
||||||
CeskaTelevizeIE,
|
CeskaTelevizeIE,
|
||||||
LyndaIE,
|
LyndaIE,
|
||||||
NPOIE,
|
NPOIE,
|
||||||
|
ComedyCentralIE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -330,5 +331,20 @@ class TestNPOSubtitles(BaseTestSubtitles):
|
||||||
self.assertEqual(md5(subtitles['nl']), 'fc6435027572b63fb4ab143abd5ad3f4')
|
self.assertEqual(md5(subtitles['nl']), 'fc6435027572b63fb4ab143abd5ad3f4')
|
||||||
|
|
||||||
|
|
||||||
|
class TestMTVSubtitles(BaseTestSubtitles):
|
||||||
|
url = 'http://www.cc.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother'
|
||||||
|
IE = ComedyCentralIE
|
||||||
|
|
||||||
|
def getInfoDict(self):
|
||||||
|
return super(TestMTVSubtitles, self).getInfoDict()['entries'][0]
|
||||||
|
|
||||||
|
def test_allsubtitles(self):
|
||||||
|
self.DL.params['writesubtitles'] = True
|
||||||
|
self.DL.params['allsubtitles'] = True
|
||||||
|
subtitles = self.getSubtitles()
|
||||||
|
self.assertEqual(set(subtitles.keys()), set(['en']))
|
||||||
|
self.assertEqual(md5(subtitles['en']), 'b9f6ca22a6acf597ec76f61749765e65')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .subtitles import SubtitlesInfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
compat_urllib_parse,
|
compat_urllib_parse,
|
||||||
compat_urllib_request,
|
compat_urllib_request,
|
||||||
|
@ -23,7 +23,7 @@ def _media_xml_tag(tag):
|
||||||
return '{http://search.yahoo.com/mrss/}%s' % tag
|
return '{http://search.yahoo.com/mrss/}%s' % tag
|
||||||
|
|
||||||
|
|
||||||
class MTVServicesInfoExtractor(SubtitlesInfoExtractor):
|
class MTVServicesInfoExtractor(InfoExtractor):
|
||||||
_MOBILE_TEMPLATE = None
|
_MOBILE_TEMPLATE = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -95,25 +95,15 @@ class MTVServicesInfoExtractor(SubtitlesInfoExtractor):
|
||||||
|
|
||||||
def _extract_subtitles(self, mdoc, mtvn_id):
|
def _extract_subtitles(self, mdoc, mtvn_id):
|
||||||
subtitles = {}
|
subtitles = {}
|
||||||
FORMATS = {
|
|
||||||
'scc': 'cea-608',
|
|
||||||
'eia-608': 'cea-608',
|
|
||||||
'xml': 'ttml',
|
|
||||||
}
|
|
||||||
subtitles_format = FORMATS.get(
|
|
||||||
self._downloader.params.get('subtitlesformat'), 'ttml')
|
|
||||||
for transcript in mdoc.findall('.//transcript'):
|
for transcript in mdoc.findall('.//transcript'):
|
||||||
if transcript.get('kind') != 'captions':
|
if transcript.get('kind') != 'captions':
|
||||||
continue
|
continue
|
||||||
lang = transcript.get('srclang')
|
lang = transcript.get('srclang')
|
||||||
for typographic in transcript.findall('./typographic'):
|
subtitles[lang] = [{
|
||||||
captions_format = typographic.get('format')
|
'url': compat_str(typographic.get('src')),
|
||||||
if captions_format == subtitles_format:
|
'ext': typographic.get('format')
|
||||||
subtitles[lang] = compat_str(typographic.get('src'))
|
} for typographic in transcript.findall('./typographic')]
|
||||||
break
|
return subtitles
|
||||||
if self._downloader.params.get('listsubtitles', False):
|
|
||||||
self._list_available_subtitles(mtvn_id, subtitles)
|
|
||||||
return self.extract_subtitles(mtvn_id, subtitles)
|
|
||||||
|
|
||||||
def _get_video_info(self, itemdoc):
|
def _get_video_info(self, itemdoc):
|
||||||
uri = itemdoc.find('guid').text
|
uri = itemdoc.find('guid').text
|
||||||
|
@ -196,8 +186,6 @@ class MTVServicesInfoExtractor(SubtitlesInfoExtractor):
|
||||||
webpage, 'mgid')
|
webpage, 'mgid')
|
||||||
|
|
||||||
videos_info = self._get_videos_info(mgid)
|
videos_info = self._get_videos_info(mgid)
|
||||||
if self._downloader.params.get('listsubtitles', False):
|
|
||||||
return
|
|
||||||
return videos_info
|
return videos_info
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue