[ie/youtube] Fix `uploader_id` extraction (#11818)
[yt-dlp.git] / yt_dlp / extractor / cineverse.py
blob124c874e2c734fde393192208add25a856c77338
1 import re
3 from .common import InfoExtractor
4 from ..utils import (
5 filter_dict,
6 float_or_none,
7 int_or_none,
8 parse_age_limit,
9 smuggle_url,
10 traverse_obj,
11 unsmuggle_url,
12 url_or_none,
16 class CineverseBaseIE(InfoExtractor):
17 _VALID_URL_BASE = r'https?://www\.(?P<host>{})'.format('|'.join(map(re.escape, (
18 'cineverse.com',
19 'asiancrush.com',
20 'dovechannel.com',
21 'screambox.com',
22 'midnightpulp.com',
23 'fandor.com',
24 'retrocrush.tv',
25 ))))
28 class CineverseIE(CineverseBaseIE):
29 _VALID_URL = rf'{CineverseBaseIE._VALID_URL_BASE}/watch/(?P<id>[A-Z0-9]+)'
30 _TESTS = [{
31 'url': 'https://www.asiancrush.com/watch/DMR00018919/Women-Who-Flirt',
32 'skip': 'geo-blocked',
33 'info_dict': {
34 'title': 'Women Who Flirt',
35 'ext': 'mp4',
36 'id': 'DMR00018919',
37 'modified_timestamp': 1678744575289,
38 'cast': ['Xun Zhou', 'Xiaoming Huang', 'Yi-Lin Sie', 'Sonia Sui', 'Quniciren'],
39 'duration': 5811.597,
40 'description': 'md5:892fd62a05611d394141e8394ace0bc6',
41 'age_limit': 13,
43 }, {
44 'url': 'https://www.retrocrush.tv/watch/1000000023016/Archenemy! Crystal Bowie',
45 'skip': 'geo-blocked',
46 'info_dict': {
47 'title': 'Archenemy! Crystal Bowie',
48 'ext': 'mp4',
49 'id': '1000000023016',
50 'episode_number': 3,
51 'season_number': 1,
52 'cast': ['Nachi Nozawa', 'Yoshiko Sakakibara', 'Toshiko Fujita'],
53 'age_limit': 0,
54 'episode': 'Episode 3',
55 'season': 'Season 1',
56 'duration': 1485.067,
57 'description': 'Cobra meets a beautiful bounty hunter by the name of Jane Royal.',
58 'series': 'Space Adventure COBRA (Original Japanese)',
62 def _real_extract(self, url):
63 url, smuggled_data = unsmuggle_url(url, default={})
64 self._initialize_geo_bypass({
65 'countries': smuggled_data.get('geo_countries'),
67 video_id = self._match_id(url)
68 html = self._download_webpage(url, video_id)
69 idetails = self._search_nextjs_data(html, video_id)['props']['pageProps']['idetails']
71 err_code = idetails.get('err_code')
72 if err_code == 1002:
73 self.raise_login_required()
74 elif err_code == 1200:
75 self.raise_geo_restricted(
76 'This video is not available from your location due to geo restriction. '
77 'You may be able to bypass it by using the /details/ page instead of the /watch/ page',
78 countries=smuggled_data.get('geo_countries'))
80 return {
81 'subtitles': filter_dict({
82 'en': traverse_obj(idetails, (('cc_url_vtt', 'subtitle_url'), {'url': {url_or_none}})) or None,
83 }),
84 'formats': self._extract_m3u8_formats(idetails['url'], video_id),
85 **traverse_obj(idetails, {
86 'title': 'title',
87 'id': ('details', 'item_id'),
88 'description': ('details', 'description'),
89 'duration': ('duration', {float_or_none(scale=1000)}),
90 'cast': ('details', 'cast', {lambda x: x.split(', ')}),
91 'modified_timestamp': ('details', 'updated_by', 0, 'update_time', 'time', {int_or_none}),
92 'season_number': ('details', 'season', {int_or_none}),
93 'episode_number': ('details', 'episode', {int_or_none}),
94 'age_limit': ('details', 'rating_code', {parse_age_limit}),
95 'series': ('details', 'series_details', 'title'),
96 }),
100 class CineverseDetailsIE(CineverseBaseIE):
101 _VALID_URL = rf'{CineverseBaseIE._VALID_URL_BASE}/details/(?P<id>[A-Z0-9]+)'
102 _TESTS = [{
103 'url': 'https://www.retrocrush.tv/details/1000000023012/Space-Adventure-COBRA-(Original-Japanese)',
104 'playlist_mincount': 30,
105 'info_dict': {
106 'title': 'Space Adventure COBRA (Original Japanese)',
107 'id': '1000000023012',
109 }, {
110 'url': 'https://www.asiancrush.com/details/NNVG4938/Hansel-and-Gretel',
111 'info_dict': {
112 'id': 'NNVG4938',
113 'ext': 'mp4',
114 'title': 'Hansel and Gretel',
115 'description': 'md5:e3e4c35309c2e82aee044f972c2fb05d',
116 'cast': ['Jeong-myeong Cheon', 'Eun Won-jae', 'Shim Eun-gyeong', 'Ji-hee Jin', 'Hee-soon Park', 'Lydia Park', 'Kyeong-ik Kim'],
117 'duration': 7030.732,
121 def _real_extract(self, url):
122 host, series_id = self._match_valid_url(url).group('host', 'id')
123 html = self._download_webpage(url, series_id)
124 pageprops = self._search_nextjs_data(html, series_id)['props']['pageProps']
126 geo_countries = traverse_obj(pageprops, ('itemDetailsData', 'geo_country', {lambda x: x.split(', ')}))
127 geoblocked = traverse_obj(pageprops, (
128 'itemDetailsData', 'playback_err_msg')) == 'This title is not available in your location.'
130 def item_result(item):
131 item_url = f'https://www.{host}/watch/{item["item_id"]}/{item["title"]}'
132 if geoblocked:
133 item_url = smuggle_url(item_url, {'geo_countries': geo_countries})
134 return self.url_result(item_url, CineverseIE)
136 season = traverse_obj(pageprops, ('seasonEpisodes', ..., 'episodes', lambda _, v: v['item_id'] and v['title']))
137 if season:
138 return self.playlist_result([item_result(ep) for ep in season], playlist_id=series_id,
139 playlist_title=traverse_obj(pageprops, ('itemDetailsData', 'title')))
140 return item_result(pageprops['itemDetailsData'])