youporn.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. extract_attributes,
  5. int_or_none,
  6. merge_dicts,
  7. str_to_int,
  8. unified_strdate,
  9. url_or_none,
  10. )
  11. class YouPornIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?youporn\.com/(?:watch|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?'
  13. _EMBED_REGEX = [r'<iframe[^>]+\bsrc=["\'](?P<url>(?:https?:)?//(?:www\.)?youporn\.com/embed/\d+)']
  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. 'duration': 210,
  25. 'uploader': 'Ask Dan And Jennifer',
  26. 'upload_date': '20101217',
  27. 'average_rating': int,
  28. 'view_count': int,
  29. 'categories': list,
  30. 'tags': list,
  31. 'age_limit': 18,
  32. },
  33. 'skip': 'This video has been disabled',
  34. }, {
  35. # Unknown uploader
  36. 'url': 'http://www.youporn.com/watch/561726/big-tits-awesome-brunette-on-amazing-webcam-show/?from=related3&al=2&from_id=561726&pos=4',
  37. 'info_dict': {
  38. 'id': '561726',
  39. 'display_id': 'big-tits-awesome-brunette-on-amazing-webcam-show',
  40. 'ext': 'mp4',
  41. 'title': 'Big Tits Awesome Brunette On amazing webcam show',
  42. 'description': 'http://sweetlivegirls.com Big Tits Awesome Brunette On amazing webcam show.mp4',
  43. 'thumbnail': r're:^https?://.*\.jpg$',
  44. 'uploader': 'Unknown',
  45. 'upload_date': '20110418',
  46. 'average_rating': int,
  47. 'view_count': int,
  48. 'categories': list,
  49. 'tags': list,
  50. 'age_limit': 18,
  51. },
  52. 'params': {
  53. 'skip_download': True,
  54. },
  55. 'skip': '404',
  56. }, {
  57. 'url': 'https://www.youporn.com/embed/505835/sex-ed-is-it-safe-to-masturbate-daily/',
  58. 'only_matching': True,
  59. }, {
  60. 'url': 'http://www.youporn.com/watch/505835',
  61. 'only_matching': True,
  62. }, {
  63. 'url': 'https://www.youporn.com/watch/13922959/femdom-principal/',
  64. 'only_matching': True,
  65. }, {
  66. 'url': 'https://www.youporn.com/watch/16290308/tinderspecial-trailer1/',
  67. 'info_dict': {
  68. 'id': '16290308',
  69. 'age_limit': 18,
  70. 'categories': [],
  71. 'description': 'md5:00ea70f642f431c379763c17c2f396bc',
  72. 'display_id': 'tinderspecial-trailer1',
  73. 'duration': 298.0,
  74. 'ext': 'mp4',
  75. 'upload_date': '20201123',
  76. 'uploader': 'Ersties',
  77. 'tags': [],
  78. 'thumbnail': 'https://fi1.ypncdn.com/202011/23/16290308/original/8/tinderspecial-trailer1-8(m=eaAaaEPbaaaa).jpg',
  79. 'timestamp': 1606089600,
  80. 'title': 'Tinder In Real Life',
  81. 'view_count': int,
  82. }
  83. }]
  84. def _real_extract(self, url):
  85. mobj = self._match_valid_url(url)
  86. video_id = mobj.group('id')
  87. display_id = mobj.group('display_id') or video_id
  88. definitions = self._download_json(
  89. 'https://www.youporn.com/api/video/media_definitions/%s/' % video_id,
  90. display_id)
  91. formats = []
  92. for definition in definitions:
  93. if not isinstance(definition, dict):
  94. continue
  95. video_url = url_or_none(definition.get('videoUrl'))
  96. if not video_url:
  97. continue
  98. f = {
  99. 'url': video_url,
  100. 'filesize': int_or_none(definition.get('videoSize')),
  101. }
  102. height = int_or_none(definition.get('quality'))
  103. # Video URL's path looks like this:
  104. # /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
  105. # /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
  106. # /videos/201703/11/109285532/1080P_4000K_109285532.mp4
  107. # We will benefit from it by extracting some metadata
  108. mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+', video_url)
  109. if mobj:
  110. if not height:
  111. height = int(mobj.group('height'))
  112. bitrate = int(mobj.group('bitrate'))
  113. f.update({
  114. 'format_id': '%dp-%dk' % (height, bitrate),
  115. 'tbr': bitrate,
  116. })
  117. f['height'] = height
  118. formats.append(f)
  119. webpage = self._download_webpage(
  120. 'http://www.youporn.com/watch/%s' % video_id, display_id,
  121. headers={'Cookie': 'age_verified=1'})
  122. title = self._html_search_regex(
  123. r'(?s)<div[^>]+class=["\']watchVideoTitle[^>]+>(.+?)</div>',
  124. webpage, 'title', default=None) or self._og_search_title(
  125. webpage, default=None) or self._html_search_meta(
  126. 'title', webpage, fatal=True)
  127. description = self._html_search_regex(
  128. r'(?s)<div[^>]+\bid=["\']description["\'][^>]*>(.+?)</div>',
  129. webpage, 'description',
  130. default=None) or self._og_search_description(
  131. webpage, default=None)
  132. thumbnail = self._search_regex(
  133. r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P<thumbnail>.+?)\1',
  134. webpage, 'thumbnail', fatal=False, group='thumbnail')
  135. duration = int_or_none(self._html_search_meta(
  136. 'video:duration', webpage, 'duration', fatal=False))
  137. uploader = self._html_search_regex(
  138. r'(?s)<div[^>]+class=["\']submitByLink["\'][^>]*>(.+?)</div>',
  139. webpage, 'uploader', fatal=False)
  140. upload_date = unified_strdate(self._html_search_regex(
  141. (r'UPLOADED:\s*<span>([^<]+)',
  142. r'Date\s+[Aa]dded:\s*<span>([^<]+)',
  143. r'''(?s)<div[^>]+class=["']videoInfo(?:Date|Time)\b[^>]*>(.+?)</div>''',
  144. r'(?s)<label\b[^>]*>Uploaded[^<]*</label>\s*<span\b[^>]*>(.+?)</span>'),
  145. webpage, 'upload date', fatal=False))
  146. age_limit = self._rta_search(webpage)
  147. view_count = None
  148. views = self._search_regex(
  149. r'(<div[^>]+\bclass=["\']js_videoInfoViews["\']>)', webpage,
  150. 'views', default=None)
  151. if views:
  152. view_count = str_to_int(extract_attributes(views).get('data-value'))
  153. comment_count = str_to_int(self._search_regex(
  154. r'>All [Cc]omments? \(([\d,.]+)\)',
  155. webpage, 'comment count', default=None))
  156. def extract_tag_box(regex, title):
  157. tag_box = self._search_regex(regex, webpage, title, default=None)
  158. if not tag_box:
  159. return []
  160. return re.findall(r'<a[^>]+href=[^>]+>([^<]+)', tag_box)
  161. categories = extract_tag_box(
  162. r'(?s)Categories:.*?</[^>]+>(.+?)</div>', 'categories')
  163. tags = extract_tag_box(
  164. r'(?s)Tags:.*?</div>\s*<div[^>]+class=["\']tagBoxContent["\'][^>]*>(.+?)</div>',
  165. 'tags')
  166. data = self._search_json_ld(webpage, video_id, expected_type='VideoObject', fatal=False)
  167. return merge_dicts(data, {
  168. 'id': video_id,
  169. 'display_id': display_id,
  170. 'title': title,
  171. 'description': description,
  172. 'thumbnail': thumbnail,
  173. 'duration': duration,
  174. 'uploader': uploader,
  175. 'upload_date': upload_date,
  176. 'view_count': view_count,
  177. 'comment_count': comment_count,
  178. 'categories': categories,
  179. 'tags': tags,
  180. 'age_limit': age_limit,
  181. 'formats': formats,
  182. })