[ie/soundcloud] Various fixes (#11820)
[yt-dlp.git] / yt_dlp / extractor / beeg.py
blob960cdfabdd3fad4fb972cdd56dfc4625a04c7bf3
1 from .common import InfoExtractor
2 from ..utils import (
3 int_or_none,
4 str_or_none,
5 traverse_obj,
6 try_get,
7 unified_timestamp,
11 class BeegIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?beeg\.(?:com(?:/video)?)/-?(?P<id>\d+)'
13 _TESTS = [{
14 'url': 'https://beeg.com/-0983946056129650',
15 'md5': '51d235147c4627cfce884f844293ff88',
16 'info_dict': {
17 'id': '0983946056129650',
18 'ext': 'mp4',
19 'title': 'sucked cock and fucked in a private plane',
20 'duration': 927,
21 'tags': list,
22 'age_limit': 18,
23 'upload_date': '20220131',
24 'timestamp': 1643656455,
25 'display_id': '2540839',
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,
39 'display_id': '2569965',
40 'upload_date': '20220131',
42 }, {
43 # api/v6 v2
44 'url': 'https://beeg.com/1941093077?t=911-1391',
45 'only_matching': True,
46 }, {
47 # api/v6 v2 w/o t
48 'url': 'https://beeg.com/1277207756',
49 'only_matching': True,
52 def _real_extract(self, url):
53 video_id = self._match_id(url)
55 webpage = self._download_webpage(url, video_id)
57 video = self._download_json(
58 f'https://store.externulls.com/facts/file/{video_id}',
59 video_id, f'Downloading JSON for {video_id}')
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
67 resources = traverse_obj(video, ('file', 'hls_resources')) or first_fact.get('hls_resources')
69 formats = []
70 for format_id, video_uri in resources.items():
71 if not video_uri:
72 continue
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)
79 return {
80 'id': video_id,
81 'display_id': str_or_none(first_fact.get('id')),
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')),
87 'formats': formats,
88 'age_limit': self._rta_search(webpage),