]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/iprima.py
Imported Upstream version 2014.02.17
[youtubedl] / 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 compat_urllib_request
10
11
12 class IPrimaIE(InfoExtractor):
13 _VALID_URL = r'https?://play\.iprima\.cz/(?P<videogroup>.+)/(?P<videoid>.+)'
14
15 _TESTS = [{
16 'url': 'http://play.iprima.cz/particka/particka-92',
17 'info_dict': {
18 'id': '39152',
19 'ext': 'flv',
20 'title': 'Partička (92)',
21 'description': 'md5:3740fda51464da35a2d4d0670b8e4fd6',
22 'thumbnail': 'http://play.iprima.cz/sites/default/files/image_crops/image_620x349/3/491483_particka-92_image_620x349.jpg',
23 },
24 'params': {
25 'skip_download': True,
26 },
27 },
28 ]
29
30 def _real_extract(self, url):
31 mobj = re.match(self._VALID_URL, url)
32 video_id = mobj.group('videoid')
33
34 webpage = self._download_webpage(url, video_id)
35
36 player_url = 'http://embed.livebox.cz/iprimaplay/player-embed-v2.js?__tok%s__=%s' % (
37 floor(random()*1073741824),
38 floor(random()*1073741824))
39
40 req = compat_urllib_request.Request(player_url)
41 req.add_header('Referer', url)
42 playerpage = self._download_webpage(req, video_id)
43
44 base_url = ''.join(re.findall(r"embed\['stream'\] = '(.+?)'.+'(\?auth=)'.+'(.+?)';", playerpage)[1])
45
46 zoneGEO = self._html_search_regex(r'"zoneGEO":(.+?),', webpage, 'zoneGEO')
47
48 if zoneGEO != '0':
49 base_url = base_url.replace('token', 'token_'+zoneGEO)
50
51 formats = []
52 for format_id in ['lq', 'hq', 'hd']:
53 filename = self._html_search_regex(r'"%s_id":(.+?),' % format_id, webpage, 'filename')
54
55 if filename == 'null':
56 continue
57
58 real_id = self._search_regex(r'Prima-[0-9]{10}-([0-9]+)_', filename, 'real video id')
59
60 if format_id == 'lq':
61 quality = 0
62 elif format_id == 'hq':
63 quality = 1
64 elif format_id == 'hd':
65 quality = 2
66 filename = 'hq/'+filename
67
68 formats.append({
69 'format_id': format_id,
70 'url': base_url,
71 'quality': quality,
72 'play_path': 'mp4:'+filename.replace('"', '')[:-4],
73 'rtmp_live': True,
74 'ext': 'flv',
75 })
76
77 self._sort_formats(formats)
78
79 return {
80 'id': real_id,
81 'title': self._og_search_title(webpage),
82 'thumbnail': self._og_search_thumbnail(webpage),
83 'formats': formats,
84 'description': self._og_search_description(webpage),
85 }