]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/laola1tv.py
Prepare for upload.
[youtubedl] / youtube_dl / extractor / laola1tv.py
1 from __future__ import unicode_literals
2
3 import random
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import ExtractorError
8
9
10 class Laola1TvIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?laola1\.tv/(?P<lang>[a-z]+)-(?P<portal>[a-z]+)/.*?/(?P<id>[0-9]+)\.html'
12 _TEST = {
13 'url': 'http://www.laola1.tv/de-de/live/bwf-bitburger-open-grand-prix-gold-court-1/250019.html',
14 'info_dict': {
15 'id': '250019',
16 'ext': 'mp4',
17 'title': 'Bitburger Open Grand Prix Gold - Court 1',
18 'categories': ['Badminton'],
19 'uploader': 'BWF - Badminton World Federation',
20 'is_live': True,
21 },
22 'params': {
23 'skip_download': True,
24 }
25 }
26
27 _BROKEN = True # Not really - extractor works fine, but f4m downloader does not support live streams yet.
28
29 def _real_extract(self, url):
30 mobj = re.match(self._VALID_URL, url)
31 video_id = mobj.group('id')
32 lang = mobj.group('lang')
33 portal = mobj.group('portal')
34
35 webpage = self._download_webpage(url, video_id)
36 iframe_url = self._search_regex(
37 r'<iframe[^>]*?class="main_tv_player"[^>]*?src="([^"]+)"',
38 webpage, 'iframe URL')
39
40 iframe = self._download_webpage(
41 iframe_url, video_id, note='Downloading iframe')
42 flashvars_m = re.findall(
43 r'flashvars\.([_a-zA-Z0-9]+)\s*=\s*"([^"]*)";', iframe)
44 flashvars = dict((m[0], m[1]) for m in flashvars_m)
45
46 xml_url = ('http://www.laola1.tv/server/hd_video.php?' +
47 'play=%s&partner=1&portal=%s&v5ident=&lang=%s' % (
48 video_id, portal, lang))
49 hd_doc = self._download_xml(xml_url, video_id)
50
51 title = hd_doc.find('.//video/title').text
52 flash_url = hd_doc.find('.//video/url').text
53 categories = hd_doc.find('.//video/meta_sports').text.split(',')
54 uploader = hd_doc.find('.//video/meta_organistation').text
55
56 ident = random.randint(10000000, 99999999)
57 token_url = '%s&ident=%s&klub=0&unikey=0&timestamp=%s&auth=%s' % (
58 flash_url, ident, flashvars['timestamp'], flashvars['auth'])
59
60 token_doc = self._download_xml(
61 token_url, video_id, note='Downloading token')
62 token_attrib = token_doc.find('.//token').attrib
63 if token_attrib.get('auth') == 'blocked':
64 raise ExtractorError('Token error: ' % token_attrib.get('comment'))
65
66 video_url = '%s?hdnea=%s&hdcore=3.2.0' % (
67 token_attrib['url'], token_attrib['auth'])
68
69 return {
70 'id': video_id,
71 'is_live': True,
72 'title': title,
73 'url': video_url,
74 'uploader': uploader,
75 'categories': categories,
76 'ext': 'mp4',
77 }