]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/nuevo.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / nuevo.py
1 from .common import InfoExtractor
2 from ..utils import float_or_none, xpath_text
3
4
5 class NuevoBaseIE(InfoExtractor):
6 def _extract_nuevo(self, config_url, video_id, headers={}):
7 config = self._download_xml(
8 config_url, video_id, transform_source=lambda s: s.strip(),
9 headers=headers)
10
11 title = xpath_text(config, './title', 'title', fatal=True).strip()
12 video_id = xpath_text(config, './mediaid', default=video_id)
13 thumbnail = xpath_text(config, ['./image', './thumb'])
14 duration = float_or_none(xpath_text(config, './duration'))
15
16 formats = []
17 for element_name, format_id in (('file', 'sd'), ('filehd', 'hd')):
18 video_url = xpath_text(config, element_name)
19 if video_url:
20 formats.append({
21 'url': video_url,
22 'format_id': format_id,
23 })
24 self._check_formats(formats, video_id)
25
26 return {
27 'id': video_id,
28 'title': title,
29 'thumbnail': thumbnail,
30 'duration': duration,
31 'formats': formats
32 }