]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tv2.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
16 class TV2IE(InfoExtractor
):
17 _VALID_URL
= r
'https?://(?:www\.)?tv2\.no/v/(?P<id>\d+)'
19 'url': 'http://www.tv2.no/v/916509/',
23 'title': 'Se Frode Gryttens hyllest av Steven Gerrard',
24 'description': 'TV 2 Sportens huspoet tar avskjed med Liverpools kaptein Steven Gerrard.',
25 'timestamp': 1431715610,
26 'upload_date': '20150515',
33 'skip_download': True,
37 def _real_extract(self
, url
):
38 video_id
= self
._match
_id
(url
)
42 for protocol
in ('HDS', 'HLS'):
43 data
= self
._download
_json
(
44 'http://sumo.tv2.no/api/web/asset/%s/play.json?protocol=%s&videoFormat=SMIL+ISMUSP' % (video_id
, protocol
),
45 video_id
, 'Downloading play JSON')['playback']
46 for item
in data
['items']['item']:
47 video_url
= item
.get('url')
48 if not video_url
or video_url
in format_urls
:
50 format_id
= '%s-%s' % (protocol
.lower(), item
.get('mediaFormat'))
51 if not self
._is
_valid
_url
(video_url
, video_id
, format_id
):
53 format_urls
.append(video_url
)
54 ext
= determine_ext(video_url
)
56 formats
.extend(self
._extract
_f
4m
_formats
(
57 video_url
, video_id
, f4m_id
=format_id
))
59 formats
.extend(self
._extract
_m
3u8_formats
(
60 video_url
, video_id
, 'mp4', m3u8_id
=format_id
))
61 elif ext
== 'ism' or video_url
.endswith('.ism/Manifest'):
66 'format_id': format_id
,
67 'tbr': int_or_none(item
.get('bitrate')),
68 'filesize': int_or_none(item
.get('fileSize')),
70 self
._sort
_formats
(formats
)
72 asset
= self
._download
_json
(
73 'http://sumo.tv2.no/api/web/asset/%s.json' % video_id
,
74 video_id
, 'Downloading metadata JSON')['asset']
76 title
= asset
['title']
77 description
= asset
.get('description')
78 timestamp
= parse_iso8601(asset
.get('createTime'))
79 duration
= float_or_none(asset
.get('accurateDuration') or asset
.get('duration'))
80 view_count
= int_or_none(asset
.get('views'))
81 categories
= asset
.get('keywords', '').split(',')
84 'id': thumbnail
.get('@type'),
85 'url': thumbnail
.get('url'),
86 } for _
, thumbnail
in asset
.get('imageVersions', {}).items()]
92 'description': description
,
93 'thumbnails': thumbnails
,
94 'timestamp': timestamp
,
96 'view_count': view_count
,
97 'categories': categories
,
102 class TV2ArticleIE(InfoExtractor
):
103 _VALID_URL
= r
'https?://(?:www\.)?tv2\.no/(?:a|\d{4}/\d{2}/\d{2}(/[^/]+)+)/(?P<id>\d+)'
105 'url': 'http://www.tv2.no/2015/05/16/nyheter/alesund/krim/pingvin/6930542',
108 'title': 'Russen hetses etter pingvintyveri – innrømmer å ha åpnet luken på buret',
109 'description': 'md5:339573779d3eea3542ffe12006190954',
113 'url': 'http://www.tv2.no/a/6930542',
114 'only_matching': True,
117 def _real_extract(self
, url
):
118 playlist_id
= self
._match
_id
(url
)
120 webpage
= self
._download
_webpage
(url
, playlist_id
)
123 self
.url_result('http://www.tv2.no/v/%s' % video_id
, 'TV2')
124 for video_id
in re
.findall(r
'data-assetid="(\d+)"', webpage
)]
126 title
= remove_end(self
._og
_search
_title
(webpage
), ' - TV2.no')
127 description
= remove_end(self
._og
_search
_description
(webpage
), ' - TV2.no')
129 return self
.playlist_result(entries
, playlist_id
, title
, description
)