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.

120 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 ..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'var videoJason = (.*)[,;]',
  43. webpage, 'JSON parameters')
  44. try:
  45. params = json.loads(json_params)
  46. except:
  47. raise ExtractorError('Invalid JSON')
  48. self.report_extraction(video_id)
  49. try:
  50. video_title = params['title']
  51. upload_date = unified_strdate(params['release_date_f'])
  52. video_description = params['description']
  53. video_uploader = params['submitted_by']
  54. thumbnail = params['thumbnails'][0]['image']
  55. except KeyError:
  56. raise ExtractorError('Missing JSON parameter: ' + sys.exc_info()[1])
  57. # Get all of the links from the page
  58. DOWNLOAD_LIST_RE = r'(?s)<ul class="downloadList">(?P<download_list>.*?)</ul>'
  59. download_list_html = self._search_regex(DOWNLOAD_LIST_RE,
  60. webpage, 'download list').strip()
  61. LINK_RE = r'<a href="([^"]+)">'
  62. links = re.findall(LINK_RE, download_list_html)
  63. # Get all encrypted links
  64. encrypted_links = re.findall(r'var encryptedQuality[0-9]{3}URL = \'([a-zA-Z0-9+/]+={0,2})\';', webpage)
  65. for encrypted_link in encrypted_links:
  66. link = aes_decrypt_text(encrypted_link, video_title, 32).decode('utf-8')
  67. links.append(link)
  68. formats = []
  69. for link in links:
  70. # A link looks like this:
  71. # 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
  72. # A path looks like this:
  73. # /201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4
  74. video_url = unescapeHTML(link)
  75. path = compat_urllib_parse_urlparse(video_url).path
  76. format_parts = path.split('/')[4].split('_')[:2]
  77. dn = compat_urllib_parse_urlparse(video_url).netloc.partition('.')[0]
  78. resolution = format_parts[0]
  79. height = int(resolution[:-len('p')])
  80. bitrate = int(format_parts[1][:-len('k')])
  81. format = '-'.join(format_parts) + '-' + dn
  82. formats.append({
  83. 'url': video_url,
  84. 'format': format,
  85. 'format_id': format,
  86. 'height': height,
  87. 'tbr': bitrate,
  88. 'resolution': resolution,
  89. })
  90. self._sort_formats(formats)
  91. if not formats:
  92. raise ExtractorError('ERROR: no known formats available for video')
  93. return {
  94. 'id': video_id,
  95. 'uploader': video_uploader,
  96. 'upload_date': upload_date,
  97. 'title': video_title,
  98. 'thumbnail': thumbnail,
  99. 'description': video_description,
  100. 'age_limit': age_limit,
  101. 'formats': formats,
  102. }