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.

94 lines
3.6 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_request,
  6. )
  7. from ..utils import (
  8. int_or_none,
  9. )
  10. class PornotubeIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:\w+\.)?pornotube\.com/(?:[^?#]*?)/video/(?P<id>[0-9]+)'
  12. _TEST = {
  13. 'url': 'http://www.pornotube.com/orientation/straight/video/4964/title/weird-hot-and-wet-science',
  14. 'md5': '60fc5a4f0d93a97968fc7999d98260c9',
  15. 'info_dict': {
  16. 'id': '4964',
  17. 'ext': 'mp4',
  18. 'upload_date': '20141203',
  19. 'title': 'Weird Hot and Wet Science',
  20. 'description': 'md5:a8304bef7ef06cb4ab476ca6029b01b0',
  21. 'categories': ['Adult Humor', 'Blondes'],
  22. 'uploader': 'Alpha Blue Archives',
  23. 'thumbnail': 're:^https?://.*\\.jpg$',
  24. 'timestamp': 1417582800,
  25. 'age_limit': 18,
  26. }
  27. }
  28. def _real_extract(self, url):
  29. video_id = self._match_id(url)
  30. # Fetch origin token
  31. js_config = self._download_webpage(
  32. 'http://www.pornotube.com/assets/src/app/config.js', video_id,
  33. note='Download JS config')
  34. originAuthenticationSpaceKey = self._search_regex(
  35. r"constant\('originAuthenticationSpaceKey',\s*'([^']+)'",
  36. js_config, 'originAuthenticationSpaceKey')
  37. # Fetch actual token
  38. token_req_data = {
  39. 'authenticationSpaceKey': originAuthenticationSpaceKey,
  40. 'credentials': 'Clip Application',
  41. }
  42. token_req = compat_urllib_request.Request(
  43. 'https://api.aebn.net/auth/v1/token/primal',
  44. data=json.dumps(token_req_data).encode('utf-8'))
  45. token_req.add_header('Content-Type', 'application/json')
  46. token_req.add_header('Origin', 'http://www.pornotube.com')
  47. token_answer = self._download_json(
  48. token_req, video_id, note='Requesting primal token')
  49. token = token_answer['tokenKey']
  50. # Get video URL
  51. delivery_req = compat_urllib_request.Request(
  52. 'https://api.aebn.net/delivery/v1/clips/%s/MP4' % video_id)
  53. delivery_req.add_header('Authorization', token)
  54. delivery_info = self._download_json(
  55. delivery_req, video_id, note='Downloading delivery information')
  56. video_url = delivery_info['mediaUrl']
  57. # Get additional info (title etc.)
  58. info_req = compat_urllib_request.Request(
  59. 'https://api.aebn.net/content/v1/clips/%s?expand='
  60. 'title,description,primaryImageNumber,startSecond,endSecond,'
  61. 'movie.title,movie.MovieId,movie.boxCoverFront,movie.stars,'
  62. 'movie.studios,stars.name,studios.name,categories.name,'
  63. 'clipActive,movieActive,publishDate,orientations' % video_id)
  64. info_req.add_header('Authorization', token)
  65. info = self._download_json(
  66. info_req, video_id, note='Downloading metadata')
  67. timestamp = int_or_none(info.get('publishDate'), scale=1000)
  68. uploader = info.get('studios', [{}])[0].get('name')
  69. movie_id = info['movie']['movieId']
  70. thumbnail = 'http://pic.aebn.net/dis/t/%s/%s_%08d.jpg' % (
  71. movie_id, movie_id, info['primaryImageNumber'])
  72. categories = [c['name'] for c in info.get('categories')]
  73. return {
  74. 'id': video_id,
  75. 'url': video_url,
  76. 'title': info['title'],
  77. 'description': info.get('description'),
  78. 'timestamp': timestamp,
  79. 'uploader': uploader,
  80. 'thumbnail': thumbnail,
  81. 'categories': categories,
  82. 'age_limit': 18,
  83. }