You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
4.2 KiB

11 years ago
11 years ago
11 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. int_or_none,
  7. str_to_int,
  8. unified_strdate,
  9. url_or_none,
  10. )
  11. class RedTubeIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:(?:www\.)?redtube\.com/|embed\.redtube\.com/\?.*?\bid=)(?P<id>[0-9]+)'
  13. _TESTS = [{
  14. 'url': 'http://www.redtube.com/66418',
  15. 'md5': 'fc08071233725f26b8f014dba9590005',
  16. 'info_dict': {
  17. 'id': '66418',
  18. 'ext': 'mp4',
  19. 'title': 'Sucked on a toilet',
  20. 'upload_date': '20110811',
  21. 'duration': 596,
  22. 'view_count': int,
  23. 'age_limit': 18,
  24. }
  25. }, {
  26. 'url': 'http://embed.redtube.com/?bgcolor=000000&id=1443286',
  27. 'only_matching': True,
  28. }]
  29. @staticmethod
  30. def _extract_urls(webpage):
  31. return re.findall(
  32. r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//embed\.redtube\.com/\?.*?\bid=\d+)',
  33. webpage)
  34. def _real_extract(self, url):
  35. video_id = self._match_id(url)
  36. webpage = self._download_webpage(
  37. 'http://www.redtube.com/%s' % video_id, video_id)
  38. if any(s in webpage for s in ['video-deleted-info', '>This video has been removed']):
  39. raise ExtractorError('Video %s has been removed' % video_id, expected=True)
  40. title = self._html_search_regex(
  41. (r'<h(\d)[^>]+class="(?:video_title_text|videoTitle)[^"]*">(?P<title>(?:(?!\1).)+)</h\1>',
  42. r'(?:videoTitle|title)\s*:\s*(["\'])(?P<title>(?:(?!\1).)+)\1',),
  43. webpage, 'title', group='title',
  44. default=None) or self._og_search_title(webpage)
  45. formats = []
  46. sources = self._parse_json(
  47. self._search_regex(
  48. r'sources\s*:\s*({.+?})', webpage, 'source', default='{}'),
  49. video_id, fatal=False)
  50. if sources and isinstance(sources, dict):
  51. for format_id, format_url in sources.items():
  52. if format_url:
  53. formats.append({
  54. 'url': format_url,
  55. 'format_id': format_id,
  56. 'height': int_or_none(format_id),
  57. })
  58. medias = self._parse_json(
  59. self._search_regex(
  60. r'mediaDefinition\s*:\s*(\[.+?\])', webpage,
  61. 'media definitions', default='{}'),
  62. video_id, fatal=False)
  63. if medias and isinstance(medias, list):
  64. for media in medias:
  65. format_url = url_or_none(media.get('videoUrl'))
  66. if not format_url:
  67. continue
  68. format_id = media.get('quality')
  69. formats.append({
  70. 'url': format_url,
  71. 'format_id': format_id,
  72. 'height': int_or_none(format_id),
  73. })
  74. if not formats:
  75. video_url = self._html_search_regex(
  76. r'<source src="(.+?)" type="video/mp4">', webpage, 'video URL')
  77. formats.append({'url': video_url})
  78. self._sort_formats(formats)
  79. thumbnail = self._og_search_thumbnail(webpage)
  80. upload_date = unified_strdate(self._search_regex(
  81. r'<span[^>]+>ADDED ([^<]+)<',
  82. webpage, 'upload date', fatal=False))
  83. duration = int_or_none(self._og_search_property(
  84. 'video:duration', webpage, default=None) or self._search_regex(
  85. r'videoDuration\s*:\s*(\d+)', webpage, 'duration', default=None))
  86. view_count = str_to_int(self._search_regex(
  87. (r'<div[^>]*>Views</div>\s*<div[^>]*>\s*([\d,.]+)',
  88. r'<span[^>]*>VIEWS</span>\s*</td>\s*<td>\s*([\d,.]+)'),
  89. webpage, 'view count', fatal=False))
  90. # No self-labeling, but they describe themselves as
  91. # "Home of Videos Porno"
  92. age_limit = 18
  93. return {
  94. 'id': video_id,
  95. 'ext': 'mp4',
  96. 'title': title,
  97. 'thumbnail': thumbnail,
  98. 'upload_date': upload_date,
  99. 'duration': duration,
  100. 'view_count': view_count,
  101. 'age_limit': age_limit,
  102. 'formats': formats,
  103. }