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