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.

203 lines
8.0 KiB

10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. str_to_int,
  7. unescapeHTML,
  8. unified_strdate,
  9. url_or_none,
  10. )
  11. from ..aes import aes_decrypt_text
  12. class YouPornIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?youporn\.com/(?:watch|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?'
  14. _TESTS = [{
  15. 'url': 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
  16. 'md5': '3744d24c50438cf5b6f6d59feb5055c2',
  17. 'info_dict': {
  18. 'id': '505835',
  19. 'display_id': 'sex-ed-is-it-safe-to-masturbate-daily',
  20. 'ext': 'mp4',
  21. 'title': 'Sex Ed: Is It Safe To Masturbate Daily?',
  22. 'description': 'Love & Sex Answers: http://bit.ly/DanAndJenn -- Is It Unhealthy To Masturbate Daily?',
  23. 'thumbnail': r're:^https?://.*\.jpg$',
  24. 'uploader': 'Ask Dan And Jennifer',
  25. 'upload_date': '20101217',
  26. 'average_rating': int,
  27. 'view_count': int,
  28. 'comment_count': int,
  29. 'categories': list,
  30. 'tags': list,
  31. 'age_limit': 18,
  32. },
  33. }, {
  34. # Unknown uploader
  35. 'url': 'http://www.youporn.com/watch/561726/big-tits-awesome-brunette-on-amazing-webcam-show/?from=related3&al=2&from_id=561726&pos=4',
  36. 'info_dict': {
  37. 'id': '561726',
  38. 'display_id': 'big-tits-awesome-brunette-on-amazing-webcam-show',
  39. 'ext': 'mp4',
  40. 'title': 'Big Tits Awesome Brunette On amazing webcam show',
  41. 'description': 'http://sweetlivegirls.com Big Tits Awesome Brunette On amazing webcam show.mp4',
  42. 'thumbnail': r're:^https?://.*\.jpg$',
  43. 'uploader': 'Unknown',
  44. 'upload_date': '20110418',
  45. 'average_rating': int,
  46. 'view_count': int,
  47. 'comment_count': int,
  48. 'categories': list,
  49. 'tags': list,
  50. 'age_limit': 18,
  51. },
  52. 'params': {
  53. 'skip_download': True,
  54. },
  55. }, {
  56. 'url': 'https://www.youporn.com/embed/505835/sex-ed-is-it-safe-to-masturbate-daily/',
  57. 'only_matching': True,
  58. }, {
  59. 'url': 'http://www.youporn.com/watch/505835',
  60. 'only_matching': True,
  61. }]
  62. @staticmethod
  63. def _extract_urls(webpage):
  64. return re.findall(
  65. r'<iframe[^>]+\bsrc=["\']((?:https?:)?//(?:www\.)?youporn\.com/embed/\d+)',
  66. webpage)
  67. def _real_extract(self, url):
  68. mobj = re.match(self._VALID_URL, url)
  69. video_id = mobj.group('id')
  70. display_id = mobj.group('display_id') or video_id
  71. webpage = self._download_webpage(
  72. 'http://www.youporn.com/watch/%s' % video_id, display_id,
  73. headers={'Cookie': 'age_verified=1'})
  74. title = self._html_search_regex(
  75. r'(?s)<div[^>]+class=["\']watchVideoTitle[^>]+>(.+?)</div>',
  76. webpage, 'title', default=None) or self._og_search_title(
  77. webpage, default=None) or self._html_search_meta(
  78. 'title', webpage, fatal=True)
  79. links = []
  80. # Main source
  81. definitions = self._parse_json(
  82. self._search_regex(
  83. r'mediaDefinition\s*=\s*(\[.+?\]);', webpage,
  84. 'media definitions', default='[]'),
  85. video_id, fatal=False)
  86. if definitions:
  87. for definition in definitions:
  88. if not isinstance(definition, dict):
  89. continue
  90. video_url = url_or_none(definition.get('videoUrl'))
  91. if video_url:
  92. links.append(video_url)
  93. # Fallback #1, this also contains extra low quality 180p format
  94. for _, link in re.findall(r'<a[^>]+href=(["\'])(http.+?)\1[^>]+title=["\']Download [Vv]ideo', webpage):
  95. links.append(link)
  96. # Fallback #2 (unavailable as at 22.06.2017)
  97. sources = self._search_regex(
  98. r'(?s)sources\s*:\s*({.+?})', webpage, 'sources', default=None)
  99. if sources:
  100. for _, link in re.findall(r'[^:]+\s*:\s*(["\'])(http.+?)\1', sources):
  101. links.append(link)
  102. # Fallback #3 (unavailable as at 22.06.2017)
  103. for _, link in re.findall(
  104. r'(?:videoSrc|videoIpadUrl|html5PlayerSrc)\s*[:=]\s*(["\'])(http.+?)\1', webpage):
  105. links.append(link)
  106. # Fallback #4, encrypted links (unavailable as at 22.06.2017)
  107. for _, encrypted_link in re.findall(
  108. r'encryptedQuality\d{3,4}URL\s*=\s*(["\'])([\da-zA-Z+/=]+)\1', webpage):
  109. links.append(aes_decrypt_text(encrypted_link, title, 32).decode('utf-8'))
  110. formats = []
  111. for video_url in set(unescapeHTML(link) for link in links):
  112. f = {
  113. 'url': video_url,
  114. }
  115. # Video URL's path looks like this:
  116. # /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
  117. # /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
  118. # We will benefit from it by extracting some metadata
  119. mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+/', video_url)
  120. if mobj:
  121. height = int(mobj.group('height'))
  122. bitrate = int(mobj.group('bitrate'))
  123. f.update({
  124. 'format_id': '%dp-%dk' % (height, bitrate),
  125. 'height': height,
  126. 'tbr': bitrate,
  127. })
  128. formats.append(f)
  129. self._sort_formats(formats)
  130. description = self._html_search_regex(
  131. r'(?s)<div[^>]+\bid=["\']description["\'][^>]*>(.+?)</div>',
  132. webpage, 'description',
  133. default=None) or self._og_search_description(
  134. webpage, default=None)
  135. thumbnail = self._search_regex(
  136. r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P<thumbnail>.+?)\1',
  137. webpage, 'thumbnail', fatal=False, group='thumbnail')
  138. uploader = self._html_search_regex(
  139. r'(?s)<div[^>]+class=["\']submitByLink["\'][^>]*>(.+?)</div>',
  140. webpage, 'uploader', fatal=False)
  141. upload_date = unified_strdate(self._html_search_regex(
  142. [r'Date\s+[Aa]dded:\s*<span>([^<]+)',
  143. r'(?s)<div[^>]+class=["\']videoInfo(?:Date|Time)["\'][^>]*>(.+?)</div>'],
  144. webpage, 'upload date', fatal=False))
  145. age_limit = self._rta_search(webpage)
  146. average_rating = int_or_none(self._search_regex(
  147. r'<div[^>]+class=["\']videoRatingPercentage["\'][^>]*>(\d+)%</div>',
  148. webpage, 'average rating', fatal=False))
  149. view_count = str_to_int(self._search_regex(
  150. r'(?s)<div[^>]+class=(["\']).*?\bvideoInfoViews\b.*?\1[^>]*>.*?(?P<count>[\d,.]+)<',
  151. webpage, 'view count', fatal=False, group='count'))
  152. comment_count = str_to_int(self._search_regex(
  153. r'>All [Cc]omments? \(([\d,.]+)\)',
  154. webpage, 'comment count', fatal=False))
  155. def extract_tag_box(regex, title):
  156. tag_box = self._search_regex(regex, webpage, title, default=None)
  157. if not tag_box:
  158. return []
  159. return re.findall(r'<a[^>]+href=[^>]+>([^<]+)', tag_box)
  160. categories = extract_tag_box(
  161. r'(?s)Categories:.*?</[^>]+>(.+?)</div>', 'categories')
  162. tags = extract_tag_box(
  163. r'(?s)Tags:.*?</div>\s*<div[^>]+class=["\']tagBoxContent["\'][^>]*>(.+?)</div>',
  164. 'tags')
  165. return {
  166. 'id': video_id,
  167. 'display_id': display_id,
  168. 'title': title,
  169. 'description': description,
  170. 'thumbnail': thumbnail,
  171. 'uploader': uploader,
  172. 'upload_date': upload_date,
  173. 'average_rating': average_rating,
  174. 'view_count': view_count,
  175. 'comment_count': comment_count,
  176. 'categories': categories,
  177. 'tags': tags,
  178. 'age_limit': age_limit,
  179. 'formats': formats,
  180. }