[ie/box] Fix formats extraction (#8649)
[yt-dlp3.git] / yt_dlp / extractor / wakanim.py
blob155008f8cb1faca7c4dc86a7def55271a136f1b8
1 from urllib.parse import unquote
3 from .common import InfoExtractor
4 from ..utils import (
5 merge_dicts,
6 urljoin,
10 class WakanimIE(InfoExtractor):
11 _VALID_URL = r'https://(?:www\.)?wakanim\.tv/[^/]+/v2/catalogue/episode/(?P<id>\d+)'
12 _TESTS = [{
13 'url': 'https://www.wakanim.tv/de/v2/catalogue/episode/2997/the-asterisk-war-omu-staffel-1-episode-02-omu',
14 'info_dict': {
15 'id': '2997',
16 'ext': 'mp4',
17 'title': 'Episode 02',
18 'description': 'md5:2927701ea2f7e901de8bfa8d39b2852d',
19 'series': 'The Asterisk War (OmU.)',
20 'season_number': 1,
21 'episode': 'Episode 02',
22 'episode_number': 2,
24 'params': {
25 'skip_download': True,
27 }, {
28 # DRM Protected
29 'url': 'https://www.wakanim.tv/de/v2/catalogue/episode/7843/sword-art-online-alicization-omu-arc-2-folge-15-omu',
30 'only_matching': True,
32 _GEO_BYPASS = False
34 def _real_extract(self, url):
35 video_id = self._match_id(url)
37 webpage = self._download_webpage(url, video_id)
39 if 'Geoblocking' in webpage:
40 if '/de/' in url:
41 self.raise_geo_restricted(countries=['DE', 'AT', 'CH'])
42 else:
43 self.raise_geo_restricted(countries=['RU'])
45 manifest_url = urljoin(url, self._search_regex(
46 r'file\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage, 'manifest url',
47 group='url'))
48 if not self.get_param('allow_unplayable_formats'):
49 # https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-content-protection-overview#streaming-urls
50 encryption = self._search_regex(
51 r'encryption%3D(c(?:enc|bc(?:s-aapl)?))',
52 manifest_url, 'encryption', default=None)
53 if encryption in ('cenc', 'cbcs-aapl'):
54 self.report_drm(video_id)
56 if 'format=mpd-time-cmaf' in unquote(manifest_url):
57 formats = self._extract_mpd_formats(
58 manifest_url, video_id, mpd_id='dash')
59 else:
60 formats = self._extract_m3u8_formats(
61 manifest_url, video_id, 'mp4', entry_protocol='m3u8_native',
62 m3u8_id='hls')
64 info = self._search_json_ld(webpage, video_id, default={})
66 title = self._search_regex(
67 (r'<h1[^>]+\bclass=["\']episode_h1[^>]+\btitle=(["\'])(?P<title>(?:(?!\1).)+)\1',
68 r'<span[^>]+\bclass=["\']episode_title["\'][^>]*>(?P<title>[^<]+)'),
69 webpage, 'title', default=None, group='title')
71 return merge_dicts(info, {
72 'id': video_id,
73 'title': title,
74 'formats': formats,