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.

114 lines
4.2 KiB

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