trueid.py 6.2 KB

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