]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/telemundo.py
Tolerate failure to `--write-link` due to unknown URL
[yt-dlp.git] / yt_dlp / extractor / telemundo.py
CommitLineData
0930b11f 1# coding: utf-8
13a49340 2from __future__ import unicode_literals
3
4from .common import InfoExtractor
5from ..utils import (
6 try_get,
7 unified_timestamp,
8 HEADRequest,
9)
10
11
12class 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)
135dfa2c 37 metadata = self._search_nextjs_data(webpage, video_id)
13a49340 38 redirect_url = try_get(
39 metadata,
40 lambda x: x['props']['initialState']['video']['associatedPlaylists'][0]['videos'][0]['videoAssets'][0]['publicUrl'])
41
42 m3u8_url = self._request_webpage(HEADRequest(
43 redirect_url + '?format=redirect&manifest=m3u&format=redirect&Tracking=true&Embedded=true&formats=MPEG4'),
44 video_id, 'Processing m3u8').geturl()
45 formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
46 self._sort_formats(formats)
47 date = unified_timestamp(try_get(
48 metadata, lambda x: x['props']['initialState']['video']['associatedPlaylists'][0]['videos'][0]['datePublished'].split(' ', 1)[1]))
49 return {
50 'url': url,
51 'id': video_id,
52 'title': self._search_regex(r'<h1[^>]+>([^<]+)', webpage, 'title', fatal=False),
53 'formats': formats,
54 'timestamp': date,
55 'uploader': 'Telemundo',
56 'uploader_id': self._search_regex(r'https?:\/\/(?:[^/]+\/){3}video\/(?P<id>[^\/]+)', m3u8_url, 'Akamai account', fatal=False)
57 }