]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/tele13.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / tele13.py
CommitLineData
8b55cadc 1from .common import InfoExtractor
6882c087 2from .youtube import YoutubeIE
3from ..utils import (
e897bd82 4 determine_ext,
6882c087 5 js_to_json,
6 qualities,
6882c087 7)
8b55cadc 8
9
10class Tele13IE(InfoExtractor):
5886b38d 11 _VALID_URL = r'^https?://(?:www\.)?t13\.cl/videos(?:/[^/]+)+/(?P<id>[\w-]+)'
8b55cadc 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',
436416af 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 },
8b55cadc 25 },
26 {
27 'url': 'http://www.t13.cl/videos/mundo/tendencias/video-captan-misteriosa-bola-fuego-cielos-bangkok',
6882c087 28 'md5': '867adf6a3b3fef932c68a71d70b70946',
8b55cadc 29 'info_dict': {
30 'id': 'rOoKv2OMpOw',
31 'ext': 'mp4',
32 'title': 'Shooting star seen on 7-Sep-2015',
6882c087 33 'description': 'md5:7292ff2a34b2f673da77da222ae77e1e',
8b55cadc 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)
8b55cadc 44 webpage = self._download_webpage(url, display_id)
45
98d7c0f4 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)
8b55cadc 52
6882c087 53 preference = qualities(['Móvil', 'SD', 'HD'])
8b55cadc 54 formats = []
6882c087 55 urls = []
56 for f in sources:
8b55cadc 57 format_url = f['file']
6882c087 58 if format_url and format_url not in urls:
59 ext = determine_ext(format_url)
60 if ext == 'm3u8':
98d7c0f4 61 formats.extend(self._extract_m3u8_formats(
62 format_url, display_id, 'mp4', 'm3u8_native',
63 m3u8_id='hls', fatal=False))
6882c087 64 elif YoutubeIE.suitable(format_url):
65 return self.url_result(format_url, 'Youtube')
8b55cadc 66 else:
6882c087 67 formats.append({
68 'url': format_url,
69 'format_id': f.get('label'),
f983b875 70 'quality': preference(f.get('label')),
6882c087 71 'ext': ext,
72 })
73 urls.append(format_url)
8b55cadc 74
75 return {
76 'id': display_id,
98d7c0f4 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),
8b55cadc 83 'formats': formats,
84 }