]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/europa.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / europa.py
CommitLineData
3bb3f041 1from .common import InfoExtractor
2from ..utils import (
af17794c
S
3 int_or_none,
4 orderedSet,
5 parse_duration,
22697a84 6 parse_iso8601,
4dfbf869 7 parse_qs,
af17794c 8 qualities,
03789976 9 traverse_obj,
af17794c 10 unified_strdate,
e897bd82 11 xpath_text,
3bb3f041 12)
13
14
15class EuropaIE(InfoExtractor):
df773c3d 16 _WORKING = False
f3b098fb 17 _VALID_URL = r'https?://ec\.europa\.eu/avservices/(?:video/player|audio/audioDetails)\.cfm\?.*?\bref=(?P<id>[A-Za-z0-9-]+)'
af17794c 18 _TESTS = [{
3bb3f041 19 'url': 'http://ec.europa.eu/avservices/video/player.cfm?ref=I107758',
af17794c 20 'md5': '574f080699ddd1e19a675b0ddf010371',
3bb3f041 21 'info_dict': {
22 'id': 'I107758',
23 'ext': 'mp4',
24 'title': 'TRADE - Wikileaks on TTIP',
25 'description': 'NEW LIVE EC Midday press briefing of 11/08/2015',
ec85ded8 26 'thumbnail': r're:^https?://.*\.jpg$',
af17794c
S
27 'upload_date': '20150811',
28 'duration': 34,
29 'view_count': int,
30 'formats': 'mincount:3',
3bb3f041 31 }
af17794c
S
32 }, {
33 'url': 'http://ec.europa.eu/avservices/video/player.cfm?sitelang=en&ref=I107786',
34 'only_matching': True,
f3b098fb
S
35 }, {
36 'url': 'http://ec.europa.eu/avservices/audio/audioDetails.cfm?ref=I-109295&sitelang=en',
37 'only_matching': True,
af17794c 38 }]
3bb3f041 39
40 def _real_extract(self, url):
41 video_id = self._match_id(url)
3bb3f041 42
af17794c
S
43 playlist = self._download_xml(
44 'http://ec.europa.eu/avservices/video/player/playlist.cfm?ID=%s' % video_id, video_id)
3bb3f041 45
af17794c
S
46 def get_item(type_, preference):
47 items = {}
48 for item in playlist.findall('./info/%s/item' % type_):
49 lang, label = xpath_text(item, 'lg', default=None), xpath_text(item, 'label', default=None)
50 if lang and label:
51 items[lang] = label.strip()
52 for p in preference:
53 if items.get(p):
54 return items[p]
3bb3f041 55
4dfbf869 56 query = parse_qs(url)
af17794c 57 preferred_lang = query.get('sitelang', ('en', ))[0]
3bb3f041 58
af17794c 59 preferred_langs = orderedSet((preferred_lang, 'en', 'int'))
3bb3f041 60
af17794c
S
61 title = get_item('title', preferred_langs) or video_id
62 description = get_item('description', preferred_langs)
a0566bbf 63 thumbnail = xpath_text(playlist, './info/thumburl', 'thumbnail')
af17794c
S
64 upload_date = unified_strdate(xpath_text(playlist, './info/date', 'upload date'))
65 duration = parse_duration(xpath_text(playlist, './info/duration', 'duration'))
b203095d 66 view_count = int_or_none(xpath_text(playlist, './info/views', 'views'))
3bb3f041 67
af17794c 68 language_preference = qualities(preferred_langs[::-1])
3bb3f041 69
af17794c
S
70 formats = []
71 for file_ in playlist.findall('./files/file'):
72 video_url = xpath_text(file_, './url')
73 if not video_url:
74 continue
75 lang = xpath_text(file_, './lg')
76 formats.append({
77 'url': video_url,
78 'format_id': lang,
79 'format_note': xpath_text(file_, './lglabel'),
80 'language_preference': language_preference(lang)
81 })
3bb3f041 82
83 return {
84 'id': video_id,
af17794c
S
85 'title': title,
86 'description': description,
a0566bbf 87 'thumbnail': thumbnail,
af17794c
S
88 'upload_date': upload_date,
89 'duration': duration,
90 'view_count': view_count,
3bb3f041 91 'formats': formats
92 }
22697a84
H
93
94
95class EuroParlWebstreamIE(InfoExtractor):
96 _VALID_URL = r'''(?x)
800a4398
EL
97 https?://multimedia\.europarl\.europa\.eu/
98 (?:\w+/)?webstreaming/(?:[\w-]+_)?(?P<id>[\w-]+)
22697a84
H
99 '''
100 _TESTS = [{
101 'url': 'https://multimedia.europarl.europa.eu/pl/webstreaming/plenary-session_20220914-0900-PLENARY',
102 'info_dict': {
03789976 103 'id': '62388b15-d85b-4add-99aa-ba12ccf64f0d',
800a4398 104 'display_id': '20220914-0900-PLENARY',
22697a84 105 'ext': 'mp4',
22697a84 106 'title': 'Plenary session',
03789976 107 'release_timestamp': 1663139069,
22697a84
H
108 'release_date': '20220914',
109 },
110 'params': {
111 'skip_download': True,
112 }
113 }, {
03789976
H
114 # live webstream
115 'url': 'https://multimedia.europarl.europa.eu/en/webstreaming/euroscola_20221115-1000-SPECIAL-EUROSCOLA',
22697a84 116 'info_dict': {
22697a84 117 'ext': 'mp4',
03789976
H
118 'id': '510eda7f-ba72-161b-7ee7-0e836cd2e715',
119 'release_timestamp': 1668502800,
120 'title': 'Euroscola 2022-11-15 19:21',
121 'release_date': '20221115',
122 'live_status': 'is_live',
22697a84 123 },
03789976 124 'skip': 'not live anymore'
22697a84 125 }, {
03789976 126 'url': 'https://multimedia.europarl.europa.eu/en/webstreaming/committee-on-culture-and-education_20230301-1130-COMMITTEE-CULT',
22697a84 127 'info_dict': {
03789976 128 'id': '7355662c-8eac-445e-4bb9-08db14b0ddd7',
800a4398 129 'display_id': '20230301-1130-COMMITTEE-CULT',
22697a84 130 'ext': 'mp4',
03789976
H
131 'release_date': '20230301',
132 'title': 'Committee on Culture and Education',
133 'release_timestamp': 1677666641,
22697a84
H
134 }
135 }, {
03789976
H
136 # live stream
137 'url': 'https://multimedia.europarl.europa.eu/en/webstreaming/committee-on-environment-public-health-and-food-safety_20230524-0900-COMMITTEE-ENVI',
22697a84 138 'info_dict': {
03789976 139 'id': 'e4255f56-10aa-4b3c-6530-08db56d5b0d9',
22697a84 140 'ext': 'mp4',
03789976
H
141 'release_date': '20230524',
142 'title': r're:Committee on Environment, Public Health and Food Safety \d{4}-\d{2}-\d{2}\s\d{2}:\d{2}',
143 'release_timestamp': 1684911541,
22697a84
H
144 'live_status': 'is_live',
145 },
03789976 146 'skip': 'Not live anymore'
800a4398
EL
147 }, {
148 'url': 'https://multimedia.europarl.europa.eu/en/webstreaming/20240320-1345-SPECIAL-PRESSER',
149 'info_dict': {
150 'id': 'c1f11567-5b52-470a-f3e1-08dc3c216ace',
151 'display_id': '20240320-1345-SPECIAL-PRESSER',
152 'ext': 'mp4',
153 'release_date': '20240320',
154 'title': 'md5:7c6c814cac55dea5e2d87bf8d3db2234',
155 'release_timestamp': 1710939767,
156 }
157 }, {
158 'url': 'https://multimedia.europarl.europa.eu/webstreaming/briefing-for-media-on-2024-european-elections_20240429-1000-SPECIAL-OTHER',
159 'only_matching': True,
22697a84
H
160 }]
161
162 def _real_extract(self, url):
163 display_id = self._match_id(url)
03789976
H
164 webpage = self._download_webpage(url, display_id)
165
166 webpage_nextjs = self._search_nextjs_data(webpage, display_id)['props']['pageProps']
22697a84
H
167
168 json_info = self._download_json(
03789976 169 'https://acs-api.europarl.connectedviews.eu/api/FullMeeting', display_id,
22697a84 170 query={
03789976
H
171 'api-version': 1.0,
172 'tenantId': 'bae646ca-1fc8-4363-80ba-2c04f06b4968',
173 'externalReference': display_id
22697a84
H
174 })
175
03789976
H
176 formats, subtitles = [], {}
177 for hls_url in traverse_obj(json_info, ((('meetingVideo'), ('meetingVideos', ...)), 'hlsUrl')):
178 fmt, subs = self._extract_m3u8_formats_and_subtitles(hls_url, display_id)
179 formats.extend(fmt)
180 self._merge_subtitles(subs, target=subtitles)
22697a84
H
181
182 return {
183 'id': json_info['id'],
800a4398 184 'display_id': display_id,
03789976 185 'title': traverse_obj(webpage_nextjs, (('mediaItem', 'title'), ('title', )), get_all=False),
22697a84
H
186 'formats': formats,
187 'subtitles': subtitles,
03789976
H
188 'release_timestamp': parse_iso8601(json_info.get('startDateTime')),
189 'is_live': traverse_obj(webpage_nextjs, ('mediaItem', 'mediaSubType')) == 'Live'
22697a84 190 }