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.

119 lines
4.3 KiB

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