]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/laola1tv.py
[SpankBang] Use python2.6 compatible string formatting spec
[youtube-dl] / youtube_dl / extractor / laola1tv.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import random
5 import re
6
7 from .common import InfoExtractor
8 from ..utils import (
9     ExtractorError,
10     xpath_text,
11 )
12
13
14 class Laola1TvIE(InfoExtractor):
15     _VALID_URL = r'https?://(?:www\.)?laola1\.tv/(?P<lang>[a-z]+)-(?P<portal>[a-z]+)/.*?/(?P<id>[0-9]+)\.html'
16     _TEST = {
17         'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie/227883.html',
18         'info_dict': {
19             'id': '227883',
20             'ext': 'mp4',
21             'title': 'Straubing Tigers - Kölner Haie',
22             'categories': ['Eishockey'],
23             'is_live': False,
24         },
25         'params': {
26             'skip_download': True,
27         }
28     }
29
30     def _real_extract(self, url):
31         mobj = re.match(self._VALID_URL, url)
32         video_id = mobj.group('id')
33         lang = mobj.group('lang')
34         portal = mobj.group('portal')
35
36         webpage = self._download_webpage(url, video_id)
37         iframe_url = self._search_regex(
38             r'<iframe[^>]*?class="main_tv_player"[^>]*?src="([^"]+)"',
39             webpage, 'iframe URL')
40
41         iframe = self._download_webpage(
42             iframe_url, video_id, note='Downloading iframe')
43         flashvars_m = re.findall(
44             r'flashvars\.([_a-zA-Z0-9]+)\s*=\s*"([^"]*)";', iframe)
45         flashvars = dict((m[0], m[1]) for m in flashvars_m)
46
47         partner_id = self._search_regex(
48             r'partnerid\s*:\s*"([^"]+)"', iframe, 'partner id')
49
50         xml_url = ('http://www.laola1.tv/server/hd_video.php?' +
51                    'play=%s&partner=%s&portal=%s&v5ident=&lang=%s' % (
52                        video_id, partner_id, portal, lang))
53         hd_doc = self._download_xml(xml_url, video_id)
54
55         title = xpath_text(hd_doc, './/video/title', fatal=True)
56         flash_url = xpath_text(hd_doc, './/video/url', fatal=True)
57         uploader = xpath_text(hd_doc, './/video/meta_organistation')
58         is_live = xpath_text(hd_doc, './/video/islive') == 'true'
59
60         categories = xpath_text(hd_doc, './/video/meta_sports')
61         if categories:
62             categories = categories.split(',')
63
64         ident = random.randint(10000000, 99999999)
65         token_url = '%s&ident=%s&klub=0&unikey=0&timestamp=%s&auth=%s' % (
66             flash_url, ident, flashvars['timestamp'], flashvars['auth'])
67
68         token_doc = self._download_xml(
69             token_url, video_id, note='Downloading token')
70         token_attrib = token_doc.find('.//token').attrib
71         if token_attrib.get('auth') in ('blocked', 'restricted'):
72             raise ExtractorError(
73                 'Token error: %s' % token_attrib.get('comment'), expected=True)
74
75         video_url = '%s?hdnea=%s&hdcore=3.2.0' % (
76             token_attrib['url'], token_attrib['auth'])
77
78         return {
79             'id': video_id,
80             'is_live': is_live,
81             'title': title,
82             'url': video_url,
83             'uploader': uploader,
84             'categories': categories,
85             'ext': 'mp4',
86         }