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