]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/parler.py
[extractor/parler] Add extractor (#4616)
[yt-dlp.git] / yt_dlp / extractor / parler.py
CommitLineData
43cf982a
BW
1import json
2
3from .common import InfoExtractor
4from .youtube import YoutubeIE
5
6from ..utils import (
7 clean_html,
8 format_field,
9 int_or_none,
10 strip_or_none,
11 traverse_obj,
12 unified_timestamp,
13 urlencode_postdata,
14)
15
16
17class ParlerIE(InfoExtractor):
18 IE_DESC = 'Posts on parler.com'
19 _VALID_URL = r'https://parler\.com/feed/(?P<id>[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12})'
20 _TESTS = [
21 {
22 'url': 'https://parler.com/feed/df79fdba-07cc-48fe-b085-3293897520d7',
23 'md5': '16e0f447bf186bb3cf64de5bbbf4d22d',
24 'info_dict': {
25 'id': 'df79fdba-07cc-48fe-b085-3293897520d7',
26 'ext': 'mp4',
27 'thumbnail': 'https://bl-images.parler.com/videos/6ce7cdf3-a27a-4d72-bf9c-d3e17ce39a66/thumbnail.jpeg',
28 'title': 'Parler video #df79fdba-07cc-48fe-b085-3293897520d7',
29 'description': 'md5:6f220bde2df4a97cbb89ac11f1fd8197',
30 'timestamp': 1659744000,
31 'upload_date': '20220806',
32 'uploader': 'Tulsi Gabbard',
33 'uploader_id': 'TulsiGabbard',
34 'uploader_url': 'https://parler.com/TulsiGabbard',
35 'view_count': int,
36 'comment_count': int,
37 'repost_count': int,
38 },
39 },
40 {
41 'url': 'https://parler.com/feed/a7406eb4-91e5-4793-b5e3-ade57a24e287',
42 'md5': '11687e2f5bb353682cee338d181422ed',
43 'info_dict': {
44 'id': 'a7406eb4-91e5-4793-b5e3-ade57a24e287',
45 'ext': 'mp4',
46 'thumbnail': 'https://bl-images.parler.com/videos/317827a8-1e48-4cbc-981f-7dd17d4c1183/thumbnail.jpeg',
47 'title': 'Parler video #a7406eb4-91e5-4793-b5e3-ade57a24e287',
48 'description': 'This man should run for office',
49 'timestamp': 1659657600,
50 'upload_date': '20220805',
51 'uploader': 'Benny Johnson',
52 'uploader_id': 'BennyJohnson',
53 'uploader_url': 'https://parler.com/BennyJohnson',
54 'view_count': int,
55 'comment_count': int,
56 'repost_count': int,
57 },
58 },
59 {
60 'url': 'https://parler.com/feed/f23b85c1-6558-470f-b9ff-02c145f28da5',
61 'md5': 'eaba1ff4a10fe281f5ce74e930ab2cb4',
62 'info_dict': {
63 'id': 'r5vkSaz8PxQ',
64 'ext': 'mp4',
65 'thumbnail': 'https://i.ytimg.com/vi_webp/r5vkSaz8PxQ/maxresdefault.webp',
66 'title': 'Tom MacDonald Names Reaction',
67 'description': 'md5:33c21f0d35ae6dc2edf3007d6696baea',
68 'upload_date': '20220716',
69 'duration': 1267,
70 'uploader': 'Mahesh Chookolingo',
71 'uploader_id': 'maheshchookolingo',
72 'uploader_url': 'http://www.youtube.com/user/maheshchookolingo',
73 'channel': 'Mahesh Chookolingo',
74 'channel_id': 'UCox6YeMSY1PQInbCtTaZj_w',
75 'channel_url': 'https://www.youtube.com/channel/UCox6YeMSY1PQInbCtTaZj_w',
76 'categories': ['Entertainment'],
77 'tags': list,
78 'availability': 'public',
79 'live_status': 'not_live',
80 'view_count': int,
81 'comment_count': int,
82 'like_count': int,
83 'channel_follower_count': int,
84 'age_limit': 0,
85 'playable_in_embed': True,
86 },
87 },
88 ]
89
90 def _real_extract(self, url):
91 video_id = self._match_id(url)
92 data = self._download_json(
93 'https://parler.com/open-api/ParleyDetailEndpoint.php', video_id,
94 data=urlencode_postdata({'uuid': video_id}))['data'][0]
95 primary = data['primary']
96
97 embed = self._parse_json(primary.get('V2LINKLONG') or '', video_id, fatal=False)
98 if embed:
99 return self.url_result(embed[0], YoutubeIE)
100
101 return {
102 'id': video_id,
103 'url': traverse_obj(primary, ('video_data', 'videoSrc')),
104 'thumbnail': traverse_obj(primary, ('video_data', 'thumbnailUrl')),
105 'title': '',
106 'description': strip_or_none(clean_html(primary.get('full_body'))) or None,
107 'timestamp': unified_timestamp(primary.get('date_created')),
108 'uploader': strip_or_none(primary.get('name')),
109 'uploader_id': strip_or_none(primary.get('username')),
110 'uploader_url': format_field(strip_or_none(primary.get('username')), None, 'https://parler.com/%s'),
111 'view_count': int_or_none(primary.get('view_count')),
112 'comment_count': int_or_none(traverse_obj(data, ('engagement', 'commentCount'))),
113 'repost_count': int_or_none(traverse_obj(data, ('engagement', 'echoCount'))),
114 }