]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/parliamentliveuk.py
869ebd8655beea6fa3c4541a2b24504746ac72b4
[yt-dlp.git] / yt_dlp / extractor / parliamentliveuk.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import json
5 import uuid
6
7 from .common import InfoExtractor
8 from ..utils import (
9 unified_timestamp,
10 try_get,
11 )
12
13
14 class ParliamentLiveUKIE(InfoExtractor):
15 IE_NAME = 'parliamentlive.tv'
16 IE_DESC = 'UK parliament videos'
17 _VALID_URL = r'(?i)https?://(?:www\.)?parliamentlive\.tv/Event/Index/(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
18
19 _TESTS = [{
20 'url': 'http://parliamentlive.tv/Event/Index/c1e9d44d-fd6c-4263-b50f-97ed26cc998b',
21 'info_dict': {
22 'id': 'c1e9d44d-fd6c-4263-b50f-97ed26cc998b',
23 'ext': 'mp4',
24 'title': 'Home Affairs Committee',
25 'timestamp': 1395153872,
26 'upload_date': '20140318',
27 },
28 'params': {
29 'format': 'bestvideo',
30 },
31 }, {
32 'url': 'http://parliamentlive.tv/event/index/3f24936f-130f-40bf-9a5d-b3d6479da6a4',
33 'only_matching': True,
34 }]
35
36 def _real_extract(self, url):
37 video_id = self._match_id(url)
38 video_info = self._download_json(f'https://www.parliamentlive.tv/Event/GetShareVideo/{video_id}', video_id)
39 _DEVICE_ID = str(uuid.uuid4())
40 auth = 'Bearer ' + self._download_json(
41 'https://exposure.api.redbee.live/v2/customer/UKParliament/businessunit/ParliamentLive/auth/anonymous',
42 video_id, headers={
43 'Origin': 'https://videoplayback.parliamentlive.tv',
44 'Accept': 'application/json, text/plain, */*',
45 'Content-Type': 'application/json;charset=utf-8'
46 }, data=json.dumps({
47 'deviceId': _DEVICE_ID,
48 'device': {
49 'deviceId': _DEVICE_ID,
50 'width': 653,
51 'height': 368,
52 'type': 'WEB',
53 'name': ' Mozilla Firefox 91'
54 }
55 }).encode('utf-8'))['sessionToken']
56
57 video_urls = self._download_json(
58 f'https://exposure.api.redbee.live/v2/customer/UKParliament/businessunit/ParliamentLive/entitlement/{video_id}/play',
59 video_id, headers={'Authorization': auth, 'Accept': 'application/json, text/plain, */*'})['formats']
60
61 formats = []
62 for format in video_urls:
63 if not format.get('mediaLocator'):
64 continue
65 if format.get('format') == 'DASH':
66 formats.extend(self._extract_mpd_formats(
67 format['mediaLocator'], video_id, mpd_id='dash', fatal=False))
68 elif format.get('format') == 'SMOOTHSTREAMING':
69 formats.extend(self._extract_ism_formats(
70 format['mediaLocator'], video_id, ism_id='ism', fatal=False))
71 elif format.get('format') == 'HLS':
72 formats.extend(self._extract_m3u8_formats(
73 format['mediaLocator'], video_id, m3u8_id='hls', fatal=False))
74
75 self._sort_formats(formats)
76
77 return {
78 'id': video_id,
79 'formats': formats,
80 'title': video_info['event']['title'],
81 'timestamp': unified_timestamp(try_get(video_info, lambda x: x['event']['publishedStartTime'])),
82 'thumbnail': video_info.get('thumbnailUrl'),
83 }