]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/dctp.py
769a219dffe36ec73dab5d1e0fc18ab9bfc61993
[youtubedl] / 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 'info_dict': {
20 'id': '95eaa4f33dad413aa17b4ee613cccc6c',
21 'display_id': 'videoinstallation-fuer-eine-kaufhausfassade',
22 'ext': 'flv',
23 'title': 'Videoinstallation für eine Kaufhausfassade',
24 'description': 'Kurzfilm',
25 'thumbnail': r're:^https?://.*\.jpg$',
26 'duration': 71.24,
27 'timestamp': 1302172322,
28 'upload_date': '20110407',
29 },
30 'params': {
31 # rtmp download
32 'skip_download': True,
33 },
34 }, {
35 # 16x9
36 'url': 'http://www.dctp.tv/filme/sind-youtuber-die-besseren-lehrer/',
37 'only_matching': True,
38 }]
39
40 _BASE_URL = 'http://dctp-ivms2-restapi.s3.amazonaws.com'
41
42 def _real_extract(self, url):
43 display_id = self._match_id(url)
44
45 version = self._download_json(
46 '%s/version.json' % self._BASE_URL, display_id,
47 'Downloading version JSON')
48
49 restapi_base = '%s/%s/restapi' % (
50 self._BASE_URL, version['version_name'])
51
52 info = self._download_json(
53 '%s/slugs/%s.json' % (restapi_base, display_id), display_id,
54 'Downloading video info JSON')
55
56 media = self._download_json(
57 '%s/media/%s.json' % (restapi_base, compat_str(info['object_id'])),
58 display_id, 'Downloading media JSON')
59
60 uuid = media['uuid']
61 title = media['title']
62 ratio = '16x9' if media.get('is_wide') else '4x3'
63 play_path = 'mp4:%s_dctp_0500_%s.m4v' % (uuid, ratio)
64
65 servers = self._download_json(
66 'http://www.dctp.tv/streaming_servers/', display_id,
67 note='Downloading server list JSON', fatal=False)
68
69 if servers:
70 endpoint = next(
71 server['endpoint']
72 for server in servers
73 if url_or_none(server.get('endpoint')) and
74 'cloudfront' in server['endpoint'])
75 else:
76 endpoint = 'rtmpe://s2pqqn4u96e4j8.cloudfront.net/cfx/st/'
77
78 app = self._search_regex(
79 r'^rtmpe?://[^/]+/(?P<app>.*)$', endpoint, 'app')
80
81 formats = [{
82 'url': endpoint,
83 'app': app,
84 'play_path': play_path,
85 'page_url': url,
86 'player_url': 'http://svm-prod-dctptv-static.s3.amazonaws.com/dctptv-relaunch2012-110.swf',
87 'ext': 'flv',
88 }]
89
90 thumbnails = []
91 images = media.get('images')
92 if isinstance(images, list):
93 for image in images:
94 if not isinstance(image, dict):
95 continue
96 image_url = url_or_none(image.get('url'))
97 if not image_url:
98 continue
99 thumbnails.append({
100 'url': image_url,
101 'width': int_or_none(image.get('width')),
102 'height': int_or_none(image.get('height')),
103 })
104
105 return {
106 'id': uuid,
107 'display_id': display_id,
108 'title': title,
109 'alt_title': media.get('subtitle'),
110 'description': media.get('description') or media.get('teaser'),
111 'timestamp': unified_timestamp(media.get('created')),
112 'duration': float_or_none(media.get('duration_in_ms'), scale=1000),
113 'thumbnails': thumbnails,
114 'formats': formats,
115 }