social media crossposting tool. 3rd time's the charm
mastodon misskey crossposting bluesky

add quotes to bsky

zenfyr.dev 5f5b5f17 bcd918f5

verified
Changed files
+34 -33
bluesky
+3 -4
bluesky/info.py
···
def _init_identity(self) -> None:
handle, did, pds = self.get_identity_options()
-
-
if did and pds:
+
if did:
self.did = did
+
if pds:
self.pds = pds
-
return
if not did:
if not handle:
···
self.did = handle_resolver.resolve_handle(handle)
if not pds:
-
self.log.info("Resolving PDS from %s DID document...", did)
+
self.log.info("Resolving PDS from %s DID document...", self.did)
atp_pds = did_resolver.resolve_did(self.did).get_atproto_pds()
if not atp_pds:
raise Exception("Failed to resolve atproto pds for %s")
+31 -29
bluesky/input.py
···
LabelsAttachment,
LanguagesAttachment,
MediaAttachment,
+
QuoteAttachment,
RemoteUrlAttachment,
)
from cross.media import Blob, download_blob
···
RemoteUrlAttachment(url=f"https://bsky.app/profile/{did}/post/{rid}")
)
-
embed = record.get("embed", {})
-
if embed:
+
embed: dict[str, Any] = record.get("embed", {})
+
blob_urls: list[tuple[str, str, str | None]] = []
+
def handle_embeds(embed: dict[str, Any]):
+
nonlocal blob_urls, post
match cast(str, embed["$type"]):
case "app.bsky.embed.record" | "app.bsky.embed.recordWithMedia":
-
_, collection, _ = AtUri.record_uri(
-
cast(str, embed["record"]["uri"])
-
)
-
if collection == "app.bsky.feed.post":
-
self.log.info("Skipping '%s'! Quote..", post_uri)
+
rcrd = embed['record']['record'] if embed['record'].get('record') else embed['record']
+
did, collection, _ = AtUri.record_uri(rcrd["uri"])
+
if collection != "app.bsky.feed.post":
return
+
if did != self.did:
+
return
+
post.attachments.put(QuoteAttachment(quoted_id=rcrd["uri"], quoted_user=did))
+
+
if embed.get('media'):
+
handle_embeds(embed["media"])
case "app.bsky.embed.images":
-
blobs: list[Blob] = []
for image in embed["images"]:
blob_cid = image["image"]["ref"]["$link"]
url = f"{self.pds}/xrpc/com.atproto.sync.getBlob?did={self.did}&cid={blob_cid}"
-
self.log.info("Downloading %s...", blob_cid)
-
blob: Blob | None = download_blob(url, image.get("alt"))
-
if not blob:
-
self.log.error(
-
"Skipping %s! Failed to download blob %s.",
-
post_uri,
-
blob_cid,
-
)
-
return
-
blobs.append(blob)
-
post.attachments.put(MediaAttachment(blobs=blobs))
+
blob_urls.append((url, blob_cid, image.get("alt")))
case "app.bsky.embed.video":
blob_cid = embed["video"]["ref"]["$link"]
url = f"{self.pds}/xrpc/com.atproto.sync.getBlob?did={self.did}&cid={blob_cid}"
-
self.log.info("Downloading %s...", blob_cid)
-
blob: Blob | None = download_blob(url, embed.get("alt"))
-
if not blob:
-
self.log.error(
-
"Skipping %s! Failed to download blob %s.",
-
post_uri,
-
blob_cid,
-
)
-
return
-
post.attachments.put(MediaAttachment(blobs=[blob]))
+
blob_urls.append((url, blob_cid, embed.get("alt")))
case _:
self.log.warning(f"Unhandled embedd type {embed['$type']}")
pass
+
if embed:
+
handle_embeds(embed)
+
+
if blob_urls:
+
blobs: list[Blob] = []
+
for url, cid, alt in blob_urls:
+
self.log.info("Downloading %s...", cid)
+
blob: Blob | None = download_blob(url, alt)
+
if not blob:
+
self.log.error(
+
"Skipping %s! Failed to download blob %s.", post_uri, cid
+
)
+
return
+
blobs.append(blob)
+
post.attachments.put(MediaAttachment(blobs=blobs))
if "langs" in record:
post.attachments.put(LanguagesAttachment(langs=record["langs"]))