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.

112 lines
4.5 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. parse_duration,
  7. qualities,
  8. unified_strdate,
  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': '30C3_-_5443_-_en_-_saal_g_-_201312281830_-_introduction_to_processor_design_-_byterazor',
  18. 'ext': 'mp4',
  19. 'title': 'Introduction to Processor Design',
  20. 'description': 'md5:80be298773966f66d56cb11260b879af',
  21. 'thumbnail': 're:^https?://.*\.jpg$',
  22. 'view_count': int,
  23. 'upload_date': '20131228',
  24. 'duration': 3660,
  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. video_id = self._match_id(url)
  32. webpage = self._download_webpage(url, video_id)
  33. if self._downloader.params.get('prefer_free_formats'):
  34. preference = qualities(['mp3', 'opus', 'mp4-lq', 'webm-lq', 'h264-sd', 'mp4-sd', 'webm-sd', 'mp4', 'webm', 'mp4-hd', 'h264-hd', 'webm-hd'])
  35. else:
  36. preference = qualities(['opus', 'mp3', 'webm-lq', 'mp4-lq', 'webm-sd', 'h264-sd', 'mp4-sd', 'webm', 'mp4', 'webm-hd', 'mp4-hd', 'h264-hd'])
  37. title = self._html_search_regex(
  38. r'(?s)<h1>(.*?)</h1>', webpage, 'title')
  39. description = self._html_search_regex(
  40. r'(?s)<h3>About</h3>(.+?)<h3>',
  41. webpage, 'description', fatal=False)
  42. upload_date = unified_strdate(self._html_search_regex(
  43. r"(?s)<span[^>]+class='[^']*fa-calendar-o'[^>]*>(.+?)</span>",
  44. webpage, 'upload date', fatal=False))
  45. view_count = int_or_none(self._html_search_regex(
  46. r"(?s)<span class='[^']*fa-eye'></span>(.*?)</li>",
  47. webpage, 'view count', fatal=False))
  48. duration = parse_duration(self._html_search_regex(
  49. r'(?s)<span[^>]+class=(["\']).*?fa-clock-o.*?\1[^>]*></span>(?P<duration>.+?)</li',
  50. webpage, 'duration', fatal=False, group='duration'))
  51. matches = re.finditer(r'''(?xs)
  52. <(?:span|div)\s+class='label\s+filetype'>(?P<format>[^<]*)</(?:span|div)>\s*
  53. <(?:span|div)\s+class='label\s+filetype'>(?P<lang>[^<]*)</(?:span|div)>\s*
  54. <a\s+download\s+href='(?P<http_url>[^']+)'>\s*
  55. (?:
  56. .*?
  57. <a\s+(?:download\s+)?href='(?P<torrent_url>[^']+\.torrent)'
  58. )?''', webpage)
  59. formats = []
  60. for m in matches:
  61. format = m.group('format')
  62. format_id = self._search_regex(
  63. r'.*/([a-z0-9_-]+)/[^/]*$',
  64. m.group('http_url'), 'format id', default=None)
  65. if format_id:
  66. format_id = m.group('lang') + '-' + format_id
  67. vcodec = 'h264' if 'h264' in format_id else (
  68. 'none' if format_id in ('mp3', 'opus') else None
  69. )
  70. formats.append({
  71. 'format_id': format_id,
  72. 'format': format,
  73. 'language': m.group('lang'),
  74. 'url': m.group('http_url'),
  75. 'vcodec': vcodec,
  76. 'preference': preference(format_id),
  77. })
  78. if m.group('torrent_url'):
  79. formats.append({
  80. 'format_id': 'torrent-%s' % (format if format_id is None else format_id),
  81. 'format': '%s (torrent)' % format,
  82. 'proto': 'torrent',
  83. 'format_note': '(unsupported; will just download the .torrent file)',
  84. 'vcodec': vcodec,
  85. 'preference': -100 + preference(format_id),
  86. 'url': m.group('torrent_url'),
  87. })
  88. self._sort_formats(formats)
  89. thumbnail = self._html_search_regex(
  90. r"<video.*?poster='([^']+)'", webpage, 'thumbnail', fatal=False)
  91. return {
  92. 'id': video_id,
  93. 'title': title,
  94. 'description': description,
  95. 'thumbnail': thumbnail,
  96. 'view_count': view_count,
  97. 'upload_date': upload_date,
  98. 'duration': duration,
  99. 'formats': formats,
  100. }