redtube.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. determine_ext,
  5. int_or_none,
  6. merge_dicts,
  7. str_to_int,
  8. unified_strdate,
  9. url_or_none,
  10. urljoin,
  11. )
  12. class RedTubeIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:(?:\w+\.)?redtube\.com(?:\.br)?/|embed\.redtube\.com/\?.*?\bid=)(?P<id>[0-9]+)'
  14. _EMBED_REGEX = [r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//embed\.redtube\.com/\?.*?\bid=\d+)']
  15. _TESTS = [{
  16. 'url': 'https://www.redtube.com/38864951',
  17. 'md5': '4fba70cbca3aefd25767ab4b523c9878',
  18. 'info_dict': {
  19. 'id': '38864951',
  20. 'ext': 'mp4',
  21. 'title': 'Public Sex on the Balcony in Freezing Paris! Amateur Couple LeoLulu',
  22. 'description': 'Watch video Public Sex on the Balcony in Freezing Paris! Amateur Couple LeoLulu on Redtube, home of free Blowjob porn videos and Blonde sex movies online. Video length: (10:46) - Uploaded by leolulu - Verified User - Starring Pornstar: Leolulu',
  23. 'upload_date': '20210111',
  24. 'timestamp': 1610343109,
  25. 'duration': 646,
  26. 'view_count': int,
  27. 'age_limit': 18,
  28. 'thumbnail': r're:https://\wi-ph\.rdtcdn\.com/videos/.+/.+\.jpg',
  29. },
  30. }, {
  31. 'url': 'http://embed.redtube.com/?bgcolor=000000&id=1443286',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://it.redtube.com/66418',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'https://www.redtube.com.br/103224331',
  38. 'only_matching': True,
  39. }]
  40. def _real_extract(self, url):
  41. video_id = self._match_id(url)
  42. webpage = self._download_webpage(
  43. f'https://www.redtube.com/{video_id}', video_id)
  44. ERRORS = (
  45. (('video-deleted-info', '>This video has been removed'), 'has been removed'),
  46. (('private_video_text', '>This video is private', '>Send a friend request to its owner to be able to view it'), 'is private'),
  47. )
  48. for patterns, message in ERRORS:
  49. if any(p in webpage for p in patterns):
  50. raise ExtractorError(
  51. f'Video {video_id} {message}', expected=True)
  52. info = self._search_json_ld(webpage, video_id, default={})
  53. if not info.get('title'):
  54. info['title'] = self._html_search_regex(
  55. (r'<h(\d)[^>]+class="(?:video_title_text|videoTitle|video_title)[^"]*">(?P<title>(?:(?!\1).)+)</h\1>',
  56. r'(?:videoTitle|title)\s*:\s*(["\'])(?P<title>(?:(?!\1).)+)\1'),
  57. webpage, 'title', group='title',
  58. default=None) or self._og_search_title(webpage)
  59. formats = []
  60. sources = self._parse_json(
  61. self._search_regex(
  62. r'sources\s*:\s*({.+?})', webpage, 'source', default='{}'),
  63. video_id, fatal=False)
  64. if sources and isinstance(sources, dict):
  65. for format_id, format_url in sources.items():
  66. if format_url:
  67. formats.append({
  68. 'url': format_url,
  69. 'format_id': format_id,
  70. 'height': int_or_none(format_id),
  71. })
  72. medias = self._parse_json(
  73. self._search_regex(
  74. r'mediaDefinition["\']?\s*:\s*(\[.+?}\s*\])', webpage,
  75. 'media definitions', default='{}'),
  76. video_id, fatal=False)
  77. for media in medias if isinstance(medias, list) else []:
  78. format_url = urljoin('https://www.redtube.com', media.get('videoUrl'))
  79. if not format_url:
  80. continue
  81. format_id = media.get('format')
  82. quality = media.get('quality')
  83. if format_id == 'hls' or (format_id == 'mp4' and not quality):
  84. more_media = self._download_json(format_url, video_id, fatal=False)
  85. else:
  86. more_media = [media]
  87. for media in more_media if isinstance(more_media, list) else []:
  88. format_url = url_or_none(media.get('videoUrl'))
  89. if not format_url:
  90. continue
  91. format_id = media.get('format')
  92. if format_id == 'hls' or determine_ext(format_url) == 'm3u8':
  93. formats.extend(self._extract_m3u8_formats(
  94. format_url, video_id, 'mp4',
  95. entry_protocol='m3u8_native', m3u8_id=format_id or 'hls',
  96. fatal=False))
  97. continue
  98. format_id = media.get('quality')
  99. formats.append({
  100. 'url': format_url,
  101. 'ext': 'mp4',
  102. 'format_id': format_id,
  103. 'height': int_or_none(format_id),
  104. })
  105. if not formats:
  106. video_url = self._html_search_regex(
  107. r'<source src="(.+?)" type="video/mp4">', webpage, 'video URL')
  108. formats.append({'url': video_url, 'ext': 'mp4'})
  109. thumbnail = self._og_search_thumbnail(webpage)
  110. upload_date = unified_strdate(self._search_regex(
  111. r'<span[^>]+>(?:ADDED|Published on) ([^<]+)<',
  112. webpage, 'upload date', default=None))
  113. duration = int_or_none(self._og_search_property(
  114. 'video:duration', webpage, default=None) or self._search_regex(
  115. r'videoDuration\s*:\s*(\d+)', webpage, 'duration', default=None))
  116. view_count = str_to_int(self._search_regex(
  117. (r'<div[^>]*>Views</div>\s*<div[^>]*>\s*([\d,.]+)',
  118. r'<span[^>]*>VIEWS</span>\s*</td>\s*<td>\s*([\d,.]+)',
  119. r'<span[^>]+\bclass=["\']video_view_count[^>]*>\s*([\d,.]+)'),
  120. webpage, 'view count', default=None))
  121. # No self-labeling, but they describe themselves as
  122. # "Home of Videos Porno"
  123. age_limit = 18
  124. return merge_dicts(info, {
  125. 'id': video_id,
  126. 'ext': 'mp4',
  127. 'thumbnail': thumbnail,
  128. 'upload_date': upload_date,
  129. 'duration': duration,
  130. 'view_count': view_count,
  131. 'age_limit': age_limit,
  132. 'formats': formats,
  133. })