]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/angel.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / angel.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import merge_dicts, url_or_none
5
6
7 class AngelIE(InfoExtractor):
8 _VALID_URL = r'https?://(?:www\.)?angel\.com/watch/(?P<series>[^/?#]+)/episode/(?P<id>[\w-]+)/season-(?P<season_number>\d+)/episode-(?P<episode_number>\d+)/(?P<title>[^/?#]+)'
9 _TESTS = [{
10 'url': 'https://www.angel.com/watch/tuttle-twins/episode/2f3d0382-ea82-4cdc-958e-84fbadadc710/season-1/episode-1/when-laws-give-you-lemons',
11 'md5': '4734e5cfdd64a568e837246aa3eaa524',
12 'info_dict': {
13 'id': '2f3d0382-ea82-4cdc-958e-84fbadadc710',
14 'ext': 'mp4',
15 'title': 'Tuttle Twins Season 1, Episode 1: When Laws Give You Lemons',
16 'description': 'md5:73b704897c20ab59c433a9c0a8202d5e',
17 'thumbnail': r're:^https?://images.angelstudios.com/image/upload/angel-app/.*$',
18 'duration': 1359.0
19 }
20 }, {
21 'url': 'https://www.angel.com/watch/the-chosen/episode/8dfb714d-bca5-4812-8125-24fb9514cd10/season-1/episode-1/i-have-called-you-by-name',
22 'md5': 'e4774bad0a5f0ad2e90d175cafdb797d',
23 'info_dict': {
24 'id': '8dfb714d-bca5-4812-8125-24fb9514cd10',
25 'ext': 'mp4',
26 'title': 'The Chosen Season 1, Episode 1: I Have Called You By Name',
27 'description': 'md5:aadfb4827a94415de5ff6426e6dee3be',
28 'thumbnail': r're:^https?://images.angelstudios.com/image/upload/angel-app/.*$',
29 'duration': 3276.0
30 }
31 }]
32
33 def _real_extract(self, url):
34 video_id = self._match_id(url)
35 webpage = self._download_webpage(url, video_id)
36
37 json_ld = self._search_json_ld(webpage, video_id)
38
39 formats, subtitles = self._extract_m3u8_formats_and_subtitles(
40 json_ld.pop('url'), video_id, note='Downloading HD m3u8 information')
41
42 info_dict = {
43 'id': video_id,
44 'title': self._og_search_title(webpage),
45 'description': self._og_search_description(webpage),
46 'formats': formats,
47 'subtitles': subtitles
48 }
49
50 # Angel uses cloudinary in the background and supports image transformations.
51 # We remove these transformations and return the source file
52 base_thumbnail_url = url_or_none(self._og_search_thumbnail(webpage)) or json_ld.pop('thumbnails')
53 if base_thumbnail_url:
54 info_dict['thumbnail'] = re.sub(r'(/upload)/.+(/angel-app/.+)$', r'\1\2', base_thumbnail_url)
55
56 return merge_dicts(info_dict, json_ld)