]> jfr.im git - yt-dlp.git/blob - youtube_dlc/extractor/mitele.py
Merge branch 'feature_subscriber_count' of https://github.com/RedpointsBots/youtube...
[yt-dlp.git] / youtube_dlc / extractor / mitele.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3 import json
4
5 from .common import InfoExtractor
6 from ..utils import (
7 int_or_none,
8 parse_iso8601,
9 smuggle_url,
10 )
11
12
13 class MiTeleIE(InfoExtractor):
14 IE_DESC = 'mitele.es'
15 _VALID_URL = r'https?://(?:www\.)?mitele\.es/(?:[^/]+/)+(?P<id>[^/]+)/player'
16
17 _TESTS = [{
18 'url': 'http://www.mitele.es/programas-tv/diario-de/57b0dfb9c715da65618b4afa/player',
19 'info_dict': {
20 'id': 'FhYW1iNTE6J6H7NkQRIEzfne6t2quqPg',
21 'ext': 'mp4',
22 'title': 'Diario de La redacción Programa 144',
23 'description': 'md5:07c35a7b11abb05876a6a79185b58d27',
24 'series': 'Diario de',
25 'season': 'Season 14',
26 'season_number': 14,
27 'episode': 'Tor, la web invisible',
28 'episode_number': 3,
29 'thumbnail': r're:(?i)^https?://.*\.jpg$',
30 'duration': 2913,
31 'age_limit': 16,
32 'timestamp': 1471209401,
33 'upload_date': '20160814',
34 },
35 }, {
36 # no explicit title
37 'url': 'http://www.mitele.es/programas-tv/cuarto-milenio/57b0de3dc915da14058b4876/player',
38 'info_dict': {
39 'id': 'oyNG1iNTE6TAPP-JmCjbwfwJqqMMX3Vq',
40 'ext': 'mp4',
41 'title': 'Cuarto Milenio Temporada 6 Programa 226',
42 'description': 'md5:5ff132013f0cd968ffbf1f5f3538a65f',
43 'series': 'Cuarto Milenio',
44 'season': 'Season 6',
45 'season_number': 6,
46 'episode': 'Episode 24',
47 'episode_number': 24,
48 'thumbnail': r're:(?i)^https?://.*\.jpg$',
49 'duration': 7313,
50 'age_limit': 12,
51 'timestamp': 1471209021,
52 'upload_date': '20160814',
53 },
54 'params': {
55 'skip_download': True,
56 }
57 }, {
58 'url': 'http://www.mitele.es/series-online/la-que-se-avecina/57aac5c1c915da951a8b45ed/player',
59 'only_matching': True,
60 }, {
61 'url': 'https://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144-40_1006364575251/player/',
62 'only_matching': True,
63 }]
64
65 def _real_extract(self, url):
66 display_id = self._match_id(url)
67 webpage = self._download_webpage(url, display_id)
68 pre_player = self._parse_json(self._search_regex(
69 r'window\.\$REACTBASE_STATE\.prePlayer_mtweb\s*=\s*({.+})',
70 webpage, 'Pre Player'), display_id)['prePlayer']
71 title = pre_player['title']
72 video = pre_player['video']
73 video_id = video['dataMediaId']
74 content = pre_player.get('content') or {}
75 info = content.get('info') or {}
76
77 info = {
78 'id': video_id,
79 'title': title,
80 'description': info.get('synopsis'),
81 'series': content.get('title'),
82 'season_number': int_or_none(info.get('season_number')),
83 'episode': content.get('subtitle'),
84 'episode_number': int_or_none(info.get('episode_number')),
85 'duration': int_or_none(info.get('duration')),
86 'thumbnail': video.get('dataPoster'),
87 'age_limit': int_or_none(info.get('rating')),
88 'timestamp': parse_iso8601(pre_player.get('publishedTime')),
89 }
90
91 if video.get('dataCmsId') == 'ooyala':
92 info.update({
93 '_type': 'url_transparent',
94 # for some reason only HLS is supported
95 'url': smuggle_url('ooyala:' + video_id, {'supportedformats': 'm3u8,dash'}),
96 })
97 else:
98 config = self._download_json(
99 video['dataConfig'], video_id, 'Downloading config JSON')
100 services = config['services']
101 gbx = self._download_json(
102 services['gbx'], video_id, 'Downloading gbx JSON')
103 caronte = self._download_json(
104 services['caronte'], video_id, 'Downloading caronte JSON')
105 cerbero = self._download_json(
106 caronte['cerbero'], video_id, 'Downloading cerbero JSON',
107 headers={
108 'Content-Type': 'application/json;charset=UTF-8',
109 'Origin': 'https://www.mitele.es'
110 },
111 data=json.dumps({
112 'bbx': caronte['bbx'],
113 'gbx': gbx['gbx']
114 }).encode('utf-8'))
115 formats = self._extract_m3u8_formats(
116 caronte['dls'][0]['stream'], video_id, 'mp4', 'm3u8_native', m3u8_id='hls',
117 query=dict([cerbero['tokens']['1']['cdn'].split('=', 1)]))
118 info['formats'] = formats
119
120 return info