2 from __future__ import unicode_literals
6 from .common import InfoExtractor
17 class TV2IE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?tv2\.no/v/(?P<id>\d+)'
20 'url': 'http://www.tv2.no/v/916509/',
24 'title': 'Se Frode Gryttens hyllest av Steven Gerrard',
25 'description': 'TV 2 Sportens huspoet tar avskjed med Liverpools kaptein Steven Gerrard.',
26 'timestamp': 1431715610,
27 'upload_date': '20150515',
34 'skip_download': True,
38 def _real_extract(self, url):
39 video_id = self._match_id(url)
43 for protocol in ('HDS', 'HLS'):
44 data = self._download_json(
45 'http://sumo.tv2.no/api/web/asset/%s/play.json?protocol=%s&videoFormat=SMIL+ISMUSP' % (video_id, protocol),
46 video_id, 'Downloading play JSON')['playback']
47 for item in data['items']['item']:
48 video_url = item.get('url')
49 if not video_url or video_url in format_urls:
51 format_id = '%s-%s' % (protocol.lower(), item.get('mediaFormat'))
52 if not self._is_valid_url(video_url, video_id, format_id):
54 format_urls.append(video_url)
55 ext = determine_ext(video_url)
57 formats.extend(self._extract_f4m_formats(
58 video_url, video_id, f4m_id=format_id))
60 formats.extend(self._extract_m3u8_formats(
61 video_url, video_id, 'mp4', m3u8_id=format_id))
62 elif ext == 'ism' or video_url.endswith('.ism/Manifest'):
67 'format_id': format_id,
68 'tbr': int_or_none(item.get('bitrate')),
69 'filesize': int_or_none(item.get('fileSize')),
71 self._sort_formats(formats)
73 asset = self._download_json(
74 'http://sumo.tv2.no/api/web/asset/%s.json' % video_id,
75 video_id, 'Downloading metadata JSON')['asset']
77 title = asset['title']
78 description = asset.get('description')
79 timestamp = parse_iso8601(asset.get('createTime'))
80 duration = float_or_none(asset.get('accurateDuration') or asset.get('duration'))
81 view_count = int_or_none(asset.get('views'))
82 categories = asset.get('keywords', '').split(',')
85 'id': thumbnail.get('@type'),
86 'url': thumbnail.get('url'),
87 } for _, thumbnail in asset.get('imageVersions', {}).items()]
93 'description': description,
94 'thumbnails': thumbnails,
95 'timestamp': timestamp,
97 'view_count': view_count,
98 'categories': categories,
103 class TV2ArticleIE(InfoExtractor):
104 _VALID_URL = r'https?://(?:www\.)?tv2\.no/(?:a|\d{4}/\d{2}/\d{2}(/[^/]+)+)/(?P<id>\d+)'
106 'url': 'http://www.tv2.no/2015/05/16/nyheter/alesund/krim/pingvin/6930542',
109 'title': 'Russen hetses etter pingvintyveri - innrømmer å ha åpnet luken på buret',
110 'description': 'md5:339573779d3eea3542ffe12006190954',
114 'url': 'http://www.tv2.no/a/6930542',
115 'only_matching': True,
118 def _real_extract(self, url):
119 playlist_id = self._match_id(url)
121 webpage = self._download_webpage(url, playlist_id)
123 # Old embed pattern (looks unused nowadays)
124 assets = re.findall(r'data-assetid=["\'](\d+)', webpage)
128 for v in re.findall('TV2ContentboxVideo\(({.+?})\)', webpage):
129 video = self._parse_json(
130 v, playlist_id, transform_source=js_to_json, fatal=False)
133 asset = video.get('assetId')
138 self.url_result('http://www.tv2.no/v/%s' % asset_id, 'TV2')
139 for asset_id in assets]
141 title = remove_end(self._og_search_title(webpage), ' - TV2.no')
142 description = remove_end(self._og_search_description(webpage), ' - TV2.no')
144 return self.playlist_result(entries, playlist_id, title, description)