ccc.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. parse_iso8601,
  5. try_get,
  6. url_or_none,
  7. )
  8. class CCCIE(InfoExtractor):
  9. IE_NAME = 'media.ccc.de'
  10. _VALID_URL = r'https?://(?:www\.)?media\.ccc\.de/v/(?P<id>[^/?#&]+)'
  11. _TESTS = [{
  12. 'url': 'https://media.ccc.de/v/30C3_-_5443_-_en_-_saal_g_-_201312281830_-_introduction_to_processor_design_-_byterazor#video',
  13. 'md5': '3a1eda8f3a29515d27f5adb967d7e740',
  14. 'info_dict': {
  15. 'id': '1839',
  16. 'ext': 'mp4',
  17. 'title': 'Introduction to Processor Design',
  18. 'creator': 'byterazor',
  19. 'description': 'md5:df55f6d073d4ceae55aae6f2fd98a0ac',
  20. 'thumbnail': r're:^https?://.*\.jpg$',
  21. 'upload_date': '20131228',
  22. 'timestamp': 1388188800,
  23. 'duration': 3710,
  24. 'tags': list,
  25. },
  26. }, {
  27. 'url': 'https://media.ccc.de/v/32c3-7368-shopshifting#download',
  28. 'only_matching': True,
  29. }]
  30. def _real_extract(self, url):
  31. display_id = self._match_id(url)
  32. webpage = self._download_webpage(url, display_id)
  33. event_id = self._search_regex(r"data-id='(\d+)'", webpage, 'event id')
  34. event_data = self._download_json(f'https://media.ccc.de/public/events/{event_id}', event_id)
  35. formats = []
  36. for recording in event_data.get('recordings', []):
  37. recording_url = recording.get('recording_url')
  38. if not recording_url:
  39. continue
  40. language = recording.get('language')
  41. folder = recording.get('folder')
  42. format_id = None
  43. if language:
  44. format_id = language
  45. if folder:
  46. if language:
  47. format_id += '-' + folder
  48. else:
  49. format_id = folder
  50. vcodec = 'h264' if 'h264' in folder else (
  51. 'none' if folder in ('mp3', 'opus') else None
  52. )
  53. formats.append({
  54. 'format_id': format_id,
  55. 'url': recording_url,
  56. 'width': int_or_none(recording.get('width')),
  57. 'height': int_or_none(recording.get('height')),
  58. 'filesize': int_or_none(recording.get('size'), invscale=1024 * 1024),
  59. 'language': language,
  60. 'vcodec': vcodec,
  61. })
  62. return {
  63. 'id': event_id,
  64. 'display_id': display_id,
  65. 'title': event_data['title'],
  66. 'creator': try_get(event_data, lambda x: ', '.join(x['persons'])),
  67. 'description': event_data.get('description'),
  68. 'thumbnail': event_data.get('thumb_url'),
  69. 'timestamp': parse_iso8601(event_data.get('date')),
  70. 'duration': int_or_none(event_data.get('length')),
  71. 'view_count': int_or_none(event_data.get('view_count')),
  72. 'tags': event_data.get('tags'),
  73. 'formats': formats,
  74. }
  75. class CCCPlaylistIE(InfoExtractor):
  76. IE_NAME = 'media.ccc.de:lists'
  77. _VALID_URL = r'https?://(?:www\.)?media\.ccc\.de/c/(?P<id>[^/?#&]+)'
  78. _TESTS = [{
  79. 'url': 'https://media.ccc.de/c/30c3',
  80. 'info_dict': {
  81. 'title': '30C3',
  82. 'id': '30c3',
  83. },
  84. 'playlist_count': 135,
  85. }, {
  86. 'url': 'https://media.ccc.de/c/DS2023',
  87. 'info_dict': {
  88. 'title': 'Datenspuren 2023',
  89. 'id': 'DS2023',
  90. },
  91. 'playlist_count': 37,
  92. }]
  93. def _real_extract(self, url):
  94. playlist_id = self._match_id(url)
  95. conf = self._download_json(
  96. 'https://media.ccc.de/public/conferences/' + playlist_id,
  97. playlist_id)
  98. entries = []
  99. for e in conf['events']:
  100. event_url = url_or_none(e.get('frontend_link'))
  101. if event_url:
  102. entries.append(self.url_result(event_url, ie=CCCIE.ie_key()))
  103. return self.playlist_result(entries, playlist_id, conf.get('title'))