]> git.bitcoin.ninja Git - youtube-dl/blob - tutv.py
4e404fbf5912fd32b695c701466309a38179e799
[youtube-dl] / tutv.py
1 import base64
2 import re
3
4 from .common import InfoExtractor
5 from ..utils import (
6     compat_parse_qs,
7 )
8
9 class TutvIE(InfoExtractor):
10     _VALID_URL=r'https?://(?:www\.)?tu\.tv/videos/(?P<id>[^/?]+)'
11     _TEST = {
12         u'url': u'http://tu.tv/videos/noah-en-pabellon-cuahutemoc',
13         u'file': u'2742556.flv',
14         u'md5': u'5eb766671f69b82e528dc1e7769c5cb2',
15         u'info_dict': {
16             u"title": u"Noah en pabellon cuahutemoc"
17         }
18     }
19
20     def _real_extract(self, url):
21         mobj = re.match(self._VALID_URL, url)
22         video_id = mobj.group('id')
23
24         webpage = self._download_webpage(url, video_id)
25         internal_id = self._search_regex(r'codVideo=([0-9]+)', webpage, u'internal video ID')
26
27         data_url = u'http://tu.tv/flvurl.php?codVideo=' + str(internal_id)
28         data_content = self._download_webpage(data_url, video_id, note=u'Downloading video info')
29         data = compat_parse_qs(data_content)
30         video_url = base64.b64decode(data['kpt'][0]).decode('utf-8')
31         ext = video_url.partition(u'?')[0].rpartition(u'.')[2]
32
33         info = {
34             'id': internal_id,
35             'url': video_url,
36             'ext': ext,
37             'title': self._og_search_title(webpage),
38         }
39         return [info]