]>
Commit | Line | Data |
---|---|---|
e295618f | 1 | # coding: utf-8 |
0865f397 PH |
2 | from __future__ import unicode_literals |
3 | ||
4 | from .common import InfoExtractor | |
8e01f3ca S |
5 | from ..compat import compat_str |
6 | from ..utils import ( | |
7 | float_or_none, | |
acbd0ff5 S |
8 | int_or_none, |
9 | unified_timestamp, | |
3052a30d | 10 | url_or_none, |
8e01f3ca | 11 | ) |
0865f397 | 12 | |
48a1e514 | 13 | |
0865f397 | 14 | class DctpTvIE(InfoExtractor): |
8e01f3ca | 15 | _VALID_URL = r'https?://(?:www\.)?dctp\.tv/(?:#/)?filme/(?P<id>[^/?#&]+)' |
acbd0ff5 S |
16 | _TESTS = [{ |
17 | # 4x3 | |
48a1e514 | 18 | 'url': 'http://www.dctp.tv/filme/videoinstallation-fuer-eine-kaufhausfassade/', |
b2771a28 | 19 | 'md5': '3ffbd1556c3fe210724d7088fad723e3', |
48a1e514 | 20 | 'info_dict': { |
e295618f | 21 | 'id': '95eaa4f33dad413aa17b4ee613cccc6c', |
75a4fc5b | 22 | 'display_id': 'videoinstallation-fuer-eine-kaufhausfassade', |
b2771a28 | 23 | 'ext': 'm4v', |
e295618f YCH |
24 | 'title': 'Videoinstallation für eine Kaufhausfassade', |
25 | 'description': 'Kurzfilm', | |
ec85ded8 | 26 | 'thumbnail': r're:^https?://.*\.jpg$', |
8e01f3ca | 27 | 'duration': 71.24, |
acbd0ff5 S |
28 | 'timestamp': 1302172322, |
29 | 'upload_date': '20110407', | |
8e01f3ca | 30 | }, |
acbd0ff5 S |
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' | |
0865f397 PH |
38 | |
39 | def _real_extract(self, url): | |
8e01f3ca | 40 | display_id = self._match_id(url) |
e295618f | 41 | |
acbd0ff5 S |
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']) | |
0865f397 | 48 | |
acbd0ff5 S |
49 | info = self._download_json( |
50 | '%s/slugs/%s.json' % (restapi_base, display_id), display_id, | |
51 | 'Downloading video info JSON') | |
e295618f | 52 | |
acbd0ff5 S |
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'] | |
b2771a28 RA |
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') | |
8e01f3ca | 79 | |
acbd0ff5 S |
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 | |
3052a30d S |
86 | image_url = url_or_none(image.get('url')) |
87 | if not image_url: | |
acbd0ff5 S |
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 | }) | |
0865f397 PH |
94 | |
95 | return { | |
acbd0ff5 S |
96 | 'id': uuid, |
97 | 'display_id': display_id, | |
0865f397 | 98 | 'title': title, |
acbd0ff5 S |
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, | |
e295618f | 104 | 'formats': formats, |
0865f397 | 105 | } |