[drtv] Modernize and make more robust

pull/8/head
Sergey M․ 8 years ago
parent 6562d34a8c
commit 6066d03db0
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

@ -4,6 +4,9 @@ from __future__ import unicode_literals
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
int_or_none,
float_or_none,
mimetype2ext,
parse_iso8601, parse_iso8601,
remove_end, remove_end,
) )
@ -58,10 +61,12 @@ class DRTVIE(InfoExtractor):
video_id, 'Downloading video JSON') video_id, 'Downloading video JSON')
data = programcard['Data'][0] data = programcard['Data'][0]
title = remove_end(self._og_search_title(webpage), ' | TV | DR') or data['Title'] title = remove_end(self._og_search_title(
description = self._og_search_description(webpage) or data['Description'] webpage, default=None), ' | TV | DR') or data['Title']
description = self._og_search_description(
webpage, default=None) or data.get('Description')
timestamp = parse_iso8601(data['CreatedTime']) timestamp = parse_iso8601(data.get('CreatedTime'))
thumbnail = None thumbnail = None
duration = None duration = None
@ -72,16 +77,18 @@ class DRTVIE(InfoExtractor):
subtitles = {} subtitles = {}
for asset in data['Assets']: for asset in data['Assets']:
if asset['Kind'] == 'Image': if asset.get('Kind') == 'Image':
thumbnail = asset['Uri'] thumbnail = asset.get('Uri')
elif asset['Kind'] == 'VideoResource': elif asset.get('Kind') == 'VideoResource':
duration = asset['DurationInMilliseconds'] / 1000.0 duration = float_or_none(asset.get('DurationInMilliseconds'), 1000)
restricted_to_denmark = asset['RestrictedToDenmark'] restricted_to_denmark = asset.get('RestrictedToDenmark')
spoken_subtitles = asset['Target'] == 'SpokenSubtitles' spoken_subtitles = asset.get('Target') == 'SpokenSubtitles'
for link in asset['Links']: for link in asset.get('Links', []):
uri = link['Uri'] uri = link.get('Uri')
target = link['Target'] if not uri:
format_id = target continue
target = link.get('Target')
format_id = target or ''
preference = None preference = None
if spoken_subtitles: if spoken_subtitles:
preference = -1 preference = -1
@ -92,8 +99,8 @@ class DRTVIE(InfoExtractor):
video_id, preference, f4m_id=format_id)) video_id, preference, f4m_id=format_id))
elif target == 'HLS': elif target == 'HLS':
formats.extend(self._extract_m3u8_formats( formats.extend(self._extract_m3u8_formats(
uri, video_id, 'mp4', preference=preference, uri, video_id, 'mp4', entry_protocol='m3u8_native',
m3u8_id=format_id)) preference=preference, m3u8_id=format_id))
else: else:
bitrate = link.get('Bitrate') bitrate = link.get('Bitrate')
if bitrate: if bitrate:
@ -101,7 +108,7 @@ class DRTVIE(InfoExtractor):
formats.append({ formats.append({
'url': uri, 'url': uri,
'format_id': format_id, 'format_id': format_id,
'tbr': bitrate, 'tbr': int_or_none(bitrate),
'ext': link.get('FileFormat'), 'ext': link.get('FileFormat'),
}) })
subtitles_list = asset.get('SubtitlesList') subtitles_list = asset.get('SubtitlesList')
@ -110,12 +117,18 @@ class DRTVIE(InfoExtractor):
'Danish': 'da', 'Danish': 'da',
} }
for subs in subtitles_list: for subs in subtitles_list:
lang = subs['Language'] if not subs.get('Uri'):
subtitles[LANGS.get(lang, lang)] = [{'url': subs['Uri'], 'ext': 'vtt'}] continue
lang = subs.get('Language') or 'da'
subtitles.setdefault(LANGS.get(lang, lang), []).append({
'url': subs['Uri'],
'ext': mimetype2ext(subs.get('MimeType')) or 'vtt'
})
if not formats and restricted_to_denmark: if not formats and restricted_to_denmark:
raise ExtractorError( self.raise_geo_restricted(
'Unfortunately, DR is not allowed to show this program outside Denmark.', expected=True) 'Unfortunately, DR is not allowed to show this program outside Denmark.',
expected=True)
self._sort_formats(formats) self._sort_formats(formats)

Loading…
Cancel
Save