1 from .common
import InfoExtractor
15 from ..utils
.traversal
import traverse_obj
18 class BlueskyIE(InfoExtractor
):
20 r
'https?://(?:www\.)?(?:bsky\.app|main\.bsky\.dev)/profile/(?P<handle>[\w.:%-]+)/post/(?P<id>\w+)',
21 r
'at://(?P<handle>[\w.:%-]+)/app\.bsky\.feed\.post/(?P<id>\w+)',
24 'url': 'https://bsky.app/profile/blu3blue.bsky.social/post/3l4omssdl632g',
25 'md5': '375539c1930ab05d15585ed772ab54fd',
27 'id': '3l4omssdl632g',
29 'uploader': 'Blu3Blu3Lilith',
30 'uploader_id': 'blu3blue.bsky.social',
31 'uploader_url': 'https://bsky.app/profile/blu3blue.bsky.social',
32 'channel_id': 'did:plc:pzdr5ylumf7vmvwasrpr5bf2',
33 'channel_url': 'https://bsky.app/profile/did:plc:pzdr5ylumf7vmvwasrpr5bf2',
34 'thumbnail': r
're:https://video.bsky.app/watch/.*\.jpg$',
35 'title': 'OMG WE HAVE VIDEOS NOW',
36 'description': 'OMG WE HAVE VIDEOS NOW',
37 'upload_date': '20240921',
38 'timestamp': 1726940605,
45 'url': 'https://bsky.app/profile/bsky.app/post/3l3vgf77uco2g',
46 'md5': 'b9e344fdbce9f2852c668a97efefb105',
48 'id': '3l3vgf77uco2g',
50 'uploader': 'Bluesky',
51 'uploader_id': 'bsky.app',
52 'uploader_url': 'https://bsky.app/profile/bsky.app',
53 'channel_id': 'did:plc:z72i7hdynmk6r22z27h6tvur',
54 'channel_url': 'https://bsky.app/profile/did:plc:z72i7hdynmk6r22z27h6tvur',
55 'thumbnail': r
're:https://video.bsky.app/watch/.*\.jpg$',
56 'title': 'Bluesky now has video! Update your app to versi...',
57 'alt_title': 'Bluesky video feature announcement',
58 'description': r
're:(?s)Bluesky now has video! .{239}',
59 'upload_date': '20240911',
60 'timestamp': 1726074716,
70 'url': 'https://main.bsky.dev/profile/souris.moe/post/3l4qhp7bcs52c',
71 'md5': '5f2df8c200b5633eb7fb2c984d29772f',
73 'id': '3l4qhp7bcs52c',
76 'uploader_id': 'souris.moe',
77 'uploader_url': 'https://bsky.app/profile/souris.moe',
78 'channel_id': 'did:plc:tj7g244gl5v6ai6cm4f4wlqp',
79 'channel_url': 'https://bsky.app/profile/did:plc:tj7g244gl5v6ai6cm4f4wlqp',
80 'thumbnail': r
're:https://video.bsky.app/watch/.*\.jpg$',
81 'title': 'Bluesky video #3l4qhp7bcs52c',
82 'upload_date': '20240922',
83 'timestamp': 1727003838,
90 'url': 'https://bsky.app/profile/de1.pds.tentacle.expert/post/3l3w4tnezek2e',
91 'md5': '1af9c7fda061cf7593bbffca89e43d1c',
93 'id': '3l3w4tnezek2e',
96 'uploader_id': 'de1.pds.tentacle.expert',
97 'uploader_url': 'https://bsky.app/profile/de1.pds.tentacle.expert',
98 'channel_id': 'did:web:de1.tentacle.expert',
99 'channel_url': 'https://bsky.app/profile/did:web:de1.tentacle.expert',
100 'thumbnail': r
're:https://video.bsky.app/watch/.*\.jpg$',
101 'title': 'Bluesky video #3l3w4tnezek2e',
102 'upload_date': '20240911',
103 'timestamp': 1726098823,
106 'comment_count': int,
110 'url': 'https://bsky.app/profile/yunayuispink.bsky.social/post/3l7gqcfes742o',
114 'uploader': 'yunayu',
115 'uploader_id': '@yunayuispink',
116 'uploader_url': 'https://www.youtube.com/@yunayuispink',
118 'channel_id': 'UCPLvXnHa7lTyNoR_dGsU14w',
119 'channel_url': 'https://www.youtube.com/channel/UCPLvXnHa7lTyNoR_dGsU14w',
120 'thumbnail': 'https://i.ytimg.com/vi_webp/XxK3t_5V3ao/maxresdefault.webp',
121 'description': r
're:Have a good goodx10000day',
122 'title': '5min vs 5hours drawing',
123 'availability': 'public',
124 'live_status': 'not_live',
125 'playable_in_embed': True,
126 'upload_date': '20241026',
127 'timestamp': 1729967784,
132 'comment_count': int,
133 'channel_follower_count': int,
134 'categories': ['Entertainment'],
137 'add_ie': ['Youtube'],
139 'url': 'https://bsky.app/profile/endshark.bsky.social/post/3jzxjkcemae2m',
143 'uploader': 'LASERBAT',
144 'uploader_id': 'laserbatx',
145 'uploader_url': 'https://laserbatx.bandcamp.com',
146 'artists': ['LASERBAT'],
147 'album_artists': ['LASERBAT'],
148 'album': 'Hari Nezumi [EP]',
149 'track': 'Forward to the End',
150 'title': 'LASERBAT - Forward to the End',
151 'thumbnail': 'https://f4.bcbits.com/img/a2507705510_5.jpg',
153 'track_id': '222792849',
154 'release_date': '20230423',
155 'upload_date': '20230423',
156 'timestamp': 1682276040.0,
157 'release_timestamp': 1682276040.0,
160 'add_ie': ['Bandcamp'],
162 'url': 'https://bsky.app/profile/dannybhoix.bsky.social/post/3l6oe5mtr2c2j',
163 'md5': 'b9e344fdbce9f2852c668a97efefb105',
165 'id': '3l3vgf77uco2g',
167 'uploader': 'Bluesky',
168 'uploader_id': 'bsky.app',
169 'uploader_url': 'https://bsky.app/profile/bsky.app',
170 'channel_id': 'did:plc:z72i7hdynmk6r22z27h6tvur',
171 'channel_url': 'https://bsky.app/profile/did:plc:z72i7hdynmk6r22z27h6tvur',
172 'thumbnail': r
're:https://video.bsky.app/watch/.*\.jpg$',
173 'title': 'Bluesky now has video! Update your app to versi...',
174 'alt_title': 'Bluesky video feature announcement',
175 'description': r
're:(?s)Bluesky now has video! .{239}',
176 'upload_date': '20240911',
177 'timestamp': 1726074716,
180 'comment_count': int,
187 'url': 'https://bsky.app/profile/alt.bun.how/post/3l7rdfxhyds2f',
188 'md5': '8775118b235cf9fa6b5ad30f95cda75c',
190 'id': '3l7rdfxhyds2f',
192 'uploader': 'cinnamon',
193 'uploader_id': 'alt.bun.how',
194 'uploader_url': 'https://bsky.app/profile/alt.bun.how',
195 'channel_id': 'did:plc:7x6rtuenkuvxq3zsvffp2ide',
196 'channel_url': 'https://bsky.app/profile/did:plc:7x6rtuenkuvxq3zsvffp2ide',
197 'thumbnail': r
're:https://video.bsky.app/watch/.*\.jpg$',
198 'title': 'crazy that i look like this tbh',
199 'description': 'crazy that i look like this tbh',
200 'upload_date': '20241030',
201 'timestamp': 1730332128,
204 'comment_count': int,
209 'url': 'at://did:plc:ia76kvnndjutgedggx2ibrem/app.bsky.feed.post/3l6zrz6zyl2dr',
210 'md5': '71b0eb6d85d03145e6af6642c7fc6d78',
212 'id': '3l6zrz6zyl2dr',
215 'uploader_id': 'mary.my.id',
216 'uploader_url': 'https://bsky.app/profile/mary.my.id',
217 'channel_id': 'did:plc:ia76kvnndjutgedggx2ibrem',
218 'channel_url': 'https://bsky.app/profile/did:plc:ia76kvnndjutgedggx2ibrem',
219 'thumbnail': r
're:https://video.bsky.app/watch/.*\.jpg$',
220 'title': 'Bluesky video #3l6zrz6zyl2dr',
221 'upload_date': '20241021',
222 'timestamp': 1729523172,
225 'comment_count': int,
229 'url': 'https://bsky.app/profile/purpleicetea.bsky.social/post/3l7gv55dc2o2w',
231 'id': '3l7gv55dc2o2w',
235 'id': '3l7gv55dc2o2w',
237 'upload_date': '20241026',
238 'description': 'One of my favorite videos',
239 'comment_count': int,
240 'uploader_url': 'https://bsky.app/profile/purpleicetea.bsky.social',
241 'uploader': 'Purple.Ice.Tea',
242 'thumbnail': r
're:https://video.bsky.app/watch/.*\.jpg$',
243 'channel_url': 'https://bsky.app/profile/did:plc:bjh5ffwya5f53dfy47dezuwx',
245 'channel_id': 'did:plc:bjh5ffwya5f53dfy47dezuwx',
247 'timestamp': 1729973202,
249 'uploader_id': 'purpleicetea.bsky.social',
250 'title': 'One of my favorite videos',
254 'id': '3l77u64l7le2e',
256 'title': 'hearing people on twitter say that bluesky isn\'...',
258 'uploader_id': 'thafnine.net',
259 'uploader_url': 'https://bsky.app/profile/thafnine.net',
260 'upload_date': '20241024',
261 'channel_url': 'https://bsky.app/profile/did:plc:6ttyq36rhiyed7wu3ws7dmqj',
262 'description': r
're:(?s)hearing people on twitter say that bluesky .{93}',
264 'alt_title': 'md5:9b1ee1937fb3d1a81e932f9ec14d560e',
266 'channel_id': 'did:plc:6ttyq36rhiyed7wu3ws7dmqj',
267 'thumbnail': r
're:https://video.bsky.app/watch/.*\.jpg$',
268 'timestamp': 1729731642,
269 'comment_count': int,
274 _BLOB_URL_TMPL
= '{}/xrpc/com.atproto.sync.getBlob'
276 def _get_service_endpoint(self
, did
, video_id
):
277 if did
.startswith('did:web:'):
278 url
= f
'https://{did[8:]}/.well-known/did.json'
280 url
= f
'https://plc.directory/{did}'
281 services
= self
._download
_json
(
282 url
, video_id
, 'Fetching service endpoint', 'Falling back to bsky.social', fatal
=False)
284 services
, ('service', lambda _
, x
: x
['type'] == 'AtprotoPersonalDataServer',
285 'serviceEndpoint', {url_or_none}
, any
)) or 'https://bsky.social'
287 def _real_extract(self
, url
):
288 handle
, video_id
= self
._match
_valid
_url
(url
).group('handle', 'id')
290 post
= self
._download
_json
(
291 'https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread',
293 'uri': f
'at://{handle}/app.bsky.feed.post/{video_id}',
299 # app.bsky.embed.video.view/app.bsky.embed.external.view
300 entries
.extend(self
._extract
_videos
(post
, video_id
))
301 # app.bsky.embed.recordWithMedia.view
302 entries
.extend(self
._extract
_videos
(
303 post
, video_id
, embed_path
=('embed', 'media'), record_subpath
=('embed', 'media')))
304 # app.bsky.embed.record.view
305 if nested_post
:= traverse_obj(post
, ('embed', 'record', ('record', None), {dict}
, any
)):
306 entries
.extend(self
._extract
_videos
(
307 nested_post
, video_id
, embed_path
=('embeds', 0), record_path
='value'))
310 raise ExtractorError('No video could be found in this post', expected
=True)
311 if len(entries
) == 1:
313 return self
.playlist_result(entries
, video_id
)
316 def _build_profile_url(path
):
317 return format_field(path
, None, 'https://bsky.app/profile/%s', default
=None)
319 def _extract_videos(self
, root
, video_id
, embed_path
='embed', record_path
='record', record_subpath
='embed'):
320 embed_path
= variadic(embed_path
, (str, bytes
, dict, set))
321 record_path
= variadic(record_path
, (str, bytes
, dict, set))
322 record_subpath
= variadic(record_subpath
, (str, bytes
, dict, set))
325 if external_uri
:= traverse_obj(root
, (
326 ((*record_path
, *record_subpath
), embed_path
), 'external', 'uri', {url_or_none}
, any
)):
327 entries
.append(self
.url_result(external_uri
))
328 if playlist
:= traverse_obj(root
, (*embed_path
, 'playlist', {url_or_none}
)):
329 formats
, subtitles
= self
._extract
_m
3u8_formats
_and
_subtitles
(
330 playlist
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False)
334 video_cid
= traverse_obj(
335 root
, (*embed_path
, 'cid', {str}
),
336 (*record_path
, *record_subpath
, 'video', 'ref', '$link', {str}
))
337 did
= traverse_obj(root
, ('author', 'did', {str}
))
339 if did
and video_cid
:
340 endpoint
= self
._get
_service
_endpoint
(did
, video_id
)
344 'url': update_url_query(
345 self
._BLOB
_URL
_TMPL
.format(endpoint
), {'did': did
, 'cid': video_cid
}),
346 **traverse_obj(root
, (*embed_path
, 'aspectRatio', {
347 'width': ('width', {int_or_none}
),
348 'height': ('height', {int_or_none}
),
350 **traverse_obj(root
, (*record_path
, *record_subpath
, 'video', {
351 'filesize': ('size', {int_or_none}
),
352 'ext': ('mimeType', {mimetype2ext}
),
356 for sub_data
in traverse_obj(root
, (
357 *record_path
, *record_subpath
, 'captions', lambda _
, v
: v
['file']['ref']['$link'])):
358 subtitles
.setdefault(sub_data
.get('lang') or 'und', []).append({
359 'url': update_url_query(
360 self
._BLOB
_URL
_TMPL
.format(endpoint
), {'did': did
, 'cid': sub_data
['file']['ref']['$link']}),
361 'ext': traverse_obj(sub_data
, ('file', 'mimeType', {mimetype2ext}
)),
367 'subtitles': subtitles
,
368 **traverse_obj(root
, {
369 'id': ('uri', {url_basename}
),
370 'thumbnail': (*embed_path
, 'thumbnail', {url_or_none}
),
371 'alt_title': (*embed_path
, 'alt', {str}
, filter),
372 'uploader': ('author', 'displayName', {str}
),
373 'uploader_id': ('author', 'handle', {str}
),
374 'uploader_url': ('author', 'handle', {self
._build
_profile
_url
}),
375 'channel_id': ('author', 'did', {str}
),
376 'channel_url': ('author', 'did', {self
._build
_profile
_url
}),
377 'like_count': ('likeCount', {int_or_none}
),
378 'repost_count': ('repostCount', {int_or_none}
),
379 'comment_count': ('replyCount', {int_or_none}
),
380 'timestamp': ('indexedAt', {parse_iso8601}
),
381 'tags': ('labels', ..., 'val', {str}
, all
, {orderedSet}
),
383 'labels', ..., 'val', {lambda x
: 18 if x
in ('sexual', 'porn', 'graphic-media') else None}, any
),
384 'description': (*record_path
, 'text', {str}
, filter),
385 'title': (*record_path
, 'text', {lambda x
: x
.replace('\n', ' ')}, {truncate_string(left
=50)}),