1 from .common
import InfoExtractor
11 class Kanal2IE(InfoExtractor
):
12 _VALID_URL
= r
'https?://kanal2\.postimees\.ee/[^?#]+\?([^#]+&)?id=(?P<id>\d+)'
14 'note': 'Test standard url (#5575)',
15 'url': 'https://kanal2.postimees.ee/pluss/video/?id=40792',
16 'md5': '7ea7b16266ec1798743777df241883dd',
20 'title': 'Aedniku aabits / Osa 53 (05.08.2016 20:00)',
21 'thumbnail': r
're:https?://.*\.jpg$',
22 'description': 'md5:53cabf3c5d73150d594747f727431248',
23 'upload_date': '20160805',
24 'timestamp': 1470420000,
28 def _real_extract(self
, url
):
29 video_id
= self
._match
_id
(url
)
30 playlist
= self
._download
_json
(
31 f
'https://kanal2.postimees.ee/player/playlist/{video_id}',
32 video_id
, query
={'type': 'episodes'}
,
33 headers
={'X-Requested-With': 'XMLHttpRequest'}
)
37 'title': join_nonempty(*traverse_obj(playlist
, ('info', ('title', 'subtitle'))), delim
=' / '),
38 'description': traverse_obj(playlist
, ('info', 'description')),
39 'thumbnail': traverse_obj(playlist
, ('data', 'image')),
40 'formats': self
.get_formats(playlist
, video_id
),
41 'timestamp': unified_timestamp(self
._search
_regex
(
42 r
'\((\d{2}\.\d{2}\.\d{4}\s\d{2}:\d{2})\)$',
43 traverse_obj(playlist
, ('info', 'subtitle')), 'timestamp', default
='') + ' +0200'),
46 def get_formats(self
, playlist
, video_id
):
47 path
= traverse_obj(playlist
, ('data', 'path'))
49 raise ExtractorError('Path value not found in playlist JSON response')
50 session
= self
._download
_json
(
51 'https://sts.postimees.ee/session/register',
52 video_id
, note
='Creating session', errnote
='Error creating session',
54 'X-Original-URI': path
,
55 'Accept': 'application/json',
57 if session
.get('reason') != 'OK' or not session
.get('session'):
58 reason
= session
.get('reason', 'unknown error')
59 raise ExtractorError(f
'Unable to obtain session: {reason}')
62 for stream
in traverse_obj(playlist
, ('data', 'streams', ..., 'file')):
63 formats
.extend(self
._extract
_m
3u8_formats
(
64 update_url_query(stream
, {'s': session['session']}
), video_id
, 'mp4'))