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.

99 lines
3.8 KiB

  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/[^?#]+/[^?#/]*?_(?P<id>[0-9]{8,})._[^?#/]*\.html'
  12. _TEST = {
  13. 'url': 'http://media.ccc.de/browse/congress/2013/30C3_-_5443_-_en_-_saal_g_-_201312281830_-_introduction_to_processor_design_-_byterazor.html#video',
  14. 'md5': '3a1eda8f3a29515d27f5adb967d7e740',
  15. 'info_dict': {
  16. 'id': '20131228183',
  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. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id)
  28. if self._downloader.params.get('prefer_free_formats'):
  29. preference = qualities(['mp3', 'opus', 'mp4-lq', 'webm-lq', 'h264-sd', 'mp4-sd', 'webm-sd', 'mp4', 'webm', 'mp4-hd', 'h264-hd', 'webm-hd'])
  30. else:
  31. preference = qualities(['opus', 'mp3', 'webm-lq', 'mp4-lq', 'webm-sd', 'h264-sd', 'mp4-sd', 'webm', 'mp4', 'webm-hd', 'mp4-hd', 'h264-hd'])
  32. title = self._html_search_regex(
  33. r'(?s)<h1>(.*?)</h1>', webpage, 'title')
  34. description = self._html_search_regex(
  35. r"(?s)<p class='description'>(.*?)</p>",
  36. webpage, 'description', fatal=False)
  37. upload_date = unified_strdate(self._html_search_regex(
  38. r"(?s)<span class='[^']*fa-calendar-o'></span>(.*?)</li>",
  39. webpage, 'upload date', fatal=False))
  40. view_count = int_or_none(self._html_search_regex(
  41. r"(?s)<span class='[^']*fa-eye'></span>(.*?)</li>",
  42. webpage, 'view count', fatal=False))
  43. matches = re.finditer(r'''(?xs)
  44. <(?:span|div)\s+class='label\s+filetype'>(?P<format>.*?)</(?:span|div)>\s*
  45. <a\s+download\s+href='(?P<http_url>[^']+)'>\s*
  46. (?:
  47. .*?
  48. <a\s+href='(?P<torrent_url>[^']+\.torrent)'
  49. )?''', webpage)
  50. formats = []
  51. for m in matches:
  52. format = m.group('format')
  53. format_id = self._search_regex(
  54. r'.*/([a-z0-9_-]+)/[^/]*$',
  55. m.group('http_url'), 'format id', default=None)
  56. vcodec = 'h264' if 'h264' in format_id else (
  57. 'none' if format_id in ('mp3', 'opus') else None
  58. )
  59. formats.append({
  60. 'format_id': format_id,
  61. 'format': format,
  62. 'url': m.group('http_url'),
  63. 'vcodec': vcodec,
  64. 'preference': preference(format_id),
  65. })
  66. if m.group('torrent_url'):
  67. formats.append({
  68. 'format_id': 'torrent-%s' % (format if format_id is None else format_id),
  69. 'format': '%s (torrent)' % format,
  70. 'proto': 'torrent',
  71. 'format_note': '(unsupported; will just download the .torrent file)',
  72. 'vcodec': vcodec,
  73. 'preference': -100 + preference(format_id),
  74. 'url': m.group('torrent_url'),
  75. })
  76. self._sort_formats(formats)
  77. thumbnail = self._html_search_regex(
  78. r"<video.*?poster='([^']+)'", webpage, 'thumbnail', fatal=False)
  79. return {
  80. 'id': video_id,
  81. 'title': title,
  82. 'description': description,
  83. 'thumbnail': thumbnail,
  84. 'view_count': view_count,
  85. 'upload_date': upload_date,
  86. 'formats': formats,
  87. }