]> jfr.im git - yt-dlp.git/blame - youtube_dlc/extractor/beeg.py
[skip travis] renaming
[yt-dlp.git] / youtube_dlc / extractor / beeg.py
CommitLineData
2aebbcce 1from __future__ import unicode_literals
2
2aebbcce 3from .common import InfoExtractor
27cef888
S
4from ..compat import (
5 compat_str,
6 compat_urlparse,
7)
5946cda7
S
8from ..utils import (
9 int_or_none,
e4d51e75 10 unified_timestamp,
5946cda7 11)
2aebbcce 12
13
14class BeegIE(InfoExtractor):
cdc7baff
S
15 _VALID_URL = r'https?://(?:www\.)?beeg\.(?:com|porn(?:/video)?)/(?P<id>\d+)'
16 _TESTS = [{
27cef888 17 # api/v6 v1
2aebbcce 18 'url': 'http://beeg.com/5416503',
8814ae42 19 'md5': 'a1a1b1a8bc70a89e49ccfd113aed0820',
2aebbcce 20 'info_dict': {
21 'id': '5416503',
22 'ext': 'mp4',
23 'title': 'Sultry Striptease',
5946cda7
S
24 'description': 'md5:d22219c09da287c14bed3d6c37ce4bc2',
25 'timestamp': 1391813355,
26 'upload_date': '20140207',
27 'duration': 383,
28 'tags': list,
7ca2e11f 29 'age_limit': 18,
2aebbcce 30 }
27cef888
S
31 }, {
32 # api/v6 v2
33 'url': 'https://beeg.com/1941093077?t=911-1391',
34 'only_matching': True,
5fc08961
S
35 }, {
36 # api/v6 v2 w/o t
37 'url': 'https://beeg.com/1277207756',
38 'only_matching': True,
cdc7baff
S
39 }, {
40 'url': 'https://beeg.porn/video/5416503',
41 'only_matching': True,
42 }, {
43 'url': 'https://beeg.porn/5416503',
44 'only_matching': True,
45 }]
2aebbcce 46
47 def _real_extract(self, url):
5946cda7 48 video_id = self._match_id(url)
3baa62e8 49
3afef2e3
S
50 webpage = self._download_webpage(url, video_id)
51
e4d51e75
S
52 beeg_version = self._search_regex(
53 r'beeg_version\s*=\s*([\da-zA-Z_-]+)', webpage, 'beeg version',
54 default='1546225636701')
3afef2e3 55
5fc08961 56 if len(video_id) >= 10:
27cef888
S
57 query = {
58 'v': 2,
27cef888 59 }
5fc08961
S
60 qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
61 t = qs.get('t', [''])[0].split('-')
62 if len(t) > 1:
63 query.update({
64 's': t[0],
65 'e': t[1],
66 })
27cef888
S
67 else:
68 query = {'v': 1}
69
6e736d86
S
70 for api_path in ('', 'api.'):
71 video = self._download_json(
72 'https://%sbeeg.com/api/v6/%s/video/%s'
73 % (api_path, beeg_version, video_id), video_id,
27cef888 74 fatal=api_path == 'api.', query=query)
6e736d86
S
75 if video:
76 break
d63cfc3f 77
5946cda7
S
78 formats = []
79 for format_id, video_url in video.items():
5d0f84d3
S
80 if not video_url:
81 continue
5946cda7
S
82 height = self._search_regex(
83 r'^(\d+)[pP]$', format_id, 'height', default=None)
84 if not height:
85 continue
86 formats.append({
e4d51e75
S
87 'url': self._proto_relative_url(
88 video_url.replace('{DATA_MARKERS}', 'data=pc_XX__%s_0' % beeg_version), 'https:'),
5946cda7
S
89 'format_id': format_id,
90 'height': int(height),
91 })
3baa62e8 92 self._sort_formats(formats)
2aebbcce 93
5946cda7 94 title = video['title']
e4d51e75 95 video_id = compat_str(video.get('id') or video_id)
5946cda7
S
96 display_id = video.get('code')
97 description = video.get('desc')
e4d51e75 98 series = video.get('ps_name')
5f6a1245 99
e4d51e75 100 timestamp = unified_timestamp(video.get('date'))
5946cda7 101 duration = int_or_none(video.get('duration'))
2aebbcce 102
5946cda7 103 tags = [tag.strip() for tag in video['tags'].split(',')] if video.get('tags') else None
2aebbcce 104
105 return {
106 'id': video_id,
5946cda7 107 'display_id': display_id,
2aebbcce 108 'title': title,
109 'description': description,
e4d51e75 110 'series': series,
5946cda7
S
111 'timestamp': timestamp,
112 'duration': duration,
113 'tags': tags,
3baa62e8 114 'formats': formats,
3afef2e3 115 'age_limit': self._rta_search(webpage),
2aebbcce 116 }