[parliamentlive.tv] Fix extractor (#1153)

Closes #1139 
Authored by: u-spec-png
This commit is contained in:
u-spec-png 2021-10-04 19:09:00 +00:00 committed by GitHub
parent 943d5ab133
commit 755203fc3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,14 @@
# coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import json
import uuid
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import (
unified_timestamp,
try_get,
)
class ParliamentLiveUKIE(InfoExtractor): class ParliamentLiveUKIE(InfoExtractor):
@ -11,12 +19,14 @@ class ParliamentLiveUKIE(InfoExtractor):
_TESTS = [{ _TESTS = [{
'url': 'http://parliamentlive.tv/Event/Index/c1e9d44d-fd6c-4263-b50f-97ed26cc998b', 'url': 'http://parliamentlive.tv/Event/Index/c1e9d44d-fd6c-4263-b50f-97ed26cc998b',
'info_dict': { 'info_dict': {
'id': '1_af9nv9ym', 'id': 'c1e9d44d-fd6c-4263-b50f-97ed26cc998b',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Home Affairs Committee', 'title': 'Home Affairs Committee',
'uploader_id': 'FFMPEG-01', 'timestamp': 1395153872,
'timestamp': 1422696664, 'upload_date': '20140318',
'upload_date': '20150131', },
'params': {
'format': 'bestvideo',
}, },
}, { }, {
'url': 'http://parliamentlive.tv/event/index/3f24936f-130f-40bf-9a5d-b3d6479da6a4', 'url': 'http://parliamentlive.tv/event/index/3f24936f-130f-40bf-9a5d-b3d6479da6a4',
@ -25,19 +35,49 @@ class ParliamentLiveUKIE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
webpage = self._download_webpage( video_info = self._download_json(f'https://www.parliamentlive.tv/Event/GetShareVideo/{video_id}', video_id)
'http://vodplayer.parliamentlive.tv/?mid=' + video_id, video_id) _DEVICE_ID = str(uuid.uuid4())
widget_config = self._parse_json(self._search_regex( auth = 'Bearer ' + self._download_json(
r'(?s)kWidgetConfig\s*=\s*({.+});', 'https://exposure.api.redbee.live/v2/customer/UKParliament/businessunit/ParliamentLive/auth/anonymous',
webpage, 'kaltura widget config'), video_id) video_id, headers={
kaltura_url = 'kaltura:%s:%s' % ( 'Origin': 'https://videoplayback.parliamentlive.tv',
widget_config['wid'][1:], widget_config['entry_id']) 'Accept': 'application/json, text/plain, */*',
event_title = self._download_json( 'Content-Type': 'application/json;charset=utf-8'
'http://parliamentlive.tv/Event/GetShareVideo/' + video_id, video_id)['event']['title'] }, data=json.dumps({
return { 'deviceId': _DEVICE_ID,
'_type': 'url_transparent', 'device': {
'title': event_title, 'deviceId': _DEVICE_ID,
'description': '', 'width': 653,
'url': kaltura_url, 'height': 368,
'ie_key': 'Kaltura', 'type': 'WEB',
'name': ' Mozilla Firefox 91'
}
}).encode('utf-8'))['sessionToken']
video_urls = self._download_json(
f'https://exposure.api.redbee.live/v2/customer/UKParliament/businessunit/ParliamentLive/entitlement/{video_id}/play',
video_id, headers={'Authorization': auth, 'Accept': 'application/json, text/plain, */*'})['formats']
formats = []
for format in video_urls:
if not format.get('mediaLocator'):
continue
if format.get('format') == 'DASH':
formats.extend(self._extract_mpd_formats(
format['mediaLocator'], video_id, mpd_id='dash', fatal=False))
elif format.get('format') == 'SMOOTHSTREAMING':
formats.extend(self._extract_ism_formats(
format['mediaLocator'], video_id, ism_id='ism', fatal=False))
elif format.get('format') == 'HLS':
formats.extend(self._extract_m3u8_formats(
format['mediaLocator'], video_id, m3u8_id='hls', fatal=False))
self._sort_formats(formats)
return {
'id': video_id,
'formats': formats,
'title': video_info['event']['title'],
'timestamp': unified_timestamp(try_get(video_info, lambda x: x['event']['publishedStartTime'])),
'thumbnail': video_info.get('thumbnailUrl'),
} }