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