3 from .common
import InfoExtractor
13 class TV4IE(InfoExtractor
):
14 IE_DESC
= 'tv4.se and tv4play.se'
15 _VALID_URL
= r
'''(?x)https?://(?:www\.)?
17 tv4\.se/(?:[^/]+)/klipp/(?:.*)-|
20 (?:program|barn)/(?:(?:[^/]+/){1,2}|(?:[^\?]+)\?video_id=)|
30 'url': 'http://www.tv4.se/kalla-fakta/klipp/kalla-fakta-5-english-subtitles-2491650',
31 'md5': 'cb837212f342d77cec06e6dad190e96d',
35 'title': 'Kalla Fakta 5 (english subtitles)',
36 'description': '2491650',
37 'series': 'Kalla fakta',
39 'thumbnail': r
're:^https?://[^/?#]+/api/v2/img/',
40 'timestamp': 1385373240,
41 'upload_date': '20131125',
43 'params': {'skip_download': 'm3u8'},
44 'expected_warnings': ['Unable to download f4m manifest'],
47 'url': 'http://www.tv4play.se/iframe/video/3054113',
48 'md5': 'cb837212f342d77cec06e6dad190e96d',
52 'title': 'Så här jobbar ficktjuvarna - se avslöjande bilder',
53 'thumbnail': r
're:^https?://.*\.jpg$',
54 'description': 'Unika bilder avslöjar hur turisternas fickor vittjas mitt på Stockholms central. Två experter på ficktjuvarna avslöjar knepen du ska se upp för.',
56 'upload_date': '20150130',
58 'skip': '404 Not Found',
61 'url': 'http://www.tv4play.se/sport/3060959',
62 'only_matching': True,
65 'url': 'http://www.tv4play.se/film/2378136',
66 'only_matching': True,
69 'url': 'http://www.tv4play.se/barn/looney-tunes?video_id=3062412',
70 'only_matching': True,
73 'url': 'http://www.tv4play.se/program/farang/3922081',
74 'only_matching': True,
77 'url': 'https://www.tv4play.se/program/nyheterna/avsnitt/13315940',
78 'only_matching': True,
82 def _call_api(self
, endpoint
, video_id
, headers
=None, query
={}):
83 return self
._download
_json
(
84 f
'https://playback2.a2d.tv/{endpoint}/{video_id}', video_id
,
85 f
'Downloading {endpoint} API JSON', headers
=headers
, query
={
92 def _real_extract(self
, url
):
93 video_id
= self
._match
_id
(url
)
95 info
= traverse_obj(self
._call
_api
('asset', video_id
, query
={
96 'protocol': 'hls,dash',
98 }), ('metadata', {dict}
)) or {}
100 manifest_url
= self
._call
_api
(
101 'play', video_id
, headers
=self
.geo_verification_headers())['playbackItem']['manifestUrl']
103 formats
, subtitles
= [], {}
105 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
106 manifest_url
, video_id
, 'mp4',
107 'm3u8_native', m3u8_id
='hls', fatal
=False)
109 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
111 fmts
, subs
= self
._extract
_mpd
_formats
_and
_subtitles
(
112 manifest_url
.replace('.m3u8', '.mpd'),
113 video_id
, mpd_id
='dash', fatal
=False)
115 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
117 fmts
= self
._extract
_f
4m
_formats
(
118 manifest_url
.replace('.m3u8', '.f4m'),
119 video_id
, f4m_id
='hds', fatal
=False)
122 fmts
, subs
= self
._extract
_ism
_formats
_and
_subtitles
(
123 re
.sub(r
'\.ism/.*?\.m3u8', r
'.ism/Manifest', manifest_url
),
124 video_id
, ism_id
='mss', fatal
=False)
126 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
128 if not formats
and info
.get('is_geo_restricted'):
129 self
.raise_geo_restricted(
130 'This video is not available from your location due to geo-restriction, or not being authenticated',
136 'subtitles': subtitles
,
137 **traverse_obj(info
, {
138 'title': ('title', {str}
),
139 'description': ('description', {str}
),
140 'timestamp': (('broadcast_date_time', 'broadcastDateTime'), {parse_iso8601}
),
141 'duration': ('duration', {int_or_none}
),
142 'thumbnail': ('image', {url_or_none}
),
143 'is_live': ('isLive', {bool_or_none}
),
144 'series': ('seriesTitle', {str}
),
145 'season_number': ('seasonNumber', {int_or_none}
),
146 'episode': ('episodeTitle', {str}
),
147 'episode_number': ('episodeNumber', {int_or_none}
),