]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/ccc.py
[brightcove:legacy] Improve embeds detection (closes #11523)
[youtube-dl] / youtube_dl / extractor / ccc.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5     int_or_none,
6     parse_iso8601,
7 )
8
9
10 class CCCIE(InfoExtractor):
11     IE_NAME = 'media.ccc.de'
12     _VALID_URL = r'https?://(?:www\.)?media\.ccc\.de/v/(?P<id>[^/?#&]+)'
13
14     _TESTS = [{
15         'url': 'https://media.ccc.de/v/30C3_-_5443_-_en_-_saal_g_-_201312281830_-_introduction_to_processor_design_-_byterazor#video',
16         'md5': '3a1eda8f3a29515d27f5adb967d7e740',
17         'info_dict': {
18             'id': '1839',
19             'ext': 'mp4',
20             'title': 'Introduction to Processor Design',
21             'description': 'md5:df55f6d073d4ceae55aae6f2fd98a0ac',
22             'thumbnail': 're:^https?://.*\.jpg$',
23             'upload_date': '20131228',
24             'timestamp': 1388188800,
25             'duration': 3710,
26         }
27     }, {
28         'url': 'https://media.ccc.de/v/32c3-7368-shopshifting#download',
29         'only_matching': True,
30     }]
31
32     def _real_extract(self, url):
33         display_id = self._match_id(url)
34         webpage = self._download_webpage(url, display_id)
35         event_id = self._search_regex("data-id='(\d+)'", webpage, 'event id')
36         event_data = self._download_json('https://media.ccc.de/public/events/%s' % event_id, event_id)
37
38         formats = []
39         for recording in event_data.get('recordings', []):
40             recording_url = recording.get('recording_url')
41             if not recording_url:
42                 continue
43             language = recording.get('language')
44             folder = recording.get('folder')
45             format_id = None
46             if language:
47                 format_id = language
48             if folder:
49                 if language:
50                     format_id += '-' + folder
51                 else:
52                     format_id = folder
53             vcodec = 'h264' if 'h264' in folder else (
54                 'none' if folder in ('mp3', 'opus') else None
55             )
56             formats.append({
57                 'format_id': format_id,
58                 'url': recording_url,
59                 'width': int_or_none(recording.get('width')),
60                 'height': int_or_none(recording.get('height')),
61                 'filesize': int_or_none(recording.get('size'), invscale=1024 * 1024),
62                 'language': language,
63                 'vcodec': vcodec,
64             })
65         self._sort_formats(formats)
66
67         return {
68             'id': event_id,
69             'display_id': display_id,
70             'title': event_data['title'],
71             'description': event_data.get('description'),
72             'thumbnail': event_data.get('thumb_url'),
73             'timestamp': parse_iso8601(event_data.get('date')),
74             'duration': int_or_none(event_data.get('length')),
75             'tags': event_data.get('tags'),
76             'formats': formats,
77         }