[iprima] Mark broken
[youtube-dl] / youtube_dl / extractor / iprima.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import re
5 from random import random
6 from math import floor
7
8 from .common import InfoExtractor
9 from ..utils import (
10     ExtractorError,
11     remove_end,
12     sanitized_Request,
13 )
14
15
16 class IPrimaIE(InfoExtractor):
17     _WORKING = False
18     _VALID_URL = r'https?://play\.iprima\.cz/(?:[^/]+/)*(?P<id>[^?#]+)'
19
20     _TESTS = [{
21         'url': 'http://play.iprima.cz/particka/particka-92',
22         'info_dict': {
23             'id': '39152',
24             'ext': 'flv',
25             'title': 'Partička (92)',
26             'description': 'md5:74e9617e51bca67c3ecfb2c6f9766f45',
27             'thumbnail': 'http://play.iprima.cz/sites/default/files/image_crops/image_620x349/3/491483_particka-92_image_620x349.jpg',
28         },
29         'params': {
30             'skip_download': True,  # requires rtmpdump
31         },
32     }, {
33         'url': 'http://play.iprima.cz/particka/tchibo-particka-jarni-moda',
34         'info_dict': {
35             'id': '9718337',
36             'ext': 'flv',
37             'title': 'Tchibo Partička - Jarní móda',
38             'thumbnail': 're:^http:.*\.jpg$',
39         },
40         'params': {
41             'skip_download': True,  # requires rtmpdump
42         },
43     }, {
44         'url': 'http://play.iprima.cz/zpravy-ftv-prima-2752015',
45         'only_matching': True,
46     }]
47
48     def _real_extract(self, url):
49         mobj = re.match(self._VALID_URL, url)
50         video_id = mobj.group('id')
51
52         webpage = self._download_webpage(url, video_id)
53
54         if re.search(r'Nemáte oprávnění přistupovat na tuto stránku\.\s*</div>', webpage):
55             raise ExtractorError(
56                 '%s said: You do not have permission to access this page' % self.IE_NAME, expected=True)
57
58         player_url = (
59             'http://embed.livebox.cz/iprimaplay/player-embed-v2.js?__tok%s__=%s' %
60             (floor(random() * 1073741824), floor(random() * 1073741824))
61         )
62
63         req = sanitized_Request(player_url)
64         req.add_header('Referer', url)
65         playerpage = self._download_webpage(req, video_id)
66
67         base_url = ''.join(re.findall(r"embed\['stream'\] = '(.+?)'.+'(\?auth=)'.+'(.+?)';", playerpage)[1])
68
69         zoneGEO = self._html_search_regex(r'"zoneGEO":(.+?),', webpage, 'zoneGEO')
70         if zoneGEO != '0':
71             base_url = base_url.replace('token', 'token_' + zoneGEO)
72
73         formats = []
74         for format_id in ['lq', 'hq', 'hd']:
75             filename = self._html_search_regex(
76                 r'"%s_id":(.+?),' % format_id, webpage, 'filename')
77
78             if filename == 'null':
79                 continue
80
81             real_id = self._search_regex(
82                 r'Prima-(?:[0-9]{10}|WEB)-([0-9]+)[-_]',
83                 filename, 'real video id')
84
85             if format_id == 'lq':
86                 quality = 0
87             elif format_id == 'hq':
88                 quality = 1
89             elif format_id == 'hd':
90                 quality = 2
91                 filename = 'hq/' + filename
92
93             formats.append({
94                 'format_id': format_id,
95                 'url': base_url,
96                 'quality': quality,
97                 'play_path': 'mp4:' + filename.replace('"', '')[:-4],
98                 'rtmp_live': True,
99                 'ext': 'flv',
100             })
101
102         self._sort_formats(formats)
103
104         return {
105             'id': real_id,
106             'title': remove_end(self._og_search_title(webpage), ' | Prima PLAY'),
107             'thumbnail': self._og_search_thumbnail(webpage),
108             'formats': formats,
109             'description': self._search_regex(
110                 r'<p[^>]+itemprop="description"[^>]*>([^<]+)',
111                 webpage, 'description', default=None),
112         }