[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / trueid.py
blob183364b4018f1d9928abe03850ccdaa905aa93b6
1 from .common import InfoExtractor
2 from ..networking.exceptions import HTTPError
3 from ..utils import (
4 ExtractorError,
5 determine_ext,
6 int_or_none,
7 parse_age_limit,
8 traverse_obj,
9 unified_timestamp,
10 url_or_none,
14 class TrueIDIE(InfoExtractor):
15 _VALID_URL = r'https?://(?P<domain>vn\.trueid\.net|trueid\.(?:id|ph))/(?:movie|series/[^/]+)/(?P<id>[^/?#&]+)'
16 _TESTS = [{
17 'url': 'https://trueid.id/movie/XYNlDOZZJzL6/pengabdi-setan/',
18 'md5': '2552c7535125885901f1a2a4bcf32ca3',
19 'info_dict': {
20 'id': 'XYNlDOZZJzL6',
21 'ext': 'mp4',
22 'title': 'Pengabdi Setan',
23 'display_id': 'pengabdi-setan',
24 'description': 'md5:b0b41df08601e85e5291496c9bbe52cd',
25 'timestamp': 1600243511,
26 'categories': ['Film Indonesia', 'Horror', 'Mystery'],
27 'release_timestamp': 1593536400,
28 'release_year': 1982,
29 'cast': list,
30 'thumbnail': 'https://cms.dmpcdn.com/movie/2020/09/18/8b6e35c0-f97f-11ea-81fe-c52fc9dd314f_original.png',
31 'upload_date': '20200916',
32 'release_date': '20200630',
34 'expected_warnings': ['Video is geo restricted.'],
35 }, {
36 'url': 'https://trueid.id/series/zZOBVPb62EwR/qXY73rwyl7oj/one-piece-ep-1/',
37 'md5': '1c6d976049bc3c89a8a25aed2c3fb081',
38 'info_dict': {
39 'id': 'qXY73rwyl7oj',
40 'ext': 'mp4',
41 'title': 'One Piece Ep. 1',
42 'display_id': 'one-piece-ep-1',
43 'description': 'md5:13226d603bd03c4150a1cf5758e842ea',
44 'timestamp': 1610421085,
45 'categories': ['Animation & Cartoon', 'Kids & Family', 'Adventure'],
46 'release_timestamp': 1612112400,
47 'release_year': 1999,
48 'age_limit': 7,
49 'cast': ['Kounosuke Uda', 'Junji Shimizu'],
50 'thumbnail': 'https://cms.dmpcdn.com/movie/2021/01/13/f84e9e70-5562-11eb-9fe2-dd6c2099a468_original.png',
51 'upload_date': '20210112',
52 'release_date': '20210131',
54 'expected_warnings': ['Video is geo restricted.'],
55 }, {
56 'url': 'https://vn.trueid.net/series/7DNPM7Bpa9wv/pwLgEQ4Xbda2/haikyu-vua-bong-chuyen-phan-1/',
57 'info_dict': {
58 'id': 'pwLgEQ4Xbda2',
59 'ext': 'mp4',
60 'title': 'Haikyu!!: Vua Bóng Chuyền Phần 1 - Tập 1',
61 'display_id': 'haikyu-vua-bong-chuyen-phan-1-tap-1',
62 'description': 'md5:0374dd44d247799169449ee30cca963a',
63 'timestamp': 1629270901,
64 'categories': ['Anime', 'Phim Hài', 'Phim Học Đường', 'Phim Thể Thao', 'Shounen'],
65 'release_timestamp': 1629270720,
66 'release_year': 2014,
67 'age_limit': 13,
68 'thumbnail': 'https://cms.dmpcdn.com/movie/2021/09/28/b6e7ec00-2039-11ec-8436-974544e5841f_webp_original.jpg',
69 'upload_date': '20210818',
70 'release_date': '20210818',
72 'expected_warnings': ['Video is geo restricted.'],
73 }, {
74 'url': 'https://trueid.ph/series/l8rvvAw7Jwv8/l8rvvAw7Jwv8/naruto-trailer/',
75 'only_matching': True,
77 _CUSTOM_RATINGS = {
78 'PG': 7,
81 def _real_extract(self, url):
82 domain, video_id = self._match_valid_url(url).group('domain', 'id')
83 webpage = self._download_webpage(url, video_id)
84 initial_data = traverse_obj(
85 self._search_nextjs_data(webpage, video_id, fatal=False), ('props', 'pageProps', 'initialContentData'), default={})
87 try:
88 stream_data = self._download_json(
89 f'https://{domain}/cmsPostProxy/contents/video/{video_id}/streamer?os=android', video_id, data=b'')['data']
90 except ExtractorError as e:
91 if not isinstance(e.cause, HTTPError):
92 raise e
93 errmsg = self._parse_json(e.cause.response.read().decode(), video_id)['meta']['message']
94 if 'country' in errmsg:
95 self.raise_geo_restricted(
96 errmsg, [initial_data['display_country']] if initial_data.get('display_country') else None, True)
97 else:
98 self.raise_no_formats(errmsg, video_id=video_id)
100 if stream_data:
101 stream_url = stream_data['stream']['stream_url']
102 stream_ext = determine_ext(stream_url)
103 if stream_ext == 'm3u8':
104 formats, subs = self._extract_m3u8_formats_and_subtitles(stream_url, video_id, 'mp4')
105 elif stream_ext == 'mpd':
106 formats, subs = self._extract_mpd_formats_and_subtitles(stream_url, video_id)
107 else:
108 formats = [{'url': stream_url}]
110 thumbnails = [
111 {'id': thumb_key, 'url': thumb_url}
112 for thumb_key, thumb_url in (initial_data.get('thumb_list') or {}).items()
113 if url_or_none(thumb_url)]
115 return {
116 'id': video_id,
117 'title': initial_data.get('title') or self._html_search_regex(
118 [r'Nonton (?P<name>.+) Gratis',
119 r'Xem (?P<name>.+) Miễn phí',
120 r'Watch (?P<name>.+) Free'], webpage, 'title', group='name'),
121 'display_id': initial_data.get('slug_title'),
122 'description': initial_data.get('synopsis'),
123 'timestamp': unified_timestamp(initial_data.get('create_date')),
124 # 'duration': int_or_none(initial_data.get('duration'), invscale=60), # duration field must atleast be accurate to the second
125 'categories': traverse_obj(initial_data, ('article_category_details', ..., 'name')),
126 'release_timestamp': unified_timestamp(initial_data.get('publish_date')),
127 'release_year': int_or_none(initial_data.get('release_year')),
128 'formats': formats,
129 'subtitles': subs,
130 'thumbnails': thumbnails,
131 'age_limit': self._CUSTOM_RATINGS.get(initial_data.get('rate')) or parse_age_limit(initial_data.get('rate')),
132 'cast': traverse_obj(initial_data, (('actor', 'director'), ...)),
133 'view_count': int_or_none(initial_data.get('count_views')),
134 'like_count': int_or_none(initial_data.get('count_likes')),
135 'average_rating': int_or_none(initial_data.get('count_ratings')),