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