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.

83 lines
2.8 KiB

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