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