pornotube.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import json
  2. from .common import InfoExtractor
  3. from ..utils import int_or_none
  4. class PornotubeIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:\w+\.)?pornotube\.com/(?:[^?#]*?)/video/(?P<id>[0-9]+)'
  6. _TEST = {
  7. 'url': 'http://www.pornotube.com/orientation/straight/video/4964/title/weird-hot-and-wet-science',
  8. 'md5': '60fc5a4f0d93a97968fc7999d98260c9',
  9. 'info_dict': {
  10. 'id': '4964',
  11. 'ext': 'mp4',
  12. 'upload_date': '20141203',
  13. 'title': 'Weird Hot and Wet Science',
  14. 'description': 'md5:a8304bef7ef06cb4ab476ca6029b01b0',
  15. 'categories': ['Adult Humor', 'Blondes'],
  16. 'uploader': 'Alpha Blue Archives',
  17. 'thumbnail': r're:^https?://.*\.jpg$',
  18. 'timestamp': 1417582800,
  19. 'age_limit': 18,
  20. },
  21. }
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. token = self._download_json(
  25. 'https://api.aebn.net/auth/v2/origins/authenticate',
  26. video_id, note='Downloading token',
  27. data=json.dumps({'credentials': 'Clip Application'}).encode(),
  28. headers={
  29. 'Content-Type': 'application/json',
  30. 'Origin': 'http://www.pornotube.com',
  31. })['tokenKey']
  32. video_url = self._download_json(
  33. f'https://api.aebn.net/delivery/v1/clips/{video_id}/MP4',
  34. video_id, note='Downloading delivery information',
  35. headers={'Authorization': token})['mediaUrl']
  36. FIELDS = (
  37. 'title', 'description', 'startSecond', 'endSecond', 'publishDate',
  38. 'studios{name}', 'categories{name}', 'movieId', 'primaryImageNumber',
  39. )
  40. info = self._download_json(
  41. 'https://api.aebn.net/content/v2/clips/{}?fields={}'.format(video_id, ','.join(FIELDS)), video_id,
  42. note='Downloading metadata',
  43. headers={'Authorization': token})
  44. if isinstance(info, list):
  45. info = info[0]
  46. title = info['title']
  47. timestamp = int_or_none(info.get('publishDate'), scale=1000)
  48. uploader = info.get('studios', [{}])[0].get('name')
  49. movie_id = info.get('movieId')
  50. primary_image_number = info.get('primaryImageNumber')
  51. thumbnail = None
  52. if movie_id and primary_image_number:
  53. thumbnail = 'http://pic.aebn.net/dis/t/%s/%s_%08d.jpg' % (
  54. movie_id, movie_id, primary_image_number)
  55. start = int_or_none(info.get('startSecond'))
  56. end = int_or_none(info.get('endSecond'))
  57. duration = end - start if start and end else None
  58. categories = [c['name'] for c in info.get('categories', []) if c.get('name')]
  59. return {
  60. 'id': video_id,
  61. 'url': video_url,
  62. 'title': title,
  63. 'description': info.get('description'),
  64. 'duration': duration,
  65. 'timestamp': timestamp,
  66. 'uploader': uploader,
  67. 'thumbnail': thumbnail,
  68. 'categories': categories,
  69. 'age_limit': 18,
  70. }