]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mitele.py
Imported Upstream version 2015.06.04.1
[youtubedl] / youtube_dl / extractor / mitele.py
1 from __future__ import unicode_literals
2
3 import json
4
5 from .common import InfoExtractor
6 from ..compat import (
7 compat_urllib_parse,
8 compat_urlparse,
9 )
10 from ..utils import (
11 get_element_by_attribute,
12 parse_duration,
13 strip_jsonp,
14 )
15
16
17 class MiTeleIE(InfoExtractor):
18 IE_NAME = 'mitele.es'
19 _VALID_URL = r'http://www\.mitele\.es/[^/]+/[^/]+/[^/]+/(?P<id>[^/]+)/'
20
21 _TESTS = [{
22 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
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 'params': {
32 # m3u8 download
33 'skip_download': True,
34 },
35 }]
36
37 def _real_extract(self, url):
38 episode = self._match_id(url)
39 webpage = self._download_webpage(url, episode)
40 embed_data_json = self._search_regex(
41 r'(?s)MSV\.embedData\[.*?\]\s*=\s*({.*?});', webpage, 'embed data',
42 ).replace('\'', '"')
43 embed_data = json.loads(embed_data_json)
44
45 domain = embed_data['mediaUrl']
46 if not domain.startswith('http'):
47 # only happens in telecinco.es videos
48 domain = 'http://' + domain
49 info_url = compat_urlparse.urljoin(
50 domain,
51 compat_urllib_parse.unquote(embed_data['flashvars']['host'])
52 )
53 info_el = self._download_xml(info_url, episode).find('./video/info')
54
55 video_link = info_el.find('videoUrl/link').text
56 token_query = compat_urllib_parse.urlencode({'id': video_link})
57 token_info = self._download_json(
58 embed_data['flashvars']['ov_tk'] + '?' + token_query,
59 episode,
60 transform_source=strip_jsonp
61 )
62 formats = self._extract_m3u8_formats(
63 token_info['tokenizedUrl'], episode, ext='mp4')
64
65 return {
66 'id': embed_data['videoId'],
67 'display_id': episode,
68 'title': info_el.find('title').text,
69 'formats': formats,
70 'description': get_element_by_attribute('class', 'text', webpage),
71 'thumbnail': info_el.find('thumb').text,
72 'duration': parse_duration(info_el.find('duration').text),
73 }