]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tutv.py
New test release.
[youtubedl] / youtube_dl / extractor / 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 title = self._html_search_regex(
26 r'<meta property="og:title" content="(.*?)">', webpage, u'title')
27 internal_id = self._search_regex(r'codVideo=([0-9]+)', webpage, u'internal video ID')
28
29 data_url = u'http://tu.tv/flvurl.php?codVideo=' + str(internal_id)
30 data_content = self._download_webpage(data_url, video_id, note=u'Downloading video info')
31 data = compat_parse_qs(data_content)
32 video_url = base64.b64decode(data['kpt'][0]).decode('utf-8')
33 ext = video_url.partition(u'?')[0].rpartition(u'.')[2]
34
35 info = {
36 'id': internal_id,
37 'url': video_url,
38 'ext': ext,
39 'title': title,
40 }
41 return [info]