]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ccc.py
Imported Upstream version 2016.02.22
[youtubedl] / youtube_dl / extractor / ccc.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 int_or_none,
8 parse_duration,
9 qualities,
10 unified_strdate,
11 )
12
13
14 class CCCIE(InfoExtractor):
15 IE_NAME = 'media.ccc.de'
16 _VALID_URL = r'https?://(?:www\.)?media\.ccc\.de/v/(?P<id>[^/?#&]+)'
17
18 _TESTS = [{
19 'url': 'https://media.ccc.de/v/30C3_-_5443_-_en_-_saal_g_-_201312281830_-_introduction_to_processor_design_-_byterazor#video',
20 'md5': '3a1eda8f3a29515d27f5adb967d7e740',
21 'info_dict': {
22 'id': '30C3_-_5443_-_en_-_saal_g_-_201312281830_-_introduction_to_processor_design_-_byterazor',
23 'ext': 'mp4',
24 'title': 'Introduction to Processor Design',
25 'description': 'md5:80be298773966f66d56cb11260b879af',
26 'thumbnail': 're:^https?://.*\.jpg$',
27 'view_count': int,
28 'upload_date': '20131228',
29 'duration': 3660,
30 }
31 }, {
32 'url': 'https://media.ccc.de/v/32c3-7368-shopshifting#download',
33 'only_matching': True,
34 }]
35
36 def _real_extract(self, url):
37 video_id = self._match_id(url)
38 webpage = self._download_webpage(url, video_id)
39
40 if self._downloader.params.get('prefer_free_formats'):
41 preference = qualities(['mp3', 'opus', 'mp4-lq', 'webm-lq', 'h264-sd', 'mp4-sd', 'webm-sd', 'mp4', 'webm', 'mp4-hd', 'h264-hd', 'webm-hd'])
42 else:
43 preference = qualities(['opus', 'mp3', 'webm-lq', 'mp4-lq', 'webm-sd', 'h264-sd', 'mp4-sd', 'webm', 'mp4', 'webm-hd', 'mp4-hd', 'h264-hd'])
44
45 title = self._html_search_regex(
46 r'(?s)<h1>(.*?)</h1>', webpage, 'title')
47 description = self._html_search_regex(
48 r'(?s)<h3>About</h3>(.+?)<h3>',
49 webpage, 'description', fatal=False)
50 upload_date = unified_strdate(self._html_search_regex(
51 r"(?s)<span[^>]+class='[^']*fa-calendar-o'[^>]*>(.+?)</span>",
52 webpage, 'upload date', fatal=False))
53 view_count = int_or_none(self._html_search_regex(
54 r"(?s)<span class='[^']*fa-eye'></span>(.*?)</li>",
55 webpage, 'view count', fatal=False))
56 duration = parse_duration(self._html_search_regex(
57 r'(?s)<span[^>]+class=(["\']).*?fa-clock-o.*?\1[^>]*></span>(?P<duration>.+?)</li',
58 webpage, 'duration', fatal=False, group='duration'))
59
60 matches = re.finditer(r'''(?xs)
61 <(?:span|div)\s+class='label\s+filetype'>(?P<format>[^<]*)</(?:span|div)>\s*
62 <(?:span|div)\s+class='label\s+filetype'>(?P<lang>[^<]*)</(?:span|div)>\s*
63 <a\s+download\s+href='(?P<http_url>[^']+)'>\s*
64 (?:
65 .*?
66 <a\s+(?:download\s+)?href='(?P<torrent_url>[^']+\.torrent)'
67 )?''', webpage)
68 formats = []
69 for m in matches:
70 format = m.group('format')
71 format_id = self._search_regex(
72 r'.*/([a-z0-9_-]+)/[^/]*$',
73 m.group('http_url'), 'format id', default=None)
74 if format_id:
75 format_id = m.group('lang') + '-' + format_id
76 vcodec = 'h264' if 'h264' in format_id else (
77 'none' if format_id in ('mp3', 'opus') else None
78 )
79 formats.append({
80 'format_id': format_id,
81 'format': format,
82 'language': m.group('lang'),
83 'url': m.group('http_url'),
84 'vcodec': vcodec,
85 'preference': preference(format_id),
86 })
87
88 if m.group('torrent_url'):
89 formats.append({
90 'format_id': 'torrent-%s' % (format if format_id is None else format_id),
91 'format': '%s (torrent)' % format,
92 'proto': 'torrent',
93 'format_note': '(unsupported; will just download the .torrent file)',
94 'vcodec': vcodec,
95 'preference': -100 + preference(format_id),
96 'url': m.group('torrent_url'),
97 })
98 self._sort_formats(formats)
99
100 thumbnail = self._html_search_regex(
101 r"<video.*?poster='([^']+)'", webpage, 'thumbnail', fatal=False)
102
103 return {
104 'id': video_id,
105 'title': title,
106 'description': description,
107 'thumbnail': thumbnail,
108 'view_count': view_count,
109 'upload_date': upload_date,
110 'duration': duration,
111 'formats': formats,
112 }