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.

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