ccc.py 3.9 KB

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