logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

youporn.py (7395B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. extract_attributes,
  7. int_or_none,
  8. str_to_int,
  9. unified_strdate,
  10. url_or_none,
  11. )
  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. '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. @staticmethod
  67. def _extract_urls(webpage):
  68. return re.findall(
  69. r'<iframe[^>]+\bsrc=["\']((?:https?:)?//(?:www\.)?youporn\.com/embed/\d+)',
  70. webpage)
  71. def _real_extract(self, url):
  72. mobj = re.match(self._VALID_URL, url)
  73. video_id = mobj.group('id')
  74. display_id = mobj.group('display_id') or video_id
  75. definitions = self._download_json(
  76. 'https://www.youporn.com/api/video/media_definitions/%s/' % video_id,
  77. display_id)
  78. formats = []
  79. for definition in definitions:
  80. if not isinstance(definition, dict):
  81. continue
  82. video_url = url_or_none(definition.get('videoUrl'))
  83. if not video_url:
  84. continue
  85. f = {
  86. 'url': video_url,
  87. 'filesize': int_or_none(definition.get('videoSize')),
  88. }
  89. height = int_or_none(definition.get('quality'))
  90. # Video URL's path looks like this:
  91. # /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
  92. # /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
  93. # /videos/201703/11/109285532/1080P_4000K_109285532.mp4
  94. # We will benefit from it by extracting some metadata
  95. mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+', video_url)
  96. if mobj:
  97. if not height:
  98. height = int(mobj.group('height'))
  99. bitrate = int(mobj.group('bitrate'))
  100. f.update({
  101. 'format_id': '%dp-%dk' % (height, bitrate),
  102. 'tbr': bitrate,
  103. })
  104. f['height'] = height
  105. formats.append(f)
  106. self._sort_formats(formats)
  107. webpage = self._download_webpage(
  108. 'http://www.youporn.com/watch/%s' % video_id, display_id,
  109. headers={'Cookie': 'age_verified=1'})
  110. title = self._html_search_regex(
  111. r'(?s)<div[^>]+class=["\']watchVideoTitle[^>]+>(.+?)</div>',
  112. webpage, 'title', default=None) or self._og_search_title(
  113. webpage, default=None) or self._html_search_meta(
  114. 'title', webpage, fatal=True)
  115. description = self._html_search_regex(
  116. r'(?s)<div[^>]+\bid=["\']description["\'][^>]*>(.+?)</div>',
  117. webpage, 'description',
  118. default=None) or self._og_search_description(
  119. webpage, default=None)
  120. thumbnail = self._search_regex(
  121. r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P<thumbnail>.+?)\1',
  122. webpage, 'thumbnail', fatal=False, group='thumbnail')
  123. duration = int_or_none(self._html_search_meta(
  124. 'video:duration', webpage, 'duration', fatal=False))
  125. uploader = self._html_search_regex(
  126. r'(?s)<div[^>]+class=["\']submitByLink["\'][^>]*>(.+?)</div>',
  127. webpage, 'uploader', fatal=False)
  128. upload_date = unified_strdate(self._html_search_regex(
  129. (r'UPLOADED:\s*<span>([^<]+)',
  130. r'Date\s+[Aa]dded:\s*<span>([^<]+)',
  131. r'''(?s)<div[^>]+class=["']videoInfo(?:Date|Time)\b[^>]*>(.+?)</div>''',
  132. r'(?s)<label\b[^>]*>Uploaded[^<]*</label>\s*<span\b[^>]*>(.+?)</span>'),
  133. webpage, 'upload date', fatal=False))
  134. age_limit = self._rta_search(webpage)
  135. view_count = None
  136. views = self._search_regex(
  137. r'(<div[^>]+\bclass=["\']js_videoInfoViews["\']>)', webpage,
  138. 'views', default=None)
  139. if views:
  140. view_count = str_to_int(extract_attributes(views).get('data-value'))
  141. comment_count = str_to_int(self._search_regex(
  142. r'>All [Cc]omments? \(([\d,.]+)\)',
  143. webpage, 'comment count', default=None))
  144. def extract_tag_box(regex, title):
  145. tag_box = self._search_regex(regex, webpage, title, default=None)
  146. if not tag_box:
  147. return []
  148. return re.findall(r'<a[^>]+href=[^>]+>([^<]+)', tag_box)
  149. categories = extract_tag_box(
  150. r'(?s)Categories:.*?</[^>]+>(.+?)</div>', 'categories')
  151. tags = extract_tag_box(
  152. r'(?s)Tags:.*?</div>\s*<div[^>]+class=["\']tagBoxContent["\'][^>]*>(.+?)</div>',
  153. 'tags')
  154. return {
  155. 'id': video_id,
  156. 'display_id': display_id,
  157. 'title': title,
  158. 'description': description,
  159. 'thumbnail': thumbnail,
  160. 'duration': duration,
  161. 'uploader': uploader,
  162. 'upload_date': upload_date,
  163. 'view_count': view_count,
  164. 'comment_count': comment_count,
  165. 'categories': categories,
  166. 'tags': tags,
  167. 'age_limit': age_limit,
  168. 'formats': formats,
  169. }