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