europa.py 7.3 KB

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