[nrktv] Rework subtitles and eliminate downloading twice

This commit is contained in:
Sergey M․ 2015-10-01 20:33:17 +06:00
parent 6751a1284d
commit 2b3f951a2e

View file

@ -4,6 +4,7 @@ from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_urlparse
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
float_or_none, float_or_none,
@ -196,20 +197,6 @@ class NRKTVIE(InfoExtractor):
} }
] ]
def _debug_print(self, txt):
if self._downloader.params.get('verbose', False):
self.to_screen('[debug] %s' % txt)
def _get_subtitles(self, subtitlesurl, video_id, baseurl):
url = "%s%s" % (baseurl, subtitlesurl)
self._debug_print('%s: Subtitle url: %s' % (video_id, url))
captions = self._download_xml(
url, video_id, 'Downloading subtitles')
lang = captions.get('lang', 'no')
return {lang: [
{'ext': 'ttml', 'url': url},
]}
def _extract_f4m(self, manifest_url, video_id): def _extract_f4m(self, manifest_url, video_id):
return self._extract_f4m_formats( return self._extract_f4m_formats(
manifest_url + '?hdcore=3.1.1&plugin=aasp-3.1.1.69.124', video_id, f4m_id='hds') manifest_url + '?hdcore=3.1.1&plugin=aasp-3.1.1.69.124', video_id, f4m_id='hds')
@ -218,7 +205,7 @@ class NRKTVIE(InfoExtractor):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id') video_id = mobj.group('id')
part_id = mobj.group('part_id') part_id = mobj.group('part_id')
baseurl = mobj.group('baseurl') base_url = mobj.group('baseurl')
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, video_id)
@ -278,11 +265,14 @@ class NRKTVIE(InfoExtractor):
self._sort_formats(formats) self._sort_formats(formats)
subtitles_url = self._html_search_regex( subtitles_url = self._html_search_regex(
r'data-subtitlesurl[ ]*=[ ]*"([^"]+)"', r'data-subtitlesurl\s*=\s*(["\'])(?P<url>.+?)\1',
webpage, 'subtitle URL', default=None) webpage, 'subtitle URL', default=None, group='url')
subtitles = None subtitles = {}
if subtitles_url: if subtitles_url:
subtitles = self.extract_subtitles(subtitles_url, video_id, baseurl) subtitles['no'] = [{
'ext': 'ttml',
'url': compat_urlparse.urljoin(base_url, subtitles_url),
}]
return { return {
'id': video_id, 'id': video_id,