]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/tele13.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / tele13.py
1 from .common import InfoExtractor
2 from .youtube import YoutubeIE
3 from ..utils import (
4 determine_ext,
5 js_to_json,
6 qualities,
7 )
8
9
10 class Tele13IE(InfoExtractor):
11 _VALID_URL = r'^https?://(?:www\.)?t13\.cl/videos(?:/[^/]+)+/(?P<id>[\w-]+)'
12 _TESTS = [
13 {
14 'url': 'http://www.t13.cl/videos/actualidad/el-circulo-de-hierro-de-michelle-bachelet-en-su-regreso-a-la-moneda',
15 'md5': '4cb1fa38adcad8fea88487a078831755',
16 'info_dict': {
17 'id': 'el-circulo-de-hierro-de-michelle-bachelet-en-su-regreso-a-la-moneda',
18 'ext': 'mp4',
19 'title': 'El círculo de hierro de Michelle Bachelet en su regreso a La Moneda',
20 },
21 'params': {
22 # HTTP Error 404: Not Found
23 'skip_download': True,
24 },
25 },
26 {
27 'url': 'http://www.t13.cl/videos/mundo/tendencias/video-captan-misteriosa-bola-fuego-cielos-bangkok',
28 'md5': '867adf6a3b3fef932c68a71d70b70946',
29 'info_dict': {
30 'id': 'rOoKv2OMpOw',
31 'ext': 'mp4',
32 'title': 'Shooting star seen on 7-Sep-2015',
33 'description': 'md5:7292ff2a34b2f673da77da222ae77e1e',
34 'uploader': 'Porjai Jaturongkhakun',
35 'upload_date': '20150906',
36 'uploader_id': 'UCnLY_3ezwNcDSC_Wc6suZxw',
37 },
38 'add_ie': ['Youtube'],
39 }
40 ]
41
42 def _real_extract(self, url):
43 display_id = self._match_id(url)
44 webpage = self._download_webpage(url, display_id)
45
46 setup_js = self._search_regex(
47 r"(?s)jwplayer\('player-vivo'\).setup\((\{.*?\})\)",
48 webpage, 'setup code')
49 sources = self._parse_json(self._search_regex(
50 r'sources\s*:\s*(\[[^\]]+\])', setup_js, 'sources'),
51 display_id, js_to_json)
52
53 preference = qualities(['Móvil', 'SD', 'HD'])
54 formats = []
55 urls = []
56 for f in sources:
57 format_url = f['file']
58 if format_url and format_url not in urls:
59 ext = determine_ext(format_url)
60 if ext == 'm3u8':
61 formats.extend(self._extract_m3u8_formats(
62 format_url, display_id, 'mp4', 'm3u8_native',
63 m3u8_id='hls', fatal=False))
64 elif YoutubeIE.suitable(format_url):
65 return self.url_result(format_url, 'Youtube')
66 else:
67 formats.append({
68 'url': format_url,
69 'format_id': f.get('label'),
70 'quality': preference(f.get('label')),
71 'ext': ext,
72 })
73 urls.append(format_url)
74
75 return {
76 'id': display_id,
77 'title': self._search_regex(
78 r'title\s*:\s*"([^"]+)"', setup_js, 'title'),
79 'description': self._html_search_meta(
80 'description', webpage, 'description'),
81 'thumbnail': self._search_regex(
82 r'image\s*:\s*"([^"]+)"', setup_js, 'thumbnail', default=None),
83 'formats': formats,
84 }