aitube.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from .common import InfoExtractor
  2. from ..utils import int_or_none, merge_dicts
  3. class AitubeKZVideoIE(InfoExtractor):
  4. _VALID_URL = r'https?://aitube\.kz/(?:video|embed/)\?(?:[^\?]+)?id=(?P<id>[\w-]+)'
  5. _TESTS = [{
  6. # id paramater as first parameter
  7. 'url': 'https://aitube.kz/video?id=9291d29b-c038-49a1-ad42-3da2051d353c&playlistId=d55b1f5f-ef2a-4f23-b646-2a86275b86b7&season=1',
  8. 'info_dict': {
  9. 'id': '9291d29b-c038-49a1-ad42-3da2051d353c',
  10. 'ext': 'mp4',
  11. 'duration': 2174.0,
  12. 'channel_id': '94962f73-013b-432c-8853-1bd78ca860fe',
  13. 'like_count': int,
  14. 'channel': 'ASTANA TV',
  15. 'comment_count': int,
  16. 'view_count': int,
  17. 'description': 'Смотреть любимые сериалы и видео, поделиться видео и сериалами с друзьями и близкими',
  18. 'thumbnail': 'https://cdn.static02.aitube.kz/kz.aitudala.aitube.staticaccess/files/ddf2a2ff-bee3-409b-b5f2-2a8202bba75b',
  19. 'upload_date': '20221102',
  20. 'timestamp': 1667370519,
  21. 'title': 'Ангел хранитель 1 серия',
  22. 'channel_follower_count': int,
  23. },
  24. }, {
  25. # embed url
  26. 'url': 'https://aitube.kz/embed/?id=9291d29b-c038-49a1-ad42-3da2051d353c',
  27. 'only_matching': True,
  28. }, {
  29. # id parameter is not as first paramater
  30. 'url': 'https://aitube.kz/video?season=1&id=9291d29b-c038-49a1-ad42-3da2051d353c&playlistId=d55b1f5f-ef2a-4f23-b646-2a86275b86b7',
  31. 'only_matching': True,
  32. }]
  33. def _real_extract(self, url):
  34. video_id = self._match_id(url)
  35. webpage = self._download_webpage(url, video_id)
  36. nextjs_data = self._search_nextjs_data(webpage, video_id)['props']['pageProps']['videoInfo']
  37. json_ld_data = self._search_json_ld(webpage, video_id)
  38. formats, subtitles = self._extract_m3u8_formats_and_subtitles(
  39. f'https://api-http.aitube.kz/kz.aitudala.aitube.staticaccess/video/{video_id}/video', video_id)
  40. return merge_dicts({
  41. 'id': video_id,
  42. 'title': nextjs_data.get('title') or self._html_search_meta(['name', 'og:title'], webpage),
  43. 'description': nextjs_data.get('description'),
  44. 'formats': formats,
  45. 'subtitles': subtitles,
  46. 'view_count': (nextjs_data.get('viewCount')
  47. or int_or_none(self._html_search_meta('ya:ovs:views_total', webpage))),
  48. 'like_count': nextjs_data.get('likeCount'),
  49. 'channel': nextjs_data.get('channelTitle'),
  50. 'channel_id': nextjs_data.get('channelId'),
  51. 'thumbnail': nextjs_data.get('coverUrl'),
  52. 'comment_count': nextjs_data.get('commentCount'),
  53. 'channel_follower_count': int_or_none(nextjs_data.get('channelSubscriberCount')),
  54. }, json_ld_data)