]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/beeg.py
New upstream version 2019.06.08
[youtubedl] / youtube_dl / extractor / beeg.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import compat_str
5 from ..utils import (
6 int_or_none,
7 unified_timestamp,
8 )
9
10
11 class BeegIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?beeg\.(?:com|porn(?:/video)?)/(?P<id>\d+)'
13 _TESTS = [{
14 'url': 'http://beeg.com/5416503',
15 'md5': 'a1a1b1a8bc70a89e49ccfd113aed0820',
16 'info_dict': {
17 'id': '5416503',
18 'ext': 'mp4',
19 'title': 'Sultry Striptease',
20 'description': 'md5:d22219c09da287c14bed3d6c37ce4bc2',
21 'timestamp': 1391813355,
22 'upload_date': '20140207',
23 'duration': 383,
24 'tags': list,
25 'age_limit': 18,
26 }
27 }, {
28 'url': 'https://beeg.porn/video/5416503',
29 'only_matching': True,
30 }, {
31 'url': 'https://beeg.porn/5416503',
32 'only_matching': True,
33 }]
34
35 def _real_extract(self, url):
36 video_id = self._match_id(url)
37
38 webpage = self._download_webpage(url, video_id)
39
40 beeg_version = self._search_regex(
41 r'beeg_version\s*=\s*([\da-zA-Z_-]+)', webpage, 'beeg version',
42 default='1546225636701')
43
44 for api_path in ('', 'api.'):
45 video = self._download_json(
46 'https://%sbeeg.com/api/v6/%s/video/%s'
47 % (api_path, beeg_version, video_id), video_id,
48 fatal=api_path == 'api.')
49 if video:
50 break
51
52 formats = []
53 for format_id, video_url in video.items():
54 if not video_url:
55 continue
56 height = self._search_regex(
57 r'^(\d+)[pP]$', format_id, 'height', default=None)
58 if not height:
59 continue
60 formats.append({
61 'url': self._proto_relative_url(
62 video_url.replace('{DATA_MARKERS}', 'data=pc_XX__%s_0' % beeg_version), 'https:'),
63 'format_id': format_id,
64 'height': int(height),
65 })
66 self._sort_formats(formats)
67
68 title = video['title']
69 video_id = compat_str(video.get('id') or video_id)
70 display_id = video.get('code')
71 description = video.get('desc')
72 series = video.get('ps_name')
73
74 timestamp = unified_timestamp(video.get('date'))
75 duration = int_or_none(video.get('duration'))
76
77 tags = [tag.strip() for tag in video['tags'].split(',')] if video.get('tags') else None
78
79 return {
80 'id': video_id,
81 'display_id': display_id,
82 'title': title,
83 'description': description,
84 'series': series,
85 'timestamp': timestamp,
86 'duration': duration,
87 'tags': tags,
88 'formats': formats,
89 'age_limit': self._rta_search(webpage),
90 }