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