mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-08-21 11:36:05 +03:00
243 lines
11 KiB
Python
243 lines
11 KiB
Python
from .common import InfoExtractor
|
|
from ..utils import (
|
|
int_or_none,
|
|
parse_iso8601,
|
|
str_or_none,
|
|
traverse_obj,
|
|
url_or_none,
|
|
urljoin,
|
|
)
|
|
|
|
|
|
class EuropaIE(InfoExtractor):
|
|
_VALID_URL = r'https?://audiovisual\.ec\.europa\.eu/(?P<language>[^/]*)/video/(?P<id>[A-Za-z0-9-]+)'
|
|
_FORMATS = {
|
|
'lr': {'vcodec': 'h264', 'acodec': 'aac', 'height': 480},
|
|
'hdmp4': {'vcodec': 'h264', 'acodec': 'aac', 'height': 1080},
|
|
'mp3': {'vcodec': 'none', 'acodec': 'mp3', 'abr': 128},
|
|
}
|
|
_TESTS = [{
|
|
'url': 'https://audiovisual.ec.europa.eu/en/video/I-107758',
|
|
'md5': '728cca2fd41d5aa7350cec1141fbe620',
|
|
'info_dict': {
|
|
'id': 'I-107758',
|
|
'ext': 'mp4',
|
|
'title': 'TRADE - Wikileaks on TTIP:- Q&A',
|
|
'description': 'LIVE EC Midday press briefing of 11/08/2015',
|
|
'uploader': 'beluga',
|
|
'duration': 34.92,
|
|
'thumbnail': 'https://vod.prd.commavservices.eu/18/107758/THUMB_M_I107758INT1W.jpg',
|
|
'timestamp': 1439288640,
|
|
'upload_date': '20150811',
|
|
'modified_timestamp': 1731858348,
|
|
'modified_date': '20241117',
|
|
},
|
|
}, {
|
|
'url': 'https://audiovisual.ec.europa.eu/en/video/I-107786',
|
|
'md5': '5ecf1eb72800573ed75a53fc06511967',
|
|
'info_dict': {
|
|
'id': 'I-107786',
|
|
'ext': 'mp4',
|
|
'title': 'Midday press briefing from 14/08/2015',
|
|
'description': 'md5:e56082f090a0ad1da6b76f453dd9d155',
|
|
'uploader': 'beluga',
|
|
'thumbnail': 'https://vod.prd.commavservices.eu/06/107786/THUMB_M_I107786INT1W.jpg',
|
|
'timestamp': 1439503200,
|
|
'upload_date': '20150813',
|
|
'modified_timestamp': 1731858616,
|
|
'modified_date': '20241117',
|
|
},
|
|
}, {
|
|
'url': 'https://audiovisual.ec.europa.eu/en/video/I-109295',
|
|
'md5': '3a6d560e0aff5633de4bb7cdc368ab72',
|
|
'info_dict': {
|
|
'id': 'I-109295',
|
|
'ext': 'mp4',
|
|
'title': 'md5:dfc882adaabf388999e20d3079ee5277',
|
|
'description': 'md5:67374bddab3fd2a8a319a92e1a286ad2',
|
|
'uploader': 'beluga',
|
|
'thumbnail': 'https://vod.prd.commavservices.eu/15/109295/THUMB_M_I109295INT1W_03.jpg',
|
|
'timestamp': 1443762000,
|
|
'upload_date': '20151002',
|
|
'modified_timestamp': 1731845416,
|
|
'modified_date': '20241117',
|
|
},
|
|
}]
|
|
|
|
def _real_extract(self, url):
|
|
language, video_id = self._match_valid_url(url).group('language', 'id')
|
|
constants = self._download_webpage('https://audiovisual.ec.europa.eu/js/constants.js', video_id, 'Downloading constants')
|
|
api = self._search_regex(r'"urlJellyfishApi":\s*"([^"]+)"', constants, 'urlJellyfishApi', 'https://yy2iyrkool.execute-api.eu-west-1.amazonaws.com/jellyfish/')
|
|
media = self._download_json(urljoin(api, f'medias/{video_id}'), video_id, 'Downloading media JSON')
|
|
info = traverse_obj(media, ('latest', {
|
|
'modified_timestamp': ('timestamp', {parse_iso8601}),
|
|
'uploader': ('user', {str_or_none}),
|
|
'id': ('data', 'reference', {str_or_none}),
|
|
'duration': ('data', 'duration', {lambda d: None if d == 1 else d}),
|
|
'timestamp': ('data', 'productionDatetime', {parse_iso8601}),
|
|
'title': ('data', 'titles', ..., ..., {lambda t: t and t.strip()}, any),
|
|
'description': ('data', 'summaries', ..., ..., {lambda t: t and t.strip()}, any),
|
|
'thumbnails': ('data', 'files', ..., ('image', 'thumb'), {'url': ('url', {url_or_none})}),
|
|
}))
|
|
formats = []
|
|
|
|
for file in traverse_obj(media, ('latest', 'data', 'files', ...)):
|
|
l = traverse_obj(file, ('language', {lambda l: l and l.lower()}))
|
|
for k in ('mp3', 'lr', 'hdmp4'):
|
|
if f_url := traverse_obj(file, (k, 'url')):
|
|
formats.append({
|
|
'url': f_url,
|
|
'language': l,
|
|
'language_preference': 10 if (l and l.lower() == language) or l == 'int' else -10,
|
|
'format_id': f'{k}-{l}',
|
|
**self._FORMATS[k],
|
|
})
|
|
return {**info, 'formats': formats}
|
|
|
|
|
|
class EuroParlWebstreamIE(InfoExtractor):
|
|
_VALID_URL = r'''(?x)
|
|
https?://multimedia\.europarl\.europa\.eu/
|
|
(?:[^/]*/)?webstreaming/(?:[^_]*_)?(?P<id>[\w-]+)
|
|
'''
|
|
_TESTS = [{
|
|
'url': 'https://multimedia.europarl.europa.eu/pl/webstreaming/plenary-session_20220914-0900-PLENARY',
|
|
'md5': '16420ad9c602663759538ac1ca16a8db',
|
|
'info_dict': {
|
|
'id': '20220914-0900-PLENARY',
|
|
'ext': 'mp4',
|
|
'title': 'Plenary session',
|
|
'description': '',
|
|
'duration': 45147,
|
|
'thumbnail': 'https://storage.eup.glcloud.eu/thumbnail/default_thumbnail.png',
|
|
'release_timestamp': 1663139069,
|
|
'release_date': '20220914',
|
|
'modified_timestamp': 1663650921,
|
|
'modified_date': '20220920',
|
|
'live_status': 'was_live',
|
|
},
|
|
}, {
|
|
'url': 'https://multimedia.europarl.europa.eu/en/webstreaming/euroscola_20221115-1000-SPECIAL-EUROSCOLA',
|
|
'md5': '8b4304f9e15a6e133100248fb55a5dce',
|
|
'info_dict': {
|
|
'ext': 'mp4',
|
|
'id': '20221115-1000-SPECIAL-EUROSCOLA',
|
|
'release_timestamp': 1668502798,
|
|
'title': 'Euroscola',
|
|
'release_date': '20221115',
|
|
'live_status': 'was_live',
|
|
'description': '',
|
|
'duration': 9587,
|
|
'thumbnail': 'https://storage.eup.glcloud.eu/thumbnail/default_thumbnail.png',
|
|
'modified_timestamp': 1668945274,
|
|
'modified_date': '20221120',
|
|
},
|
|
}, {
|
|
'url': 'https://multimedia.europarl.europa.eu/en/webstreaming/committee-on-culture-and-education_20230301-1130-COMMITTEE-CULT',
|
|
'md5': '0ca01cf33009d866e6f5e1cd3088c10c',
|
|
'info_dict': {
|
|
'id': '20230301-1130-COMMITTEE-CULT',
|
|
'ext': 'mp4',
|
|
'release_date': '20230301',
|
|
'title': 'Committee on Culture and Education',
|
|
'release_timestamp': 1677666641,
|
|
'description': 'Committee on Culture and Education',
|
|
'duration': 1003,
|
|
'thumbnail': 'https://storage.eup.glcloud.eu/thumbnail/default_thumbnail.png',
|
|
'modified_timestamp': 1732475771,
|
|
'modified_date': '20241124',
|
|
'live_status': 'was_live',
|
|
},
|
|
}, {
|
|
'url': 'https://multimedia.europarl.europa.eu/en/webstreaming/committee-on-environment-public-health-and-food-safety_20230524-0900-COMMITTEE-ENVI',
|
|
'md5': 'f2e8c30935f956a7165c2f4f4b4ee090',
|
|
'info_dict': {
|
|
'id': '20230524-0900-COMMITTEE-ENVI',
|
|
'ext': 'mp4',
|
|
'release_date': '20230524',
|
|
'title': 'Committee on Environment, Public Health and Food Safety',
|
|
'release_timestamp': 1684912288,
|
|
'live_status': 'was_live',
|
|
'description': 'Committee on Environment, Public Health and Food Safety',
|
|
'duration': 4831,
|
|
'thumbnail': 'https://storage.eup.glcloud.eu/thumbnail/default_thumbnail.png',
|
|
'modified_timestamp': 1732475771,
|
|
'modified_date': '20241124',
|
|
},
|
|
}, {
|
|
'url': 'https://multimedia.europarl.europa.eu/en/webstreaming/20240320-1345-SPECIAL-PRESSER',
|
|
'md5': '518758eb706471c4c4ef3a134034a5bd',
|
|
'info_dict': {
|
|
'id': '20240320-1345-SPECIAL-PRESSER',
|
|
'ext': 'mp4',
|
|
'release_date': '20240320',
|
|
'title': 'md5:7c6c814cac55dea5e2d87bf8d3db2234',
|
|
'release_timestamp': 1710939767,
|
|
'description': 'md5:7c6c814cac55dea5e2d87bf8d3db2234',
|
|
'duration': 927,
|
|
'thumbnail': 'https://storage.eup.glcloud.eu/thumbnail/default_thumbnail.png',
|
|
'modified_timestamp': 1732475771,
|
|
'modified_date': '20241124',
|
|
'live_status': 'was_live',
|
|
},
|
|
}, {
|
|
'url': 'https://multimedia.europarl.europa.eu/en/webstreaming/20250328-1600-SPECIAL-PRESSER',
|
|
'md5': 'dd1c5e67eb55e609998583d7c2966105',
|
|
'info_dict': {
|
|
'id': '20250328-1600-SPECIAL-PRESSER',
|
|
'ext': 'mp4',
|
|
'title': 'md5:04a2ab70c183dabe891a7cd190c3121d',
|
|
'description': '',
|
|
'duration': 1023,
|
|
'thumbnail': 'https://storage.eup.glcloud.eu/thumbnail/default_thumbnail.png',
|
|
'release_timestamp': 1743177199,
|
|
'release_date': '20250328',
|
|
'modified_timestamp': 1743180924,
|
|
'modified_date': '20250328',
|
|
'live_status': 'was_live',
|
|
},
|
|
}, {
|
|
'url': 'https://multimedia.europarl.europa.eu/webstreaming/briefing-for-media-on-2024-european-elections_20240429-1000-SPECIAL-OTHER',
|
|
'only_matching': True,
|
|
}]
|
|
|
|
def _real_extract(self, url):
|
|
video_id = self._match_id(url)
|
|
webpage = self._download_webpage(f'https://control.eup.glcloud.eu/content-manager/content-page/{video_id}', video_id)
|
|
stream_info = self._search_json(r'<script [^>]*id="ng-state"[^>]*>', webpage, 'stream info', video_id)['contentEventKey']
|
|
player_url = stream_info.get('playerUrl')
|
|
# status = traverse_obj(stream_info, ('media_item', 'mediaSubType'))
|
|
# base = 'https://control.eup.glcloud.eu/content-manager/api/v1/socket.io/?EIO=4&transport=polling'
|
|
# headers = {'referer': f'https://control.eup.glcloud.eu/content-manager/content-page/{video_id}'}
|
|
# sid = self._download_socket_json(base, video_id, note='Opening socket', headers=headers)['sid']
|
|
# base += '&sid=' + sid
|
|
# self._download_webpage(base, video_id, 'Polling socket with payload', data=b'40/content,', headers=headers)
|
|
# self._download_webpage(base, video_id, 'Polling socket', headers=headers)
|
|
# self._download_socket_json(base, video_id, 'Getting broadcast metadata from socket', headers=headers)
|
|
if player_url:
|
|
live_status = 'was_live'
|
|
query = None if stream_info.get('finalVod') else {'startTime': stream_info.get('startTime'), 'endTime': stream_info.get('endTime')}
|
|
formats, subtitles = self._extract_m3u8_formats_and_subtitles(player_url, video_id, query=query)
|
|
else:
|
|
formats = None
|
|
subtitles = None
|
|
live_status = 'is_upcoming'
|
|
self.raise_no_formats('Stream didn\'t start yet', True, video_id)
|
|
if stream_info.get('live'):
|
|
live_status = 'is_live'
|
|
|
|
return {
|
|
'formats': formats,
|
|
'subtitles': subtitles,
|
|
'live_status': live_status,
|
|
**traverse_obj(stream_info, {
|
|
'id': ('commonId', {str_or_none}),
|
|
'title': ('title', {str_or_none}),
|
|
'description': ('description', {str_or_none}),
|
|
'release_timestamp': ('startTime', {int_or_none}),
|
|
'duration': ('endTime', {lambda e: e and (s := stream_info.get('startTime')) and (e - s)}),
|
|
'thumbnail': ('posterFrame', {url_or_none}),
|
|
'modified_timestamp': ('meta', 'updatedAt', {parse_iso8601}),
|
|
}),
|
|
}
|