redtube.py 5.9 KB

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