ccc.py 3.5 KB

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