ccc.py 3.9 KB

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