]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/telemundo.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / telemundo.py
1 from .common import InfoExtractor
2 from ..utils import (
3 try_get,
4 unified_timestamp,
5 HEADRequest,
6 )
7
8
9 class TelemundoIE(InfoExtractor):
10
11 _VALID_URL = r'https?:\/\/(?:www\.)?telemundo\.com\/.+?video\/[^\/]+(?P<id>tmvo\d{7})'
12 _TESTS = [{
13 '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',
14 'info_dict': {
15 'id': 'tmvo9829325',
16 'timestamp': 1621396800,
17 'title': 'Esta aplicación gratuita está ayudando a los latinos a encontrar trabajo en Estados Unidos',
18 'uploader': 'Telemundo',
19 'uploader_id': 'NBCU_Telemundo',
20 'ext': 'mp4',
21 'upload_date': '20210519',
22 },
23 'params': {
24 'skip_download': True,
25 }
26 }, {
27 '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',
28 'only_matching': True,
29 }]
30
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33 webpage = self._download_webpage(url, video_id)
34 metadata = self._search_nextjs_data(webpage, video_id)
35 redirect_url = try_get(
36 metadata,
37 lambda x: x['props']['initialState']['video']['associatedPlaylists'][0]['videos'][0]['videoAssets'][0]['publicUrl'])
38
39 m3u8_url = self._request_webpage(HEADRequest(
40 redirect_url + '?format=redirect&manifest=m3u&format=redirect&Tracking=true&Embedded=true&formats=MPEG4'),
41 video_id, 'Processing m3u8').geturl()
42 formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
43 date = unified_timestamp(try_get(
44 metadata, lambda x: x['props']['initialState']['video']['associatedPlaylists'][0]['videos'][0]['datePublished'].split(' ', 1)[1]))
45 return {
46 'url': url,
47 'id': video_id,
48 'title': self._search_regex(r'<h1[^>]+>([^<]+)', webpage, 'title', fatal=False),
49 'formats': formats,
50 'timestamp': date,
51 'uploader': 'Telemundo',
52 'uploader_id': self._search_regex(r'https?:\/\/(?:[^/]+\/){3}video\/(?P<id>[^\/]+)', m3u8_url, 'Akamai account', fatal=False)
53 }