]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tvplay.py
Prepare for release.
[youtubedl] / youtube_dl / extractor / tvplay.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_str
8 from ..utils import (
9 parse_iso8601,
10 qualities,
11 )
12
13
14 class TVPlayIE(InfoExtractor):
15 IE_DESC = 'TV3Play and related services'
16 _VALID_URL = r'''(?x)http://(?:www\.)?
17 (?:tvplay\.lv/parraides|
18 tv3play\.lt/programos|
19 tv3play\.ee/sisu|
20 tv3play\.se/program|
21 tv6play\.se/program|
22 tv8play\.se/program|
23 tv10play\.se/program|
24 tv3play\.no/programmer|
25 viasat4play\.no/programmer|
26 tv6play\.no/programmer|
27 tv3play\.dk/programmer|
28 )/[^/]+/(?P<id>\d+)
29 '''
30 _TESTS = [
31 {
32 'url': 'http://www.tvplay.lv/parraides/vinas-melo-labak/418113?autostart=true',
33 'info_dict': {
34 'id': '418113',
35 'ext': 'flv',
36 'title': 'Kādi ir īri? - Viņas melo labāk',
37 'description': 'Baiba apsmej īrus, kādi tie ir un ko viņi dara.',
38 'duration': 25,
39 'timestamp': 1406097056,
40 'upload_date': '20140723',
41 },
42 'params': {
43 # rtmp download
44 'skip_download': True,
45 },
46 },
47 {
48 'url': 'http://www.tv3play.lt/programos/moterys-meluoja-geriau/409229?autostart=true',
49 'info_dict': {
50 'id': '409229',
51 'ext': 'flv',
52 'title': 'Moterys meluoja geriau',
53 'description': 'md5:9aec0fc68e2cbc992d2a140bd41fa89e',
54 'duration': 1330,
55 'timestamp': 1403769181,
56 'upload_date': '20140626',
57 },
58 'params': {
59 # rtmp download
60 'skip_download': True,
61 },
62 },
63 {
64 'url': 'http://www.tv3play.ee/sisu/kodu-keset-linna/238551?autostart=true',
65 'info_dict': {
66 'id': '238551',
67 'ext': 'flv',
68 'title': 'Kodu keset linna 398537',
69 'description': 'md5:7df175e3c94db9e47c0d81ffa5d68701',
70 'duration': 1257,
71 'timestamp': 1292449761,
72 'upload_date': '20101215',
73 },
74 'params': {
75 # rtmp download
76 'skip_download': True,
77 },
78 },
79 {
80 'url': 'http://www.tv3play.se/program/husraddarna/395385?autostart=true',
81 'info_dict': {
82 'id': '395385',
83 'ext': 'flv',
84 'title': 'Husräddarna S02E07',
85 'description': 'md5:f210c6c89f42d4fc39faa551be813777',
86 'duration': 2574,
87 'timestamp': 1400596321,
88 'upload_date': '20140520',
89 },
90 'params': {
91 # rtmp download
92 'skip_download': True,
93 },
94 },
95 {
96 'url': 'http://www.tv6play.se/program/den-sista-dokusapan/266636?autostart=true',
97 'info_dict': {
98 'id': '266636',
99 'ext': 'flv',
100 'title': 'Den sista dokusåpan S01E08',
101 'description': 'md5:295be39c872520221b933830f660b110',
102 'duration': 1492,
103 'timestamp': 1330522854,
104 'upload_date': '20120229',
105 },
106 'params': {
107 # rtmp download
108 'skip_download': True,
109 },
110 },
111 {
112 'url': 'http://www.tv8play.se/program/antikjakten/282756?autostart=true',
113 'info_dict': {
114 'id': '282756',
115 'ext': 'flv',
116 'title': 'Antikjakten S01E10',
117 'description': 'md5:1b201169beabd97e20c5ad0ad67b13b8',
118 'duration': 2646,
119 'timestamp': 1348575868,
120 'upload_date': '20120925',
121 },
122 'params': {
123 # rtmp download
124 'skip_download': True,
125 },
126 },
127 {
128 'url': 'http://www.tv3play.no/programmer/anna-anka-soker-assistent/230898?autostart=true',
129 'info_dict': {
130 'id': '230898',
131 'ext': 'flv',
132 'title': 'Anna Anka søker assistent - Ep. 8',
133 'description': 'md5:f80916bf5bbe1c5f760d127f8dd71474',
134 'duration': 2656,
135 'timestamp': 1277720005,
136 'upload_date': '20100628',
137 },
138 'params': {
139 # rtmp download
140 'skip_download': True,
141 },
142 },
143 {
144 'url': 'http://www.viasat4play.no/programmer/budbringerne/21873?autostart=true',
145 'info_dict': {
146 'id': '21873',
147 'ext': 'flv',
148 'title': 'Budbringerne program 10',
149 'description': 'md5:4db78dc4ec8a85bb04fd322a3ee5092d',
150 'duration': 1297,
151 'timestamp': 1254205102,
152 'upload_date': '20090929',
153 },
154 'params': {
155 # rtmp download
156 'skip_download': True,
157 },
158 },
159 {
160 'url': 'http://www.tv6play.no/programmer/hotelinspektor-alex-polizzi/361883?autostart=true',
161 'info_dict': {
162 'id': '361883',
163 'ext': 'flv',
164 'title': 'Hotelinspektør Alex Polizzi - Ep. 10',
165 'description': 'md5:3ecf808db9ec96c862c8ecb3a7fdaf81',
166 'duration': 2594,
167 'timestamp': 1393236292,
168 'upload_date': '20140224',
169 },
170 'params': {
171 # rtmp download
172 'skip_download': True,
173 },
174 },
175 ]
176
177 def _real_extract(self, url):
178 video_id = self._match_id(url)
179
180 video = self._download_json(
181 'http://playapi.mtgx.tv/v1/videos/%s' % video_id, video_id, 'Downloading video JSON')
182
183 if video['is_geo_blocked']:
184 self.report_warning(
185 'This content might not be available in your country due to copyright reasons')
186
187 streams = self._download_json(
188 'http://playapi.mtgx.tv/v1/videos/stream/%s' % video_id, video_id, 'Downloading streams JSON')
189
190 quality = qualities(['hls', 'medium', 'high'])
191 formats = []
192 for format_id, video_url in streams['streams'].items():
193 if not video_url or not isinstance(video_url, compat_str):
194 continue
195 fmt = {
196 'format_id': format_id,
197 'preference': quality(format_id),
198 }
199 if video_url.startswith('rtmp'):
200 m = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url)
201 if not m:
202 continue
203 fmt.update({
204 'ext': 'flv',
205 'url': m.group('url'),
206 'app': m.group('app'),
207 'play_path': m.group('playpath'),
208 })
209 elif video_url.endswith('.f4m'):
210 formats.extend(self._extract_f4m_formats(
211 video_url + '?hdcore=3.5.0&plugin=aasp-3.5.0.151.81', video_id))
212 continue
213 else:
214 fmt.update({
215 'url': video_url,
216 })
217 formats.append(fmt)
218
219 self._sort_formats(formats)
220
221 return {
222 'id': video_id,
223 'title': video['title'],
224 'description': video['description'],
225 'duration': video['duration'],
226 'timestamp': parse_iso8601(video['created_at']),
227 'view_count': video['views']['total'],
228 'age_limit': video.get('age_limit', 0),
229 'formats': formats,
230 }