]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/dctp.py
[extractor/common] Relax interaction count extraction in _json_ld
[youtube-dl] / youtube_dl / extractor / dctp.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_str
6 from ..utils import (
7     float_or_none,
8     int_or_none,
9     unified_timestamp,
10     url_or_none,
11 )
12
13
14 class DctpTvIE(InfoExtractor):
15     _VALID_URL = r'https?://(?:www\.)?dctp\.tv/(?:#/)?filme/(?P<id>[^/?#&]+)'
16     _TESTS = [{
17         # 4x3
18         'url': 'http://www.dctp.tv/filme/videoinstallation-fuer-eine-kaufhausfassade/',
19         'md5': '3ffbd1556c3fe210724d7088fad723e3',
20         'info_dict': {
21             'id': '95eaa4f33dad413aa17b4ee613cccc6c',
22             'display_id': 'videoinstallation-fuer-eine-kaufhausfassade',
23             'ext': 'm4v',
24             'title': 'Videoinstallation für eine Kaufhausfassade',
25             'description': 'Kurzfilm',
26             'thumbnail': r're:^https?://.*\.jpg$',
27             'duration': 71.24,
28             'timestamp': 1302172322,
29             'upload_date': '20110407',
30         },
31     }, {
32         # 16x9
33         'url': 'http://www.dctp.tv/filme/sind-youtuber-die-besseren-lehrer/',
34         'only_matching': True,
35     }]
36
37     _BASE_URL = 'http://dctp-ivms2-restapi.s3.amazonaws.com'
38
39     def _real_extract(self, url):
40         display_id = self._match_id(url)
41
42         version = self._download_json(
43             '%s/version.json' % self._BASE_URL, display_id,
44             'Downloading version JSON')
45
46         restapi_base = '%s/%s/restapi' % (
47             self._BASE_URL, version['version_name'])
48
49         info = self._download_json(
50             '%s/slugs/%s.json' % (restapi_base, display_id), display_id,
51             'Downloading video info JSON')
52
53         media = self._download_json(
54             '%s/media/%s.json' % (restapi_base, compat_str(info['object_id'])),
55             display_id, 'Downloading media JSON')
56
57         uuid = media['uuid']
58         title = media['title']
59         is_wide = media.get('is_wide')
60         formats = []
61
62         def add_formats(suffix):
63             templ = 'https://%%s/%s_dctp_%s.m4v' % (uuid, suffix)
64             formats.extend([{
65                 'format_id': 'hls-' + suffix,
66                 'url': templ % 'cdn-segments.dctp.tv' + '/playlist.m3u8',
67                 'protocol': 'm3u8_native',
68             }, {
69                 'format_id': 's3-' + suffix,
70                 'url': templ % 'completed-media.s3.amazonaws.com',
71             }, {
72                 'format_id': 'http-' + suffix,
73                 'url': templ % 'cdn-media.dctp.tv',
74             }])
75
76         add_formats('0500_' + ('16x9' if is_wide else '4x3'))
77         if is_wide:
78             add_formats('720p')
79
80         thumbnails = []
81         images = media.get('images')
82         if isinstance(images, list):
83             for image in images:
84                 if not isinstance(image, dict):
85                     continue
86                 image_url = url_or_none(image.get('url'))
87                 if not image_url:
88                     continue
89                 thumbnails.append({
90                     'url': image_url,
91                     'width': int_or_none(image.get('width')),
92                     'height': int_or_none(image.get('height')),
93                 })
94
95         return {
96             'id': uuid,
97             'display_id': display_id,
98             'title': title,
99             'alt_title': media.get('subtitle'),
100             'description': media.get('description') or media.get('teaser'),
101             'timestamp': unified_timestamp(media.get('created')),
102             'duration': float_or_none(media.get('duration_in_ms'), scale=1000),
103             'thumbnails': thumbnails,
104             'formats': formats,
105         }