]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/ccc.py
[tagesschau] Fix article media ids
[yt-dlp.git] / youtube_dl / extractor / ccc.py
CommitLineData
8f84f571
PH
1from __future__ import unicode_literals
2
3import re
4
5from .common import InfoExtractor
6from ..utils import (
7 int_or_none,
82597f0e 8 parse_duration,
8f84f571
PH
9 qualities,
10 unified_strdate,
11)
12
13
14class CCCIE(InfoExtractor):
15 IE_NAME = 'media.ccc.de'
0d5095fc 16 _VALID_URL = r'https?://(?:www\.)?media\.ccc\.de/v/(?P<id>[^/?#&]+)'
8f84f571 17
0d5095fc
S
18 _TESTS = [{
19 'url': 'https://media.ccc.de/v/30C3_-_5443_-_en_-_saal_g_-_201312281830_-_introduction_to_processor_design_-_byterazor#video',
15da7ce7 20 'md5': '3a1eda8f3a29515d27f5adb967d7e740',
8f84f571 21 'info_dict': {
0d5095fc 22 'id': '30C3_-_5443_-_en_-_saal_g_-_201312281830_-_introduction_to_processor_design_-_byterazor',
8f84f571
PH
23 'ext': 'mp4',
24 'title': 'Introduction to Processor Design',
8499d211 25 'description': 'md5:80be298773966f66d56cb11260b879af',
8f84f571
PH
26 'thumbnail': 're:^https?://.*\.jpg$',
27 'view_count': int,
8499d211 28 'upload_date': '20131228',
82597f0e 29 'duration': 3660,
8f84f571 30 }
0d5095fc
S
31 }, {
32 'url': 'https://media.ccc.de/v/32c3-7368-shopshifting#download',
33 'only_matching': True,
34 }]
8f84f571
PH
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(
611c1dd9 48 r'(?s)<h3>About</h3>(.+?)<h3>',
8f84f571
PH
49 webpage, 'description', fatal=False)
50 upload_date = unified_strdate(self._html_search_regex(
c9154514 51 r"(?s)<span[^>]+class='[^']*fa-calendar-o'[^>]*>(.+?)</span>",
8f84f571
PH
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))
82597f0e
S
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'))
8f84f571
PH
59
60 matches = re.finditer(r'''(?xs)
32f90364
PH
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*
15da7ce7 63 <a\s+download\s+href='(?P<http_url>[^']+)'>\s*
8f84f571
PH
64 (?:
65 .*?
32f90364 66 <a\s+(?:download\s+)?href='(?P<torrent_url>[^']+\.torrent)'
8f84f571
PH
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)
32f90364
PH
74 if format_id:
75 format_id = m.group('lang') + '-' + format_id
8f84f571
PH
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,
32f90364 82 'language': m.group('lang'),
8f84f571
PH
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,
82597f0e 110 'duration': duration,
8f84f571
PH
111 'formats': formats,
112 }