2 from __future__ import unicode_literals
4 from .common import InfoExtractor
13 class TV2IE(InfoExtractor):
14 _VALID_URL = 'http://(?:www\.)?tv2\.no/v/(?P<id>\d+)'
16 'url': 'http://www.tv2.no/v/916509/',
17 'md5': '9cb9e3410b18b515d71892f27856e9b1',
21 'title': 'Se Gryttens hyllest av Steven Gerrard',
22 'description': 'TV 2 Sportens huspoet tar avskjed med Liverpools kaptein Steven Gerrard.',
23 'timestamp': 1431715610,
24 'upload_date': '20150515',
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
36 for protocol in ('HDS', 'HLS'):
37 data = self._download_json(
38 'http://sumo.tv2.no/api/web/asset/%s/play.json?protocol=%s&videoFormat=SMIL+ISMUSP' % (video_id, protocol),
39 video_id, 'Downloading play JSON')['playback']
40 for item in data['items']['item']:
41 video_url = item.get('url')
42 if not video_url or video_url in format_urls:
44 format_id = '%s-%s' % (protocol.lower(), item.get('mediaFormat'))
45 if not self._is_valid_url(video_url, video_id, format_id):
47 format_urls.append(video_url)
48 ext = determine_ext(video_url)
50 formats.extend(self._extract_f4m_formats(
51 video_url, video_id, f4m_id=format_id))
53 formats.extend(self._extract_m3u8_formats(
54 video_url, video_id, 'mp4', m3u8_id=format_id))
55 elif ext == 'ism' or video_url.endswith('.ism/Manifest'):
60 'format_id': format_id,
61 'tbr': int_or_none(item.get('bitrate')),
62 'filesize': int_or_none(item.get('fileSize')),
64 self._sort_formats(formats)
66 asset = self._download_json(
67 'http://sumo.tv2.no/api/web/asset/%s.json' % video_id,
68 video_id, 'Downloading metadata JSON')['asset']
70 title = asset['title']
71 description = asset.get('description')
72 timestamp = parse_iso8601(asset.get('createTime'))
73 duration = float_or_none(asset.get('accurateDuration') or asset.get('duration'))
74 view_count = int_or_none(asset.get('views'))
75 categories = asset.get('keywords', '').split(',')
78 'id': thumbnail.get('@type'),
79 'url': thumbnail.get('url'),
80 } for _, thumbnail in asset.get('imageVersions', {}).items()]
86 'description': description,
87 'thumbnails': thumbnails,
88 'timestamp': timestamp,
90 'view_count': view_count,
91 'categories': categories,