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.

118 lines
4.3 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. import sys
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. compat_urllib_parse_urlparse,
  8. compat_urllib_request,
  9. ExtractorError,
  10. unescapeHTML,
  11. unified_strdate,
  12. )
  13. from ..aes import (
  14. aes_decrypt_text
  15. )
  16. class YouPornIE(InfoExtractor):
  17. _VALID_URL = r'^(?P<proto>https?://)(?:www\.)?(?P<url>youporn\.com/watch/(?P<videoid>[0-9]+)/(?P<title>[^/]+))'
  18. _TEST = {
  19. 'url': 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
  20. 'md5': '71ec5fcfddacf80f495efa8b6a8d9a89',
  21. 'info_dict': {
  22. 'id': '505835',
  23. 'ext': 'mp4',
  24. 'upload_date': '20101221',
  25. 'description': 'Love & Sex Answers: http://bit.ly/DanAndJenn -- Is It Unhealthy To Masturbate Daily?',
  26. 'uploader': 'Ask Dan And Jennifer',
  27. 'title': 'Sex Ed: Is It Safe To Masturbate Daily?',
  28. 'age_limit': 18,
  29. }
  30. }
  31. def _real_extract(self, url):
  32. mobj = re.match(self._VALID_URL, url)
  33. video_id = mobj.group('videoid')
  34. url = mobj.group('proto') + 'www.' + mobj.group('url')
  35. req = compat_urllib_request.Request(url)
  36. req.add_header('Cookie', 'age_verified=1')
  37. webpage = self._download_webpage(req, video_id)
  38. age_limit = self._rta_search(webpage)
  39. # Get JSON parameters
  40. json_params = self._search_regex(r'var currentVideo = new Video\((.*)\);', webpage, 'JSON parameters')
  41. try:
  42. params = json.loads(json_params)
  43. except:
  44. raise ExtractorError(u'Invalid JSON')
  45. self.report_extraction(video_id)
  46. try:
  47. video_title = params['title']
  48. upload_date = unified_strdate(params['release_date_f'])
  49. video_description = params['description']
  50. video_uploader = params['submitted_by']
  51. thumbnail = params['thumbnails'][0]['image']
  52. except KeyError:
  53. raise ExtractorError('Missing JSON parameter: ' + sys.exc_info()[1])
  54. # Get all of the links from the page
  55. DOWNLOAD_LIST_RE = r'(?s)<ul class="downloadList">(?P<download_list>.*?)</ul>'
  56. download_list_html = self._search_regex(DOWNLOAD_LIST_RE,
  57. webpage, 'download list').strip()
  58. LINK_RE = r'<a href="([^"]+)">'
  59. links = re.findall(LINK_RE, download_list_html)
  60. # Get all encrypted links
  61. encrypted_links = re.findall(r'var encryptedQuality[0-9]{3}URL = \'([a-zA-Z0-9+/]+={0,2})\';', webpage)
  62. for encrypted_link in encrypted_links:
  63. link = aes_decrypt_text(encrypted_link, video_title, 32).decode('utf-8')
  64. links.append(link)
  65. formats = []
  66. for link in links:
  67. # A link looks like this:
  68. # http://cdn1.download.youporn.phncdn.com/201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4?nvb=20121113051249&nva=20121114051249&ir=1200&sr=1200&hash=014b882080310e95fb6a0
  69. # A path looks like this:
  70. # /201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4
  71. video_url = unescapeHTML(link)
  72. path = compat_urllib_parse_urlparse(video_url).path
  73. format_parts = path.split('/')[4].split('_')[:2]
  74. dn = compat_urllib_parse_urlparse(video_url).netloc.partition('.')[0]
  75. resolution = format_parts[0]
  76. height = int(resolution[:-len('p')])
  77. bitrate = int(format_parts[1][:-len('k')])
  78. format = '-'.join(format_parts) + '-' + dn
  79. formats.append({
  80. 'url': video_url,
  81. 'format': format,
  82. 'format_id': format,
  83. 'height': height,
  84. 'tbr': bitrate,
  85. 'resolution': resolution,
  86. })
  87. self._sort_formats(formats)
  88. if not formats:
  89. raise ExtractorError(u'ERROR: no known formats available for video')
  90. return {
  91. 'id': video_id,
  92. 'uploader': video_uploader,
  93. 'upload_date': upload_date,
  94. 'title': video_title,
  95. 'thumbnail': thumbnail,
  96. 'description': video_description,
  97. 'age_limit': age_limit,
  98. 'formats': formats,
  99. }