You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.8 KiB

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