]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/chingari.py
[spotify] Detect iframe embeds (#3430)
[yt-dlp.git] / yt_dlp / extractor / chingari.py
CommitLineData
d1a77684
AG
1import itertools
2import json
3
4from .common import InfoExtractor
5from ..compat import compat_urllib_parse_unquote_plus
6from ..utils import (
7 clean_html,
8 ExtractorError,
9 int_or_none,
10 str_to_int,
11 url_or_none,
12)
13
14
15class ChingariBaseIE(InfoExtractor):
16 def _get_post(self, id, post_data):
17 media_data = post_data['mediaLocation']
18 base_url = media_data['base']
19 author_data = post_data.get('authorData', {})
20 song_data = post_data.get('song', {}) # revist this in future for differentiating b/w 'art' and 'author'
21
22 formats = [{
23 'format_id': frmt,
24 'width': str_to_int(frmt[1:]),
25 'url': base_url + frmt_path,
26 } for frmt, frmt_path in media_data.get('transcoded', {}).items()]
27
28 if media_data.get('path'):
29 formats.append({
30 'format_id': 'original',
31 'format_note': 'Direct video.',
32 'url': base_url + '/apipublic' + media_data['path'],
33 'quality': 10,
34 })
35 self._sort_formats(formats)
36 timestamp = str_to_int(post_data.get('created_at'))
37 if timestamp:
38 timestamp = int_or_none(timestamp, 1000)
39
40 thumbnail, uploader_url = None, None
41 if media_data.get('thumbnail'):
42 thumbnail = base_url + media_data.get('thumbnail')
43 if author_data.get('username'):
44 uploader_url = 'https://chingari.io/' + author_data.get('username')
45
46 return {
47 'id': id,
48 'title': compat_urllib_parse_unquote_plus(clean_html(post_data.get('caption'))),
49 'description': compat_urllib_parse_unquote_plus(clean_html(post_data.get('caption'))),
50 'duration': media_data.get('duration'),
51 'thumbnail': url_or_none(thumbnail),
52 'like_count': post_data.get('likeCount'),
53 'view_count': post_data.get('viewsCount'),
54 'comment_count': post_data.get('commentCount'),
55 'repost_count': post_data.get('shareCount'),
56 'timestamp': timestamp,
57 'uploader_id': post_data.get('userId') or author_data.get('_id'),
58 'uploader': author_data.get('name'),
59 'uploader_url': url_or_none(uploader_url),
60 'track': song_data.get('title'),
61 'artist': song_data.get('author'),
62 'formats': formats,
63 }
64
65
66class ChingariIE(ChingariBaseIE):
73f035e1 67 _VALID_URL = r'https?://(?:www\.)?chingari\.io/share/post\?id=(?P<id>[^&/#?]+)'
d1a77684
AG
68 _TESTS = [{
69 'url': 'https://chingari.io/share/post?id=612f8f4ce1dc57090e8a7beb',
70 'info_dict': {
71 'id': '612f8f4ce1dc57090e8a7beb',
72 'ext': 'mp4',
73 'title': 'Happy birthday Srila Prabhupada',
74 'description': 'md5:c7080ebfdfeb06016e638c286d6bc3fa',
75 'duration': 0,
76 'thumbnail': 'https://media.chingari.io/uploads/c41d30e2-06b6-4e3b-9b4b-edbb929cec06-1630506826911/thumbnail/198f993f-ce87-4623-82c6-cd071bd6d4f4-1630506828016.jpg',
77 'like_count': int,
78 'view_count': int,
79 'comment_count': int,
80 'repost_count': int,
81 'timestamp': 1630506828,
82 'upload_date': '20210901',
83 'uploader_id': '5f0403982c8bd344f4813f8c',
84 'uploader': 'ISKCON,Inc.',
85 'uploader_url': 'https://chingari.io/iskcon,inc',
86 'track': None,
87 'artist': None,
88 },
89 'params': {'skip_download': True}
90 }]
91
92 def _real_extract(self, url):
93 id = self._match_id(url)
94 post_json = self._download_json(f'https://api.chingari.io/post/post_details/{id}', id)
95 if post_json['code'] != 200:
96 raise ExtractorError(post_json['message'], expected=True)
97 post_data = post_json['data']
98 return self._get_post(id, post_data)
99
100
101class ChingariUserIE(ChingariBaseIE):
73f035e1 102 _VALID_URL = r'https?://(?:www\.)?chingari\.io/(?!share/post)(?P<id>[^/?]+)'
d1a77684
AG
103 _TESTS = [{
104 'url': 'https://chingari.io/dada1023',
105 'playlist_mincount': 3,
106 'info_dict': {
107 'id': 'dada1023',
108 },
109 'entries': [{
110 'url': 'https://chingari.io/share/post?id=614781f3ade60b3a0bfff42a',
111 'info_dict': {
112 'id': '614781f3ade60b3a0bfff42a',
113 'ext': 'mp4',
114 'title': '#chingaribappa ',
115 'description': 'md5:d1df21d84088770468fa63afe3b17857',
116 'duration': 7,
117 'thumbnail': 'https://media.chingari.io/uploads/346d86d4-abb2-474e-a164-ffccf2bbcb72-1632076273717/thumbnail/b0b3aac2-2b86-4dd1-909d-9ed6e57cf77c-1632076275552.jpg',
118 'like_count': int,
119 'view_count': int,
120 'comment_count': int,
121 'repost_count': int,
122 'timestamp': 1632076275,
123 'upload_date': '20210919',
124 'uploader_id': '5efc4b12cca35c3d1794c2d3',
125 'uploader': 'dada (girish) dhawale',
126 'uploader_url': 'https://chingari.io/dada1023',
127 'track': None,
128 'artist': None
129 },
130 'params': {'skip_download': True}
131 }, {
132 'url': 'https://chingari.io/share/post?id=6146b132bcbf860959e12cba',
133 'info_dict': {
134 'id': '6146b132bcbf860959e12cba',
135 'ext': 'mp4',
136 'title': 'Tactor harvesting',
137 'description': 'md5:8403f12dce68828b77ecee7eb7e887b7',
138 'duration': 59.3,
139 'thumbnail': 'https://media.chingari.io/uploads/b353ca70-7a87-400d-93a6-fa561afaec86-1632022814584/thumbnail/c09302e3-2043-41b1-a2fe-77d97e5bd676-1632022834260.jpg',
140 'like_count': int,
141 'view_count': int,
142 'comment_count': int,
143 'repost_count': int,
144 'timestamp': 1632022834,
145 'upload_date': '20210919',
146 'uploader_id': '5efc4b12cca35c3d1794c2d3',
147 'uploader': 'dada (girish) dhawale',
148 'uploader_url': 'https://chingari.io/dada1023',
149 'track': None,
150 'artist': None
151 },
152 'params': {'skip_download': True}
153 }, {
154 'url': 'https://chingari.io/share/post?id=6145651b74cb030a64c40b82',
155 'info_dict': {
156 'id': '6145651b74cb030a64c40b82',
157 'ext': 'mp4',
158 'title': '#odiabhajan ',
159 'description': 'md5:687ea36835b9276cf2af90f25e7654cb',
160 'duration': 56.67,
161 'thumbnail': 'https://media.chingari.io/uploads/6cbf216b-babc-4cce-87fe-ceaac8d706ac-1631937782708/thumbnail/8855754f-6669-48ce-b269-8cc0699ed6da-1631937819522.jpg',
162 'like_count': int,
163 'view_count': int,
164 'comment_count': int,
165 'repost_count': int,
166 'timestamp': 1631937819,
167 'upload_date': '20210918',
168 'uploader_id': '5efc4b12cca35c3d1794c2d3',
169 'uploader': 'dada (girish) dhawale',
170 'uploader_url': 'https://chingari.io/dada1023',
171 'track': None,
172 'artist': None
173 },
174 'params': {'skip_download': True}
175 }],
176 }, {
177 'url': 'https://chingari.io/iskcon%2Cinc',
178 'playlist_mincount': 1025,
179 'info_dict': {
180 'id': 'iskcon%2Cinc',
181 },
182 }]
183
184 def _entries(self, id):
185 skip = 0
186 has_more = True
187 for page in itertools.count():
188 posts = self._download_json('https://api.chingari.io/users/getPosts', id,
189 data=json.dumps({'userId': id, 'ownerId': id, 'skip': skip, 'limit': 20}).encode(),
190 headers={'content-type': 'application/json;charset=UTF-8'},
191 note='Downloading page %s' % page)
192 for post in posts.get('data', []):
193 post_data = post['post']
194 yield self._get_post(post_data['_id'], post_data)
195 skip += 20
196 has_more = posts['hasMoreData']
197 if not has_more:
198 break
199
200 def _real_extract(self, url):
201 alt_id = self._match_id(url)
202 post_json = self._download_json(f'https://api.chingari.io/user/{alt_id}', alt_id)
203 if post_json['code'] != 200:
204 raise ExtractorError(post_json['message'], expected=True)
205 id = post_json['data']['_id']
206 return self.playlist_result(self._entries(id), playlist_id=alt_id)