pornbox.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. from .common import InfoExtractor
  2. from ..compat import functools
  3. from ..utils import (
  4. int_or_none,
  5. parse_duration,
  6. parse_iso8601,
  7. qualities,
  8. str_or_none,
  9. traverse_obj,
  10. url_or_none,
  11. )
  12. class PornboxIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?pornbox\.com/application/watch-page/(?P<id>[0-9]+)'
  14. _TESTS = [{
  15. 'url': 'https://pornbox.com/application/watch-page/212108',
  16. 'md5': '3ff6b6e206f263be4c5e987a3162ac6e',
  17. 'info_dict': {
  18. 'id': '212108',
  19. 'ext': 'mp4',
  20. 'title': 'md5:ececc5c6e6c9dd35d290c45fed05fd49',
  21. 'uploader': 'Lily Strong',
  22. 'timestamp': 1665871200,
  23. 'upload_date': '20221015',
  24. 'age_limit': 18,
  25. 'availability': 'needs_auth',
  26. 'duration': 1505,
  27. 'cast': ['Lily Strong', 'John Strong'],
  28. 'tags': 'count:11',
  29. 'description': 'md5:589c7f33e183aa8aa939537300efb859',
  30. 'thumbnail': r're:^https?://cdn-image\.gtflixtv\.com.*\.jpg.*$',
  31. },
  32. }, {
  33. 'url': 'https://pornbox.com/application/watch-page/216045',
  34. 'info_dict': {
  35. 'id': '216045',
  36. 'title': 'md5:3e48528e73a9a2b12f7a2772ed0b26a2',
  37. 'description': 'md5:3e631dcaac029f15ed434e402d1b06c7',
  38. 'uploader': 'VK Studio',
  39. 'timestamp': 1618264800,
  40. 'upload_date': '20210412',
  41. 'age_limit': 18,
  42. 'availability': 'premium_only',
  43. 'duration': 2710,
  44. 'cast': 'count:3',
  45. 'tags': 'count:29',
  46. 'thumbnail': r're:^https?://cdn-image\.gtflixtv\.com.*\.jpg.*$',
  47. 'subtitles': 'count:6',
  48. },
  49. 'params': {
  50. 'skip_download': True,
  51. 'ignore_no_formats_error': True,
  52. },
  53. 'expected_warnings': [
  54. 'You are either not logged in or do not have access to this scene',
  55. 'No video formats found', 'Requested format is not available'],
  56. }]
  57. def _real_extract(self, url):
  58. video_id = self._match_id(url)
  59. public_data = self._download_json(f'https://pornbox.com/contents/{video_id}', video_id)
  60. subtitles = {country_code: [{
  61. 'url': f'https://pornbox.com/contents/{video_id}/subtitles/{country_code}',
  62. 'ext': 'srt',
  63. }] for country_code in traverse_obj(public_data, ('subtitles', ..., {str}))}
  64. is_free_scene = traverse_obj(
  65. public_data, ('price', 'is_available_for_free', {bool}), default=False)
  66. metadata = {
  67. 'id': video_id,
  68. **traverse_obj(public_data, {
  69. 'title': ('scene_name', {str.strip}),
  70. 'description': ('small_description', {str.strip}),
  71. 'uploader': 'studio',
  72. 'duration': ('runtime', {parse_duration}),
  73. 'cast': (('models', 'male_models'), ..., 'model_name'),
  74. 'thumbnail': ('player_poster', {url_or_none}),
  75. 'tags': ('niches', ..., 'niche'),
  76. }),
  77. 'age_limit': 18,
  78. 'timestamp': parse_iso8601(traverse_obj(
  79. public_data, ('studios', 'release_date'), 'publish_date')),
  80. 'availability': self._availability(needs_auth=True, needs_premium=not is_free_scene),
  81. 'subtitles': subtitles,
  82. }
  83. if not public_data.get('is_purchased') or not is_free_scene:
  84. self.raise_login_required(
  85. 'You are either not logged in or do not have access to this scene', metadata_available=True)
  86. return metadata
  87. media_id = traverse_obj(public_data, (
  88. 'medias', lambda _, v: v['title'] == 'Full video', 'media_id', {int}), get_all=False)
  89. if not media_id:
  90. self.raise_no_formats('Could not find stream id', video_id=video_id)
  91. stream_data = self._download_json(
  92. f'https://pornbox.com/media/{media_id}/stream', video_id=video_id, note='Getting manifest urls')
  93. get_quality = qualities(['web', 'vga', 'hd', '1080p', '4k', '8k'])
  94. metadata['formats'] = traverse_obj(stream_data, ('qualities', lambda _, v: v['src'], {
  95. 'url': 'src',
  96. 'vbr': ('bitrate', {functools.partial(int_or_none, scale=1000)}),
  97. 'format_id': ('quality', {str_or_none}),
  98. 'quality': ('quality', {get_quality}),
  99. 'width': ('size', {lambda x: int(x[:-1])}),
  100. }))
  101. return metadata