]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/mitele.py
fix increment operator
[yt-dlp.git] / 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 get_element_by_attribute,
10 parse_duration,
11 strip_jsonp,
12 )
13
14
15 class MiTeleIE(InfoExtractor):
16 IE_NAME = 'mitele.es'
17 _VALID_URL = r'http://www\.mitele\.es/[^/]+/[^/]+/[^/]+/(?P<episode>[^/]+)/'
18
19 _TEST = {
20 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
21 'md5': '6a75fe9d0d3275bead0cb683c616fddb',
22 'info_dict': {
23 'id': '0fce117d',
24 'ext': 'mp4',
25 'title': 'Programa 144 - Tor, la web invisible',
26 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
27 'display_id': 'programa-144',
28 'duration': 2913,
29 },
30 }
31
32 def _real_extract(self, url):
33 mobj = re.match(self._VALID_URL, url)
34 episode = mobj.group('episode')
35 webpage = self._download_webpage(url, episode)
36 embed_data_json = self._search_regex(
37 r'MSV\.embedData\[.*?\]\s*=\s*({.*?});', webpage, 'embed data',
38 flags=re.DOTALL
39 ).replace('\'', '"')
40 embed_data = json.loads(embed_data_json)
41
42 info_url = embed_data['flashvars']['host']
43 info_el = self._download_xml(info_url, episode).find('./video/info')
44
45 video_link = info_el.find('videoUrl/link').text
46 token_query = compat_urllib_parse.urlencode({'id': video_link})
47 token_info = self._download_json(
48 'http://token.mitele.es/?' + token_query, episode,
49 transform_source=strip_jsonp
50 )
51
52 return {
53 'id': embed_data['videoId'],
54 'display_id': episode,
55 'title': info_el.find('title').text,
56 'url': token_info['tokenizedUrl'],
57 'description': get_element_by_attribute('class', 'text', webpage),
58 'thumbnail': info_el.find('thumb').text,
59 'duration': parse_duration(info_el.find('duration').text),
60 }