Skip to content

Commit

Permalink
[bluesky] add 'author["instance"]' metadata (#4438)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Nov 2, 2024
1 parent 99fe2b1 commit 9deed87
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
12 changes: 10 additions & 2 deletions gallery_dl/extractor/bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ def posts(self):
def _pid(self, post):
return post["uri"].rpartition("/")[2]

@memcache(keyarg=1)
def _instance(self, handle):
return ".".join(handle.rsplit(".", 2)[-2:])

def _prepare(self, post):
author = post["author"]
author["instance"] = self._instance(author["handle"])

if self._metadata_facets:
if "facets" in post:
post["hashtags"] = tags = []
Expand All @@ -102,7 +109,7 @@ def _prepare(self, post):
post["hashtags"] = post["mentions"] = post["uris"] = ()

if self._metadata_user:
post["user"] = self._user or post["author"]
post["user"] = self._user or author

post["instance"] = self.instance
post["post_id"] = self._pid(post)
Expand Down Expand Up @@ -440,7 +447,8 @@ def _did_from_actor(self, actor, user_did=False):
if user_did and not extr.config("reposts", False):
extr._user_did = did
if extr._metadata_user:
extr._user = self.get_profile(did)
extr._user = user = self.get_profile(did)
user["instance"] = extr._instance(user["handle"])

return did

Expand Down
47 changes: 47 additions & 0 deletions test/results/bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"did" : "did:plc:z72i7hdynmk6r22z27h6tvur",
"displayName": "Bluesky",
"handle" : "bsky.app",
"instance" : "bsky.app",
"labels" : [],
},
"cid" : "bafyreihh7m6bfrwlcjfklwturmja7qfse5gte7lskpmgw76flivimbnoqm",
Expand Down Expand Up @@ -181,6 +182,7 @@
"followersCount": int,
"followsCount" : int,
"handle" : "bsky.app",
"instance" : "bsky.app",
"indexedAt" : "2024-08-30T21:49:26.737Z",
"labels" : [],
"postsCount" : int,
Expand All @@ -199,6 +201,7 @@
"did" : "did:plc:cslxjqkeexku6elp5xowxkq7",
"displayName": "mikf",
"handle" : "mikf.bsky.social",
"instance" : "bsky.social",
"labels" : [],
},
"cid" : "bafyreihtck7clocti2qshaiounadof74pxqhz7gnvbstxujqzhlodigqru",
Expand Down Expand Up @@ -295,4 +298,48 @@
"text" : {"quote with media", ""},
},

{
"#url" : "https://bsky.app/profile/nytimes.com/post/3l7xvcjgdxg2g",
"#comment" : "instance metadata",
"#class" : bluesky.BlueskyPostExtractor,
"#options" : {"metadata": "user"},

"instance": "bsky.app",
"author": {
"createdAt" : "2023-06-05T18:50:31.498Z",
"did" : "did:plc:eclio37ymobqex2ncko63h4r",
"displayName": "The New York Times",
"handle" : "nytimes.com",
"instance" : "nytimes.com",
},
"user": {
"avatar" : "https://cdn.bsky.app/img/avatar/plain/did:plc:eclio37ymobqex2ncko63h4r/bafkreidvvqj5jymmpaeklwkpq6gi532el447mjy2yultuukypzqm5ohfju@jpeg",
"banner" : "https://cdn.bsky.app/img/banner/plain/did:plc:eclio37ymobqex2ncko63h4r/bafkreiaiorkgl6t2j5w3sf6nj37drvwuvriq3e3vqwf4yn3pchpwfbekta@jpeg",
"createdAt" : "2023-06-05T18:50:31.498Z",
"description" : "In-depth, independent reporting to better understand the world, now on Bluesky. News tips? Share them here: http://nyti.ms/2FVHq9v",
"did" : "did:plc:eclio37ymobqex2ncko63h4r",
"displayName" : "The New York Times",
"followersCount": int,
"followsCount" : int,
"handle" : "nytimes.com",
"instance" : "nytimes.com",
"indexedAt" : "2024-01-20T05:04:46.757Z",
"labels" : [],
"postsCount" : int,
},
},

{
"#url" : "https://bsky.app/profile/stupidsaru.woke.cat/post/3l66wwwqw6u2w",
"#comment" : "instance metadata",
"#class" : bluesky.BlueskyPostExtractor,

"author": {
"createdAt": "2023-08-31T23:28:42.305Z",
"did" : "did:plc:b7s3pdcjk6qvxmu3n674hlgj",
"handle" : "stupidsaru.woke.cat",
"instance" : "woke.cat",
},
},

)

0 comments on commit 9deed87

Please sign in to comment.