[ccc] Extract creator
[youtube-dl] / youtube_dl / extractor / ccc.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     int_or_none,
7     parse_iso8601,
8     try_get,
9 )
10
11
12 class CCCIE(InfoExtractor):
13     IE_NAME = 'media.ccc.de'
14     _VALID_URL = r'https?://(?:www\.)?media\.ccc\.de/v/(?P<id>[^/?#&]+)'
15
16     _TESTS = [{
17         'url': 'https://media.ccc.de/v/30C3_-_5443_-_en_-_saal_g_-_201312281830_-_introduction_to_processor_design_-_byterazor#video',
18         'md5': '3a1eda8f3a29515d27f5adb967d7e740',
19         'info_dict': {
20             'id': '1839',
21             'ext': 'mp4',
22             'title': 'Introduction to Processor Design',
23             'creator': 'byterazor',
24             'description': 'md5:df55f6d073d4ceae55aae6f2fd98a0ac',
25             'thumbnail': r're:^https?://.*\.jpg$',
26             'upload_date': '20131228',
27             'timestamp': 1388188800,
28             'duration': 3710,
29             'tags': list,
30         }
31     }, {
32         'url': 'https://media.ccc.de/v/32c3-7368-shopshifting#download',
33         'info_dict': {
34             'id': '2835',
35             'ext': 'mp4',
36             'title': 'Shopshifting',
37             'creator': 'Karsten Nohl, Fabian Bräunlein, dexter',
38             'description': 'md5:0fade0535e9dc3076d0cbda4958a18eb',
39             'upload_date': '20151227',
40             'timestamp': 1451249100,
41             'tags': list,
42         }
43     }]
44
45     def _real_extract(self, url):
46         display_id = self._match_id(url)
47         webpage = self._download_webpage(url, display_id)
48         event_id = self._search_regex(r"data-id='(\d+)'", webpage, 'event id')
49         event_data = self._download_json('https://media.ccc.de/public/events/%s' % event_id, event_id)
50
51         formats = []
52         for recording in event_data.get('recordings', []):
53             recording_url = recording.get('recording_url')
54             if not recording_url:
55                 continue
56             language = recording.get('language')
57             folder = recording.get('folder')
58             format_id = None
59             if language:
60                 format_id = language
61             if folder:
62                 if language:
63                     format_id += '-' + folder
64                 else:
65                     format_id = folder
66             vcodec = 'h264' if 'h264' in folder else (
67                 'none' if folder in ('mp3', 'opus') else None
68             )
69             formats.append({
70                 'format_id': format_id,
71                 'url': recording_url,
72                 'width': int_or_none(recording.get('width')),
73                 'height': int_or_none(recording.get('height')),
74                 'filesize': int_or_none(recording.get('size'), invscale=1024 * 1024),
75                 'language': language,
76                 'vcodec': vcodec,
77             })
78         self._sort_formats(formats)
79
80         return {
81             'id': event_id,
82             'display_id': display_id,
83             'title': event_data['title'],
84             'creator': try_get(event_data, lambda x: ', '.join(x['persons'])),
85             'description': event_data.get('description'),
86             'thumbnail': event_data.get('thumb_url'),
87             'timestamp': parse_iso8601(event_data.get('date')),
88             'duration': int_or_none(event_data.get('length')),
89             'tags': event_data.get('tags'),
90             'formats': formats,
91         }
92
93
94 class CCCPlaylistIE(InfoExtractor):
95     IE_NAME = 'media.ccc.de:lists'
96     _VALID_URL = r'https?://(?:www\.)?media\.ccc\.de/c/(?P<id>[^/?#&]+)'
97     _TESTS = [{
98         'url': 'https://media.ccc.de/c/30c3',
99         'info_dict': {
100             'title': '30C3',
101             'id': '30c3',
102         },
103         'playlist_count': 135,
104     }]
105
106     def _real_extract(self, url):
107         acronym = self._match_id(url).lower()
108
109         conf = self._download_json('https://media.ccc.de/public/conferences/' + acronym, acronym)
110
111         return self.playlist_result(
112             [self.url_result(event['frontend_link']) for event in conf['events']],
113             acronym,
114             conf['title'],
115         )