···27272828 def _init_identity(self) -> None:
2929 handle, did, pds = self.get_identity_options()
3030-3131- if did and pds:
3030+ if did:
3231 self.did = did
3232+ if pds:
3333 self.pds = pds
3434- return
35343635 if not did:
3736 if not handle:
···4039 self.did = handle_resolver.resolve_handle(handle)
41404241 if not pds:
4343- self.log.info("Resolving PDS from %s DID document...", did)
4242+ self.log.info("Resolving PDS from %s DID document...", self.did)
4443 atp_pds = did_resolver.resolve_did(self.did).get_atproto_pds()
4544 if not atp_pds:
4645 raise Exception("Failed to resolve atproto pds for %s")
+31-29
bluesky/input.py
···1313 LabelsAttachment,
1414 LanguagesAttachment,
1515 MediaAttachment,
1616+ QuoteAttachment,
1617 RemoteUrlAttachment,
1718)
1819from cross.media import Blob, download_blob
···8182 RemoteUrlAttachment(url=f"https://bsky.app/profile/{did}/post/{rid}")
8283 )
83848484- embed = record.get("embed", {})
8585- if embed:
8585+ embed: dict[str, Any] = record.get("embed", {})
8686+ blob_urls: list[tuple[str, str, str | None]] = []
8787+ def handle_embeds(embed: dict[str, Any]):
8888+ nonlocal blob_urls, post
8689 match cast(str, embed["$type"]):
8790 case "app.bsky.embed.record" | "app.bsky.embed.recordWithMedia":
8888- _, collection, _ = AtUri.record_uri(
8989- cast(str, embed["record"]["uri"])
9090- )
9191- if collection == "app.bsky.feed.post":
9292- self.log.info("Skipping '%s'! Quote..", post_uri)
9191+ rcrd = embed['record']['record'] if embed['record'].get('record') else embed['record']
9292+ did, collection, _ = AtUri.record_uri(rcrd["uri"])
9393+ if collection != "app.bsky.feed.post":
9394 return
9595+ if did != self.did:
9696+ return
9797+ post.attachments.put(QuoteAttachment(quoted_id=rcrd["uri"], quoted_user=did))
9898+9999+ if embed.get('media'):
100100+ handle_embeds(embed["media"])
94101 case "app.bsky.embed.images":
9595- blobs: list[Blob] = []
96102 for image in embed["images"]:
97103 blob_cid = image["image"]["ref"]["$link"]
98104 url = f"{self.pds}/xrpc/com.atproto.sync.getBlob?did={self.did}&cid={blob_cid}"
9999- self.log.info("Downloading %s...", blob_cid)
100100- blob: Blob | None = download_blob(url, image.get("alt"))
101101- if not blob:
102102- self.log.error(
103103- "Skipping %s! Failed to download blob %s.",
104104- post_uri,
105105- blob_cid,
106106- )
107107- return
108108- blobs.append(blob)
109109- post.attachments.put(MediaAttachment(blobs=blobs))
105105+ blob_urls.append((url, blob_cid, image.get("alt")))
110106 case "app.bsky.embed.video":
111107 blob_cid = embed["video"]["ref"]["$link"]
112108 url = f"{self.pds}/xrpc/com.atproto.sync.getBlob?did={self.did}&cid={blob_cid}"
113113- self.log.info("Downloading %s...", blob_cid)
114114- blob: Blob | None = download_blob(url, embed.get("alt"))
115115- if not blob:
116116- self.log.error(
117117- "Skipping %s! Failed to download blob %s.",
118118- post_uri,
119119- blob_cid,
120120- )
121121- return
122122- post.attachments.put(MediaAttachment(blobs=[blob]))
109109+ blob_urls.append((url, blob_cid, embed.get("alt")))
123110 case _:
124111 self.log.warning(f"Unhandled embedd type {embed['$type']}")
125112 pass
113113+ if embed:
114114+ handle_embeds(embed)
115115+116116+ if blob_urls:
117117+ blobs: list[Blob] = []
118118+ for url, cid, alt in blob_urls:
119119+ self.log.info("Downloading %s...", cid)
120120+ blob: Blob | None = download_blob(url, alt)
121121+ if not blob:
122122+ self.log.error(
123123+ "Skipping %s! Failed to download blob %s.", post_uri, cid
124124+ )
125125+ return
126126+ blobs.append(blob)
127127+ post.attachments.put(MediaAttachment(blobs=blobs))
126128127129 if "langs" in record:
128130 post.attachments.put(LanguagesAttachment(langs=record["langs"]))