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.

219 lines
7.9 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. clean_html,
  6. dict_get,
  7. ExtractorError,
  8. int_or_none,
  9. parse_duration,
  10. unified_strdate,
  11. )
  12. class XHamsterIE(InfoExtractor):
  13. _VALID_URL = r'(?P<proto>https?)://(?:.+?\.)?xhamster\.com/movies/(?P<id>[0-9]+)/(?P<seo>.*?)\.html(?:\?.*)?'
  14. _TESTS = [{
  15. 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
  16. 'md5': '8281348b8d3c53d39fffb377d24eac4e',
  17. 'info_dict': {
  18. 'id': '1509445',
  19. 'ext': 'mp4',
  20. 'title': 'FemaleAgent Shy beauty takes the bait',
  21. 'upload_date': '20121014',
  22. 'uploader': 'Ruseful2011',
  23. 'duration': 893,
  24. 'age_limit': 18,
  25. 'categories': ['Fake Hub', 'Amateur', 'MILFs', 'POV', 'Boss', 'Office', 'Oral', 'Reality', 'Sexy'],
  26. },
  27. }, {
  28. 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
  29. 'info_dict': {
  30. 'id': '2221348',
  31. 'ext': 'mp4',
  32. 'title': 'Britney Spears Sexy Booty',
  33. 'upload_date': '20130914',
  34. 'uploader': 'jojo747400',
  35. 'duration': 200,
  36. 'age_limit': 18,
  37. 'categories': ['Britney Spears', 'Celebrities', 'HD Videos', 'Sexy', 'Sexy Booty'],
  38. },
  39. 'params': {
  40. 'skip_download': True,
  41. },
  42. }, {
  43. # empty seo
  44. 'url': 'http://xhamster.com/movies/5667973/.html',
  45. 'info_dict': {
  46. 'id': '5667973',
  47. 'ext': 'mp4',
  48. 'title': '....',
  49. 'upload_date': '20160208',
  50. 'uploader': 'parejafree',
  51. 'duration': 72,
  52. 'age_limit': 18,
  53. 'categories': ['Amateur', 'Blowjobs'],
  54. },
  55. 'params': {
  56. 'skip_download': True,
  57. },
  58. }, {
  59. 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
  60. 'only_matching': True,
  61. }, {
  62. # This video is visible for marcoalfa123456's friends only
  63. 'url': 'https://it.xhamster.com/movies/7263980/la_mia_vicina.html',
  64. 'only_matching': True,
  65. }]
  66. def _real_extract(self, url):
  67. def extract_video_url(webpage, name):
  68. return self._search_regex(
  69. [r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
  70. r'''<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumb''',
  71. r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
  72. webpage, name, group='mp4')
  73. def is_hd(webpage):
  74. return '<div class=\'icon iconHD\'' in webpage
  75. mobj = re.match(self._VALID_URL, url)
  76. video_id = mobj.group('id')
  77. seo = mobj.group('seo')
  78. proto = mobj.group('proto')
  79. mrss_url = '%s://xhamster.com/movies/%s/%s.html' % (proto, video_id, seo)
  80. webpage = self._download_webpage(mrss_url, video_id)
  81. error = self._html_search_regex(
  82. r'<div[^>]+id=["\']videoClosed["\'][^>]*>(.+?)</div>',
  83. webpage, 'error', default=None)
  84. if error:
  85. raise ExtractorError(error, expected=True)
  86. title = self._html_search_regex(
  87. [r'<h1[^>]*>([^<]+)</h1>',
  88. r'<meta[^>]+itemprop=".*?caption.*?"[^>]+content="(.+?)"',
  89. r'<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>'],
  90. webpage, 'title')
  91. # Only a few videos have an description
  92. mobj = re.search(r'<span>Description: </span>([^<]+)', webpage)
  93. description = mobj.group(1) if mobj else None
  94. upload_date = unified_strdate(self._search_regex(
  95. r'hint=["\'](\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}',
  96. webpage, 'upload date', fatal=False))
  97. uploader = self._html_search_regex(
  98. r'<span[^>]+itemprop=["\']author[^>]+><a[^>]+><span[^>]+>([^<]+)',
  99. webpage, 'uploader', default='anonymous')
  100. thumbnail = self._search_regex(
  101. [r'''thumb\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)''',
  102. r'''<video[^>]+poster=(?P<q>["'])(?P<thumbnail>.+?)(?P=q)[^>]*>'''],
  103. webpage, 'thumbnail', fatal=False, group='thumbnail')
  104. duration = parse_duration(self._search_regex(
  105. r'Runtime:\s*</span>\s*([\d:]+)', webpage,
  106. 'duration', fatal=False))
  107. view_count = int_or_none(self._search_regex(
  108. r'content=["\']User(?:View|Play)s:(\d+)',
  109. webpage, 'view count', fatal=False))
  110. mobj = re.search(r'hint=[\'"](?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes', webpage)
  111. (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
  112. mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
  113. comment_count = mobj.group('commentcount') if mobj else 0
  114. age_limit = self._rta_search(webpage)
  115. hd = is_hd(webpage)
  116. format_id = 'hd' if hd else 'sd'
  117. video_url = extract_video_url(webpage, format_id)
  118. formats = [{
  119. 'url': video_url,
  120. 'format_id': 'hd' if hd else 'sd',
  121. 'preference': 1,
  122. }]
  123. if not hd:
  124. mrss_url = self._search_regex(r'<link rel="canonical" href="([^"]+)', webpage, 'mrss_url')
  125. webpage = self._download_webpage(mrss_url + '?hd', video_id, note='Downloading HD webpage')
  126. if is_hd(webpage):
  127. video_url = extract_video_url(webpage, 'hd')
  128. formats.append({
  129. 'url': video_url,
  130. 'format_id': 'hd',
  131. 'preference': 2,
  132. })
  133. self._sort_formats(formats)
  134. categories_html = self._search_regex(
  135. r'(?s)<table.+?(<span>Categories:.+?)</table>', webpage,
  136. 'categories', default=None)
  137. categories = [clean_html(category) for category in re.findall(
  138. r'<a[^>]+>(.+?)</a>', categories_html)] if categories_html else None
  139. return {
  140. 'id': video_id,
  141. 'title': title,
  142. 'description': description,
  143. 'upload_date': upload_date,
  144. 'uploader': uploader,
  145. 'thumbnail': thumbnail,
  146. 'duration': duration,
  147. 'view_count': view_count,
  148. 'like_count': int_or_none(like_count),
  149. 'dislike_count': int_or_none(dislike_count),
  150. 'comment_count': int_or_none(comment_count),
  151. 'age_limit': age_limit,
  152. 'categories': categories,
  153. 'formats': formats,
  154. }
  155. class XHamsterEmbedIE(InfoExtractor):
  156. _VALID_URL = r'https?://(?:www\.)?xhamster\.com/xembed\.php\?video=(?P<id>\d+)'
  157. _TEST = {
  158. 'url': 'http://xhamster.com/xembed.php?video=3328539',
  159. 'info_dict': {
  160. 'id': '3328539',
  161. 'ext': 'mp4',
  162. 'title': 'Pen Masturbation',
  163. 'upload_date': '20140728',
  164. 'uploader_id': 'anonymous',
  165. 'duration': 5,
  166. 'age_limit': 18,
  167. }
  168. }
  169. @staticmethod
  170. def _extract_urls(webpage):
  171. return [url for _, url in re.findall(
  172. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
  173. webpage)]
  174. def _real_extract(self, url):
  175. video_id = self._match_id(url)
  176. webpage = self._download_webpage(url, video_id)
  177. video_url = self._search_regex(
  178. r'href="(https?://xhamster\.com/movies/%s/[^"]*\.html[^"]*)"' % video_id,
  179. webpage, 'xhamster url', default=None)
  180. if not video_url:
  181. vars = self._parse_json(
  182. self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
  183. video_id)
  184. video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
  185. return self.url_result(video_url, 'XHamster')