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