likee.py 6.8 KB

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