]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/likee.py
[cleanup] Fix infodict returned fields (#8906)
[yt-dlp.git] / yt_dlp / extractor / likee.py
CommitLineData
f963b7ab
HTL
1import json
2
3from .common import InfoExtractor
4from ..utils import (
5 int_or_none,
6 js_to_json,
7 parse_iso8601,
8 str_or_none,
9 traverse_obj,
10)
11
12
13class LikeeIE(InfoExtractor):
14 IE_NAME = 'likee'
15 _VALID_URL = r'(?x)https?://(www\.)?likee\.video/(?:(?P<channel_name>[^/]+)/video/|v/)(?P<id>\w+)'
16 _TESTS = [{
17 'url': 'https://likee.video/@huynh_hong_quan_/video/7093444807096327263',
18 'info_dict': {
19 'id': '7093444807096327263',
20 'ext': 'mp4',
21 'title': '🤴🤴🤴',
22 'description': 'md5:9a7ebe816f0e78722ee5ed76f75983b4',
23 'thumbnail': r're:^https?://.+\.jpg',
24 'uploader': 'Huỳnh Hồng Qu&acirc;n ',
f963b7ab
HTL
25 'artist': 'Huỳnh Hồng Qu&acirc;n ',
26 'timestamp': 1651571320,
27 'upload_date': '20220503',
28 'view_count': int,
29 'uploader_id': 'huynh_hong_quan_',
30 'duration': 12374,
31 'comment_count': int,
32 'like_count': int,
33 },
34 }, {
35 'url': 'https://likee.video/@649222262/video/7093167848050058862',
36 'info_dict': {
37 'id': '7093167848050058862',
38 'ext': 'mp4',
39 'title': 'likee video #7093167848050058862',
40 'description': 'md5:3f971c8c6ee8a216f2b1a9094c5de99f',
41 'thumbnail': r're:^https?://.+\.jpg',
42 'comment_count': int,
43 'like_count': int,
44 'uploader': 'Vương Phước Nhi',
f963b7ab
HTL
45 'timestamp': 1651506835,
46 'upload_date': '20220502',
47 'duration': 60024,
f963b7ab
HTL
48 'artist': 'Vương Phước Nhi',
49 'uploader_id': '649222262',
50 'view_count': int,
51 },
52 }, {
53 'url': 'https://likee.video/@fernanda_rivasg/video/6932224568407629502',
54 'info_dict': {
55 'id': '6932224568407629502',
56 'ext': 'mp4',
57 'title': 'Un trend viejito🔥 #LIKEE #Ferlovers #trend ',
58 'description': 'md5:c42b903a72a99d6d8b73e3d1126fbcef',
59 'thumbnail': r're:^https?://.+\.jpg',
60 'comment_count': int,
61 'duration': 9684,
62 'uploader_id': 'fernanda_rivasg',
63 'view_count': int,
f963b7ab 64 'artist': 'La Cami La✨',
f963b7ab
HTL
65 'like_count': int,
66 'uploader': 'Fernanda Rivas🎶',
67 'timestamp': 1614034308,
68 'upload_date': '20210222',
69 },
70 }, {
71 'url': 'https://likee.video/v/k6QcOp',
72 'info_dict': {
73 'id': 'k6QcOp',
74 'ext': 'mp4',
75 'title': '#AguaChallenge t&uacute; ya lo intentaste?😱🤩',
76 'description': 'md5:b0cc462689d4ff2b624daa4dba7640d9',
77 'thumbnail': r're:^https?://.+\.jpg',
78 'comment_count': int,
79 'duration': 18014,
f963b7ab
HTL
80 'view_count': int,
81 'timestamp': 1611694774,
82 'like_count': int,
83 'uploader': 'Fernanda Rivas🎶',
84 'uploader_id': 'fernanda_rivasg',
f963b7ab
HTL
85 'artist': 'ʟᴇʀɪᴋ_ᴜɴɪᴄᴏʀɴ♡︎',
86 'upload_date': '20210126',
87 },
88 }, {
89 'url': 'https://www.likee.video/@649222262/video/7093167848050058862',
90 'only_matching': True,
91 }, {
92 'url': 'https://www.likee.video/v/k6QcOp',
93 'only_matching': True,
94 }]
95
96 def _real_extract(self, url):
97 video_id = self._match_id(url)
98 webpage = self._download_webpage(url, video_id)
99 info = self._parse_json(
100 self._search_regex(r'window\.data\s=\s({.+?});', webpage, 'video info'),
101 video_id, transform_source=js_to_json)
102 video_url = traverse_obj(info, 'video_url', ('originVideoInfo', 'video_url'))
103 if not video_url:
104 self.raise_no_formats('Video was deleted', expected=True)
105 formats = [{
106 'format_id': 'mp4-with-watermark',
107 'url': video_url,
108 'height': info.get('video_height'),
109 'width': info.get('video_width'),
110 }, {
111 'format_id': 'mp4-without-watermark',
112 'url': video_url.replace('_4', ''),
113 'height': info.get('video_height'),
114 'width': info.get('video_width'),
115 'quality': 1,
116 }]
f963b7ab
HTL
117 return {
118 'id': video_id,
119 'title': info.get('msgText'),
120 'description': info.get('share_desc'),
121 'view_count': int_or_none(info.get('video_count')),
122 'like_count': int_or_none(info.get('likeCount')),
f963b7ab
HTL
123 'comment_count': int_or_none(info.get('comment_count')),
124 'uploader': str_or_none(info.get('nick_name')),
125 'uploader_id': str_or_none(info.get('likeeId')),
126 'artist': str_or_none(traverse_obj(info, ('sound', 'owner_name'))),
127 'timestamp': parse_iso8601(info.get('uploadDate')),
128 'thumbnail': info.get('coverUrl'),
129 'duration': int_or_none(traverse_obj(info, ('option_data', 'dur'))),
130 'formats': formats,
131 }
132
133
134class LikeeUserIE(InfoExtractor):
135 IE_NAME = 'likee:user'
136 _VALID_URL = r'https?://(www\.)?likee\.video/(?P<id>[^/]+)/?$'
137 _TESTS = [{
138 'url': 'https://likee.video/@fernanda_rivasg',
139 'info_dict': {
140 'id': '925638334',
141 'title': 'fernanda_rivasg',
142 },
143 'playlist_mincount': 500,
144 }, {
145 'url': 'https://likee.video/@may_hmoob',
146 'info_dict': {
147 'id': '2943949041',
148 'title': 'may_hmoob',
149 },
150 'playlist_mincount': 80,
151 }]
152 _PAGE_SIZE = 50
153 _API_GET_USER_VIDEO = 'https://api.like-video.com/likee-activity-flow-micro/videoApi/getUserVideo'
154
155 def _entries(self, user_name, user_id):
156 last_post_id = ''
157 while True:
158 user_videos = self._download_json(
159 self._API_GET_USER_VIDEO, user_name,
160 data=json.dumps({
161 'uid': user_id,
162 'count': self._PAGE_SIZE,
163 'lastPostId': last_post_id,
164 'tabType': 0,
165 }).encode('utf-8'),
166 headers={'content-type': 'application/json'},
167 note=f'Get user info with lastPostId #{last_post_id}')
168 items = traverse_obj(user_videos, ('data', 'videoList'))
169 if not items:
170 break
171 for item in items:
172 last_post_id = item['postId']
173 yield self.url_result(f'https://likee.video/{user_name}/video/{last_post_id}')
174
175 def _real_extract(self, url):
176 user_name = self._match_id(url)
177 webpage = self._download_webpage(url, user_name)
178 info = self._parse_json(
179 self._search_regex(r'window\.data\s*=\s*({.+?});', webpage, 'user info'),
180 user_name, transform_source=js_to_json)
181 user_id = traverse_obj(info, ('userinfo', 'uid'))
182 return self.playlist_result(self._entries(user_name, user_id), user_id, traverse_obj(info, ('userinfo', 'user_name')))