1 from __future__ import unicode_literals
3 from .common import InfoExtractor
4 from .common import ExtractorError
5 from ..utils import parse_iso8601
9 class DRBonanzaIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?dr\.dk/bonanza/(?:[^/]+/)+(?:[^/])+?(?:assetId=(?P<id>\d+))?(?:[#&]|$)'
13 'url': 'http://www.dr.dk/bonanza/serie/portraetter/Talkshowet.htm?assetId=65517',
14 'md5': 'fe330252ddea607635cf2eb2c99a0af3',
18 'title': 'Talkshowet - Leonard Cohen',
19 'description': 'md5:8f34194fb30cd8c8a30ad8b27b70c0ca',
20 'timestamp': 1295537932,
21 'upload_date': '20110120',
25 'url': 'http://www.dr.dk/bonanza/radio/serie/sport/fodbold.htm?assetId=59410',
26 'md5': '6dfe039417e76795fb783c52da3de11d',
30 'title': 'EM fodbold 1992 Danmark - Tyskland finale Transmission',
31 'description': 'md5:501e5a195749480552e214fbbed16c4e',
32 'timestamp': 1223274900,
33 'upload_date': '20081006',
38 def _real_extract(self, url):
39 url_id = self._match_id(url)
41 webpage = self._download_webpage(url, url_id if url_id else "")
44 info = json.loads(self._html_search_regex(r'({.*?' + url_id + '.*})', webpage, 'json'))
46 # Just fetch the first video on that page
47 info = json.loads(self._html_search_regex(r'bonanzaFunctions.newPlaylist\(({.*})\)', webpage, 'json'))
49 asset_id = str(info['AssetId'])
50 title = info['Title'].rstrip(' \'\"-,.:;!?')
51 duration = info['Duration']
52 timestamp = parse_iso8601(re.sub(r'\.\d+$', '', info['Created'])) # First published online. "FirstPublished" contains the date for original airing.
54 def parse_filename_info(url):
55 match = re.search(r'/\d+_(?P<width>\d+)x(?P<height>\d+)x(?P<bitrate>\d+)K\.(?P<ext>\w+)$', url)
57 return {'width': int(match.group(1)), 'height': int(match.group(2)), 'bitrate': int(match.group(3)), 'ext': match.group(4)}
58 match = re.search(r'/\d+_(?P<bitrate>\d+)K\.(?P<ext>\w+)$', url)
60 return {'bitrate': int(match.group(1)), 'ext': match.group(2)}
61 return {'width': None, 'height': None, 'bitrate': None, 'ext': None}
63 video_types = ['VideoHigh', 'VideoMid', 'VideoLow']
72 for file in info['Files']:
73 if info['Type'] == "Video":
74 if file['Type'] in video_types:
75 fileinfo = parse_filename_info(file['Location'])
77 'url': file['Location'],
78 'format_id': file['Type'].replace('Video', ''),
79 'preference': preferencemap.get(file['Type'], -10),
80 'width': fileinfo['width'],
81 'height': fileinfo['height'],
82 'vbr': fileinfo['bitrate'],
83 'ext': fileinfo['ext'],
85 elif file['Type'] == "Thumb":
86 thumbnail = file['Location']
87 elif info['Type'] == "Audio":
88 if file['Type'] == "Audio":
89 fileinfo = parse_filename_info(file['Location'])
91 'url': file['Location'],
92 'format_id': file['Type'],
93 'abr': fileinfo['bitrate'],
94 'ext': fileinfo['ext'],
97 elif file['Type'] == "Thumb":
98 thumbnail = file['Location']
100 description = "{}\n{}\n{}\n".format(info['Description'], info['Actors'], info['Colophon'])
103 f['url'] = f['url'].replace('rtmp://vod-bonanza.gss.dr.dk/bonanza/', 'http://vodfiles.dr.dk/')
104 f['url'] = f['url'].replace('mp4:bonanza', 'bonanza')
106 self._sort_formats(formats)
108 display_id = re.sub(r'[^\w\d-]', '', re.sub(r' ', '-', title.lower())) + '-' + asset_id
109 display_id = re.sub(r'-+', '-', display_id)
113 'display_id': display_id,
116 'description': description,
117 'thumbnail': thumbnail,
118 'timestamp': timestamp,
119 'duration': duration,