]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/telemundo.py
[docs,cleanup] Improve docs and minor cleanup
[yt-dlp.git] / yt_dlp / extractor / telemundo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 try_get,
7 unified_timestamp,
8 HEADRequest,
9 )
10
11
12 class TelemundoIE(InfoExtractor):
13
14 _VALID_URL = r'https?:\/\/(?:www\.)?telemundo\.com\/.+?video\/[^\/]+(?P<id>tmvo\d{7})'
15 _TESTS = [{
16 'url': 'https://www.telemundo.com/noticias/noticias-telemundo-en-la-noche/empleo/video/esta-aplicacion-gratuita-esta-ayudando-los-latinos-encontrar-trabajo-en-estados-unidos-tmvo9829325',
17 'info_dict': {
18 'id': 'tmvo9829325',
19 'timestamp': 1621396800,
20 'title': 'Esta aplicación gratuita está ayudando a los latinos a encontrar trabajo en Estados Unidos',
21 'uploader': 'Telemundo',
22 'uploader_id': 'NBCU_Telemundo',
23 'ext': 'mp4',
24 'upload_date': '20210519',
25 },
26 'params': {
27 'skip_download': True,
28 }
29 }, {
30 'url': 'https://www.telemundo.com/shows/al-rojo-vivo/empleo/video/personajes-de-times-square-piden-que-la-ciudad-de-nueva-york-los-deje-volver-trabajar-tmvo9816272',
31 'only_matching': True,
32 }]
33
34 def _real_extract(self, url):
35 video_id = self._match_id(url)
36 webpage = self._download_webpage(url, video_id)
37 metadata = self._parse_json(
38 self._search_regex(r'<[^>]+id="__NEXT_DATA__"[^>]+>([^<]+)', webpage, 'JSON metadata'), video_id)
39 redirect_url = try_get(
40 metadata,
41 lambda x: x['props']['initialState']['video']['associatedPlaylists'][0]['videos'][0]['videoAssets'][0]['publicUrl'])
42
43 m3u8_url = self._request_webpage(HEADRequest(
44 redirect_url + '?format=redirect&manifest=m3u&format=redirect&Tracking=true&Embedded=true&formats=MPEG4'),
45 video_id, 'Processing m3u8').geturl()
46 formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
47 self._sort_formats(formats)
48 date = unified_timestamp(try_get(
49 metadata, lambda x: x['props']['initialState']['video']['associatedPlaylists'][0]['videos'][0]['datePublished'].split(' ', 1)[1]))
50 return {
51 'url': url,
52 'id': video_id,
53 'title': self._search_regex(r'<h1[^>]+>([^<]+)', webpage, 'title', fatal=False),
54 'formats': formats,
55 'timestamp': date,
56 'uploader': 'Telemundo',
57 'uploader_id': self._search_regex(r'https?:\/\/(?:[^/]+\/){3}video\/(?P<id>[^\/]+)', m3u8_url, 'Akamai account', fatal=False)
58 }