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