]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/beeg.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / beeg.py
CommitLineData
2aebbcce 1from .common import InfoExtractor
5946cda7
S
2from ..utils import (
3 int_or_none,
f4f9f6d0 4 str_or_none,
cd170e81
B
5 traverse_obj,
6 try_get,
e4d51e75 7 unified_timestamp,
5946cda7 8)
2aebbcce 9
10
11class BeegIE(InfoExtractor):
cd170e81 12 _VALID_URL = r'https?://(?:www\.)?beeg\.(?:com(?:/video)?)/-?(?P<id>\d+)'
cdc7baff 13 _TESTS = [{
cd170e81
B
14 'url': 'https://beeg.com/-0983946056129650',
15 'md5': '51d235147c4627cfce884f844293ff88',
2aebbcce 16 'info_dict': {
cd170e81 17 'id': '0983946056129650',
2aebbcce 18 'ext': 'mp4',
cd170e81
B
19 'title': 'sucked cock and fucked in a private plane',
20 'duration': 927,
5946cda7 21 'tags': list,
7ca2e11f 22 'age_limit': 18,
cd170e81
B
23 'upload_date': '20220131',
24 'timestamp': 1643656455,
f4f9f6d0 25 'display_id': '2540839',
cd170e81
B
26 }
27 }, {
28 'url': 'https://beeg.com/-0599050563103750?t=4-861',
29 'md5': 'bd8b5ea75134f7f07fad63008db2060e',
30 'info_dict': {
31 'id': '0599050563103750',
32 'ext': 'mp4',
33 'title': 'Bad Relatives',
34 'duration': 2060,
35 'tags': list,
36 'age_limit': 18,
37 'description': 'md5:b4fc879a58ae6c604f8f259155b7e3b9',
38 'timestamp': 1643623200,
f4f9f6d0 39 'display_id': '2569965',
cd170e81 40 'upload_date': '20220131',
2aebbcce 41 }
27cef888
S
42 }, {
43 # api/v6 v2
44 'url': 'https://beeg.com/1941093077?t=911-1391',
45 'only_matching': True,
5fc08961
S
46 }, {
47 # api/v6 v2 w/o t
48 'url': 'https://beeg.com/1277207756',
49 'only_matching': True,
cdc7baff 50 }]
2aebbcce 51
52 def _real_extract(self, url):
5946cda7 53 video_id = self._match_id(url)
3baa62e8 54
3afef2e3
S
55 webpage = self._download_webpage(url, video_id)
56
cd170e81
B
57 video = self._download_json(
58 'https://store.externulls.com/facts/file/%s' % video_id,
59 video_id, 'Downloading JSON for %s' % video_id)
3afef2e3 60
cd170e81
B
61 fc_facts = video.get('fc_facts')
62 first_fact = {}
63 for fact in fc_facts:
64 if not first_fact or try_get(fact, lambda x: x['id'] < first_fact['id']):
65 first_fact = fact
27cef888 66
cd170e81 67 resources = traverse_obj(video, ('file', 'hls_resources')) or first_fact.get('hls_resources')
d63cfc3f 68
5946cda7 69 formats = []
cd170e81
B
70 for format_id, video_uri in resources.items():
71 if not video_uri:
5946cda7 72 continue
cd170e81
B
73 height = int_or_none(self._search_regex(r'fl_cdn_(\d+)', format_id, 'height', default=None))
74 current_formats = self._extract_m3u8_formats(f'https://video.beeg.com/{video_uri}', video_id, ext='mp4', m3u8_id=str(height))
75 for f in current_formats:
76 f['height'] = height
77 formats.extend(current_formats)
5f6a1245 78
2aebbcce 79 return {
80 'id': video_id,
f4f9f6d0 81 'display_id': str_or_none(first_fact.get('id')),
cd170e81
B
82 'title': traverse_obj(video, ('file', 'stuff', 'sf_name')),
83 'description': traverse_obj(video, ('file', 'stuff', 'sf_story')),
84 'timestamp': unified_timestamp(first_fact.get('fc_created')),
85 'duration': int_or_none(traverse_obj(video, ('file', 'fl_duration'))),
86 'tags': traverse_obj(video, ('tags', ..., 'tg_name')),
3baa62e8 87 'formats': formats,
3afef2e3 88 'age_limit': self._rta_search(webpage),
2aebbcce 89 }