cineverse.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. filter_dict,
  5. int_or_none,
  6. parse_age_limit,
  7. smuggle_url,
  8. traverse_obj,
  9. unsmuggle_url,
  10. url_or_none,
  11. )
  12. class CineverseBaseIE(InfoExtractor):
  13. _VALID_URL_BASE = r'https?://www\.(?P<host>{})'.format('|'.join(map(re.escape, (
  14. 'cineverse.com',
  15. 'asiancrush.com',
  16. 'dovechannel.com',
  17. 'screambox.com',
  18. 'midnightpulp.com',
  19. 'fandor.com',
  20. 'retrocrush.tv',
  21. ))))
  22. class CineverseIE(CineverseBaseIE):
  23. _VALID_URL = rf'{CineverseBaseIE._VALID_URL_BASE}/watch/(?P<id>[A-Z0-9]+)'
  24. _TESTS = [{
  25. 'url': 'https://www.asiancrush.com/watch/DMR00018919/Women-Who-Flirt',
  26. 'skip': 'geo-blocked',
  27. 'info_dict': {
  28. 'title': 'Women Who Flirt',
  29. 'ext': 'mp4',
  30. 'id': 'DMR00018919',
  31. 'modified_timestamp': 1678744575289,
  32. 'cast': ['Xun Zhou', 'Xiaoming Huang', 'Yi-Lin Sie', 'Sonia Sui', 'Quniciren'],
  33. 'duration': 5811.597,
  34. 'description': 'md5:892fd62a05611d394141e8394ace0bc6',
  35. 'age_limit': 13,
  36. },
  37. }, {
  38. 'url': 'https://www.retrocrush.tv/watch/1000000023016/Archenemy! Crystal Bowie',
  39. 'skip': 'geo-blocked',
  40. 'info_dict': {
  41. 'title': 'Archenemy! Crystal Bowie',
  42. 'ext': 'mp4',
  43. 'id': '1000000023016',
  44. 'episode_number': 3,
  45. 'season_number': 1,
  46. 'cast': ['Nachi Nozawa', 'Yoshiko Sakakibara', 'Toshiko Fujita'],
  47. 'age_limit': 0,
  48. 'episode': 'Episode 3',
  49. 'season': 'Season 1',
  50. 'duration': 1485.067,
  51. 'description': 'Cobra meets a beautiful bounty hunter by the name of Jane Royal.',
  52. 'series': 'Space Adventure COBRA (Original Japanese)',
  53. },
  54. }]
  55. def _real_extract(self, url):
  56. url, smuggled_data = unsmuggle_url(url, default={})
  57. self._initialize_geo_bypass({
  58. 'countries': smuggled_data.get('geo_countries'),
  59. })
  60. video_id = self._match_id(url)
  61. html = self._download_webpage(url, video_id)
  62. idetails = self._search_nextjs_data(html, video_id)['props']['pageProps']['idetails']
  63. err_code = idetails.get('err_code')
  64. if err_code == 1002:
  65. self.raise_login_required()
  66. elif err_code == 1200:
  67. self.raise_geo_restricted(
  68. 'This video is not available from your location due to geo restriction. '
  69. 'You may be able to bypass it by using the /details/ page instead of the /watch/ page',
  70. countries=smuggled_data.get('geo_countries'))
  71. return {
  72. 'subtitles': filter_dict({
  73. 'en': traverse_obj(idetails, (('cc_url_vtt', 'subtitle_url'), {'url': {url_or_none}})) or None,
  74. }),
  75. 'formats': self._extract_m3u8_formats(idetails['url'], video_id),
  76. **traverse_obj(idetails, {
  77. 'title': 'title',
  78. 'id': ('details', 'item_id'),
  79. 'description': ('details', 'description'),
  80. 'duration': ('duration', {lambda x: x / 1000}),
  81. 'cast': ('details', 'cast', {lambda x: x.split(', ')}),
  82. 'modified_timestamp': ('details', 'updated_by', 0, 'update_time', 'time', {int_or_none}),
  83. 'season_number': ('details', 'season', {int_or_none}),
  84. 'episode_number': ('details', 'episode', {int_or_none}),
  85. 'age_limit': ('details', 'rating_code', {parse_age_limit}),
  86. 'series': ('details', 'series_details', 'title'),
  87. }),
  88. }
  89. class CineverseDetailsIE(CineverseBaseIE):
  90. _VALID_URL = rf'{CineverseBaseIE._VALID_URL_BASE}/details/(?P<id>[A-Z0-9]+)'
  91. _TESTS = [{
  92. 'url': 'https://www.retrocrush.tv/details/1000000023012/Space-Adventure-COBRA-(Original-Japanese)',
  93. 'playlist_mincount': 30,
  94. 'info_dict': {
  95. 'title': 'Space Adventure COBRA (Original Japanese)',
  96. 'id': '1000000023012',
  97. },
  98. }, {
  99. 'url': 'https://www.asiancrush.com/details/NNVG4938/Hansel-and-Gretel',
  100. 'info_dict': {
  101. 'id': 'NNVG4938',
  102. 'ext': 'mp4',
  103. 'title': 'Hansel and Gretel',
  104. 'description': 'md5:e3e4c35309c2e82aee044f972c2fb05d',
  105. 'cast': ['Jeong-myeong Cheon', 'Eun Won-jae', 'Shim Eun-gyeong', 'Ji-hee Jin', 'Hee-soon Park', 'Lydia Park', 'Kyeong-ik Kim'],
  106. 'duration': 7030.732,
  107. },
  108. }]
  109. def _real_extract(self, url):
  110. host, series_id = self._match_valid_url(url).group('host', 'id')
  111. html = self._download_webpage(url, series_id)
  112. pageprops = self._search_nextjs_data(html, series_id)['props']['pageProps']
  113. geo_countries = traverse_obj(pageprops, ('itemDetailsData', 'geo_country', {lambda x: x.split(', ')}))
  114. geoblocked = traverse_obj(pageprops, (
  115. 'itemDetailsData', 'playback_err_msg')) == 'This title is not available in your location.'
  116. def item_result(item):
  117. item_url = f'https://www.{host}/watch/{item["item_id"]}/{item["title"]}'
  118. if geoblocked:
  119. item_url = smuggle_url(item_url, {'geo_countries': geo_countries})
  120. return self.url_result(item_url, CineverseIE)
  121. season = traverse_obj(pageprops, ('seasonEpisodes', ..., 'episodes', lambda _, v: v['item_id'] and v['title']))
  122. if season:
  123. return self.playlist_result([item_result(ep) for ep in season], playlist_id=series_id,
  124. playlist_title=traverse_obj(pageprops, ('itemDetailsData', 'title')))
  125. return item_result(pageprops['itemDetailsData'])