2015-04-04 17:19:28 +00:00
|
|
|
# coding: utf-8
|
2014-06-27 13:53:59 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2015-02-18 16:20:22 +00:00
|
|
|
from .common import InfoExtractor, ExtractorError
|
2014-06-28 10:36:13 +00:00
|
|
|
from ..utils import parse_iso8601
|
2014-06-27 13:53:59 +00:00
|
|
|
|
|
|
|
|
2015-02-18 16:20:22 +00:00
|
|
|
class DRTVIE(InfoExtractor):
|
2015-01-30 16:42:11 +00:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?dr\.dk/tv/se/(?:[^/]+/)*(?P<id>[\da-z-]+)(?:[/#?]|$)'
|
2014-06-27 13:53:59 +00:00
|
|
|
|
|
|
|
_TEST = {
|
2015-04-04 17:19:28 +00:00
|
|
|
'url': 'https://www.dr.dk/tv/se/boern/ultra/panisk-paske/panisk-paske-5',
|
|
|
|
'md5': 'dc515a9ab50577fa14cc4e4b0265168f',
|
2014-06-27 13:53:59 +00:00
|
|
|
'info_dict': {
|
2015-04-04 17:19:28 +00:00
|
|
|
'id': 'panisk-paske-5',
|
2014-06-27 13:53:59 +00:00
|
|
|
'ext': 'mp4',
|
2015-04-04 17:19:28 +00:00
|
|
|
'title': 'Panisk Påske (5)',
|
|
|
|
'description': 'md5:ca14173c5ab24cd26b0fcc074dff391c',
|
|
|
|
'timestamp': 1426984612,
|
|
|
|
'upload_date': '20150322',
|
|
|
|
'duration': 1455,
|
2014-06-27 13:53:59 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2014-10-29 19:10:00 +00:00
|
|
|
video_id = self._match_id(url)
|
2014-06-27 13:53:59 +00:00
|
|
|
|
2015-02-02 15:11:25 +00:00
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
2015-04-04 17:17:09 +00:00
|
|
|
if '>Programmet er ikke længere tilgængeligt' in webpage:
|
|
|
|
raise ExtractorError(
|
|
|
|
'Video %s is not available' % video_id, expected=True)
|
|
|
|
|
2015-02-02 15:11:25 +00:00
|
|
|
video_id = self._search_regex(
|
|
|
|
r'data-(?:material-identifier|episode-slug)="([^"]+)"',
|
|
|
|
webpage, 'video id')
|
2014-06-27 13:53:59 +00:00
|
|
|
|
2015-02-02 15:11:25 +00:00
|
|
|
programcard = self._download_json(
|
|
|
|
'http://www.dr.dk/mu/programcard/expanded/%s' % video_id,
|
|
|
|
video_id, 'Downloading video JSON')
|
2014-06-27 13:53:59 +00:00
|
|
|
data = programcard['Data'][0]
|
|
|
|
|
|
|
|
title = data['Title']
|
|
|
|
description = data['Description']
|
2014-10-29 19:10:00 +00:00
|
|
|
timestamp = parse_iso8601(data['CreatedTime'])
|
2014-06-27 13:53:59 +00:00
|
|
|
|
|
|
|
thumbnail = None
|
|
|
|
duration = None
|
|
|
|
|
|
|
|
restricted_to_denmark = False
|
|
|
|
|
|
|
|
formats = []
|
|
|
|
subtitles = {}
|
|
|
|
|
|
|
|
for asset in data['Assets']:
|
|
|
|
if asset['Kind'] == 'Image':
|
|
|
|
thumbnail = asset['Uri']
|
|
|
|
elif asset['Kind'] == 'VideoResource':
|
|
|
|
duration = asset['DurationInMilliseconds'] / 1000.0
|
|
|
|
restricted_to_denmark = asset['RestrictedToDenmark']
|
2015-01-25 17:56:04 +00:00
|
|
|
spoken_subtitles = asset['Target'] == 'SpokenSubtitles'
|
2014-06-27 13:53:59 +00:00
|
|
|
for link in asset['Links']:
|
|
|
|
target = link['Target']
|
|
|
|
uri = link['Uri']
|
2015-01-25 17:56:04 +00:00
|
|
|
format_id = target
|
|
|
|
preference = -1 if target == 'HDS' else -2
|
|
|
|
if spoken_subtitles:
|
|
|
|
preference -= 2
|
|
|
|
format_id += '-spoken-subtitles'
|
2014-06-27 13:53:59 +00:00
|
|
|
formats.append({
|
|
|
|
'url': uri + '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43' if target == 'HDS' else uri,
|
2015-01-25 17:56:04 +00:00
|
|
|
'format_id': format_id,
|
2014-06-27 13:53:59 +00:00
|
|
|
'ext': link['FileFormat'],
|
2015-01-25 17:56:04 +00:00
|
|
|
'preference': preference,
|
2014-06-27 13:53:59 +00:00
|
|
|
})
|
|
|
|
subtitles_list = asset.get('SubtitlesList')
|
|
|
|
if isinstance(subtitles_list, list):
|
|
|
|
LANGS = {
|
|
|
|
'Danish': 'dk',
|
|
|
|
}
|
|
|
|
for subs in subtitles_list:
|
|
|
|
lang = subs['Language']
|
2015-02-18 16:20:22 +00:00
|
|
|
subtitles[LANGS.get(lang, lang)] = [{'url': subs['Uri'], 'ext': 'vtt'}]
|
2014-06-27 13:53:59 +00:00
|
|
|
|
|
|
|
if not formats and restricted_to_denmark:
|
|
|
|
raise ExtractorError(
|
|
|
|
'Unfortunately, DR is not allowed to show this program outside Denmark.', expected=True)
|
|
|
|
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': title,
|
|
|
|
'description': description,
|
|
|
|
'thumbnail': thumbnail,
|
|
|
|
'timestamp': timestamp,
|
|
|
|
'duration': duration,
|
|
|
|
'formats': formats,
|
2015-02-18 16:20:22 +00:00
|
|
|
'subtitles': subtitles,
|
2014-06-27 13:53:59 +00:00
|
|
|
}
|