]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mitele.py
Prepare for upload.
[youtubedl] / youtube_dl / extractor / mitele.py
1 from __future__ import unicode_literals
2
3 import re
4 import json
5
6 from .common import InfoExtractor
7 from ..utils import (
8 compat_urllib_parse,
9 compat_urlparse,
10 get_element_by_attribute,
11 parse_duration,
12 strip_jsonp,
13 )
14
15
16 class MiTeleIE(InfoExtractor):
17 IE_NAME = 'mitele.es'
18 _VALID_URL = r'http://www\.mitele\.es/[^/]+/[^/]+/[^/]+/(?P<episode>[^/]+)/'
19
20 _TEST = {
21 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
22 'md5': '6a75fe9d0d3275bead0cb683c616fddb',
23 'info_dict': {
24 'id': '0fce117d',
25 'ext': 'mp4',
26 'title': 'Programa 144 - Tor, la web invisible',
27 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
28 'display_id': 'programa-144',
29 'duration': 2913,
30 },
31 }
32
33 def _real_extract(self, url):
34 mobj = re.match(self._VALID_URL, url)
35 episode = mobj.group('episode')
36 webpage = self._download_webpage(url, episode)
37 embed_data_json = self._search_regex(
38 r'MSV\.embedData\[.*?\]\s*=\s*({.*?});', webpage, 'embed data',
39 flags=re.DOTALL
40 ).replace('\'', '"')
41 embed_data = json.loads(embed_data_json)
42
43 domain = embed_data['mediaUrl']
44 if not domain.startswith('http'):
45 # only happens in telecinco.es videos
46 domain = 'http://' + domain
47 info_url = compat_urlparse.urljoin(
48 domain,
49 compat_urllib_parse.unquote(embed_data['flashvars']['host'])
50 )
51 info_el = self._download_xml(info_url, episode).find('./video/info')
52
53 video_link = info_el.find('videoUrl/link').text
54 token_query = compat_urllib_parse.urlencode({'id': video_link})
55 token_info = self._download_json(
56 embed_data['flashvars']['ov_tk'] + '?' + token_query,
57 episode,
58 transform_source=strip_jsonp
59 )
60
61 return {
62 'id': embed_data['videoId'],
63 'display_id': episode,
64 'title': info_el.find('title').text,
65 'url': token_info['tokenizedUrl'],
66 'description': get_element_by_attribute('class', 'text', webpage),
67 'thumbnail': info_el.find('thumb').text,
68 'duration': parse_duration(info_el.find('duration').text),
69 }