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.

95 lines
3.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. )
  10. class RedTubeIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:(?:www\.)?redtube\.com/|embed\.redtube\.com/\?.*?\bid=)(?P<id>[0-9]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.redtube.com/66418',
  14. 'md5': '7b8c22b5e7098a3e1c09709df1126d2d',
  15. 'info_dict': {
  16. 'id': '66418',
  17. 'ext': 'mp4',
  18. 'title': 'Sucked on a toilet',
  19. 'upload_date': '20120831',
  20. 'duration': 596,
  21. 'view_count': int,
  22. 'age_limit': 18,
  23. }
  24. }, {
  25. 'url': 'http://embed.redtube.com/?bgcolor=000000&id=1443286',
  26. 'only_matching': True,
  27. }]
  28. @staticmethod
  29. def _extract_urls(webpage):
  30. return re.findall(
  31. r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//embed\.redtube\.com/\?.*?\bid=\d+)',
  32. webpage)
  33. def _real_extract(self, url):
  34. video_id = self._match_id(url)
  35. webpage = self._download_webpage(
  36. 'http://www.redtube.com/%s' % video_id, video_id)
  37. if any(s in webpage for s in ['video-deleted-info', '>This video has been removed']):
  38. raise ExtractorError('Video %s has been removed' % video_id, expected=True)
  39. title = self._html_search_regex(
  40. (r'<h1 class="videoTitle[^"]*">(?P<title>.+?)</h1>',
  41. r'videoTitle\s*:\s*(["\'])(?P<title>)\1'),
  42. webpage, 'title', group='title')
  43. formats = []
  44. sources = self._parse_json(
  45. self._search_regex(
  46. r'sources\s*:\s*({.+?})', webpage, 'source', default='{}'),
  47. video_id, fatal=False)
  48. if sources and isinstance(sources, dict):
  49. for format_id, format_url in sources.items():
  50. if format_url:
  51. formats.append({
  52. 'url': format_url,
  53. 'format_id': format_id,
  54. 'height': int_or_none(format_id),
  55. })
  56. else:
  57. video_url = self._html_search_regex(
  58. r'<source src="(.+?)" type="video/mp4">', webpage, 'video URL')
  59. formats.append({'url': video_url})
  60. self._sort_formats(formats)
  61. thumbnail = self._og_search_thumbnail(webpage)
  62. upload_date = unified_strdate(self._search_regex(
  63. r'<span[^>]+class="added-time"[^>]*>ADDED ([^<]+)<',
  64. webpage, 'upload date', fatal=False))
  65. duration = int_or_none(self._search_regex(
  66. r'videoDuration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
  67. view_count = str_to_int(self._search_regex(
  68. r'<span[^>]*>VIEWS</span></td>\s*<td>([\d,.]+)',
  69. webpage, 'view count', fatal=False))
  70. # No self-labeling, but they describe themselves as
  71. # "Home of Videos Porno"
  72. age_limit = 18
  73. return {
  74. 'id': video_id,
  75. 'ext': 'mp4',
  76. 'title': title,
  77. 'thumbnail': thumbnail,
  78. 'upload_date': upload_date,
  79. 'duration': duration,
  80. 'view_count': view_count,
  81. 'age_limit': age_limit,
  82. 'formats': formats,
  83. }