likee.py 7.2 KB

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