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