Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: add crawler config options (Bluesky) (#2132)

NTFSvolume1bec9139d5af
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca6a53356..8773a9639 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Support premium URLs (direct links)(GoFile)
+- BlueSky support
- FileditchAlbums support
### Changed
diff --git a/cyberdrop_dl/config/crawlers.py b/cyberdrop_dl/config/crawlers.py
index b204b4271..d9b65bace 100644
--- a/cyberdrop_dl/config/crawlers.py
+++ b/cyberdrop_dl/config/crawlers.py
@@ -59,7 +59,7 @@ class TwitterArticlesConfig(ConfigModel):
class TwitterConfig(ConfigModel):
cards: bool = True
- "Parse and download cards in a post (embeds from thirdparty sites)"
+ "Parse and download cards in a post (embeds from third-party sites)"
threads: bool = True
"Downloads all posts in a thread (All direct replies from OP to their own tweet)"
@@ -78,6 +78,20 @@ class TwitterConfig(ConfigModel):
# "large", "medium", or "small" are always available
+class BlueSkyConfig(ConfigModel):
+ external: bool = True
+ "Parse and download embeds from third-party sites"
+
+ threads: bool = True
+ "Downloads all posts in a thread (All direct replies from OP to their own post)"
+
+ content_urls: bool = True
+ "Parse and try to download any URL found inside the text of a post"
+
+ reposts: bool = False
+ "Download media from reposts in the user's timeline"
+
+
class OctaveMusicConfig(ConfigModel):
quality: Literal["lossless", "mp3-320"] = "mp3-320"
"Quality of audio file to download (lossless are .flac files)"
@@ -169,6 +183,7 @@ class Crawlers(ConfigGroup, name=None):
"Name of crawlers to disable for the current run"
bandcamp: BandcampConfig = Field(default_factory=BandcampConfig)
+ bluesky: BlueSkyConfig = Field(default_factory=BlueSkyConfig)
clonr: ClonrConfig = Field(default_factory=ClonrConfig)
clypit: ClypitConfig = Field(default_factory=ClypitConfig)
generic: GenericCrawlers = Field(default_factory=GenericCrawlers)
diff --git a/cyberdrop_dl/config/default.yaml b/cyberdrop_dl/config/default.yaml
index ad94a355e..b6c84a827 100644
--- a/cyberdrop_dl/config/default.yaml
+++ b/cyberdrop_dl/config/default.yaml
@@ -26,6 +26,11 @@ crawlers:
- vorbis
- aiff
- alas
+ bluesky:
+ content_urls: true
+ external: true
+ reposts: false
+ threads: true
clonr:
use_source: false
zip: false
diff --git a/cyberdrop_dl/config/schema.json b/cyberdrop_dl/config/schema.json
index 8af6101b1..c0d03b539 100644
--- a/cyberdrop_dl/config/schema.json
+++ b/cyberdrop_dl/config/schema.json
@@ -101,6 +101,33 @@
"title": "BandcampConfig",
"type": "object"
},
+ "BlueSkyConfig": {
+ "additionalProperties": false,
+ "properties": {
+ "external": {
+ "default": true,
+ "title": "External",
+ "type": "boolean"
+ },
+ "threads": {
+ "default": true,
+ "title": "Threads",
+ "type": "boolean"
+ },
+ "content_urls": {
+ "default": true,
+ "title": "Content Urls",
+ "type": "boolean"
+ },
+ "reposts": {
+ "default": false,
+ "title": "Reposts",
+ "type": "boolean"
+ }
+ },
+ "title": "BlueSkyConfig",
+ "type": "object"
+ },
"ByteSizeSerilized": {
"anyOf": [
{
@@ -160,6 +187,9 @@
"bandcamp": {
"$ref": "#/$defs/BandcampConfig"
},
+ "bluesky": {
+ "$ref": "#/$defs/BlueSkyConfig"
+ },
"clonr": {
"$ref": "#/$defs/ClonrConfig"
},
diff --git a/cyberdrop_dl/crawlers/bluesky/crawler.py b/cyberdrop_dl/crawlers/bluesky/crawler.py
index 5c48658f6..79d97c719 100644
--- a/cyberdrop_dl/crawlers/bluesky/crawler.py
+++ b/cyberdrop_dl/crawlers/bluesky/crawler.py
@@ -13,6 +13,7 @@ from cyberdrop_dl.utils.errors import error_handling_wrapper
if TYPE_CHECKING:
from collections.abc import Generator, Mapping
+ from cyberdrop_dl.config.crawlers import BlueSkyConfig
from cyberdrop_dl.crawlers.bluesky.types import Blob, FeedFilter, LegacyBlob, PostView
from cyberdrop_dl.url_objects import ScrapeItem
@@ -30,6 +31,7 @@ class BlueskyCrawler(Crawler):
DEFAULT_POST_TITLE_FORMAT: ClassVar[str] = "{date:%Y-%m-%d} - {id}"
def __post_init__(self) -> None:
+ self.__config__: BlueSkyConfig = self.config.crawlers.bluesky
self.api: BlueSkyAPI = BlueSkyAPI.from_crawler(self)
@property
@@ -40,8 +42,14 @@ class BlueskyCrawler(Crawler):
match scrape_item.url.parts[1:]:
case ["profile", user, "post", post_id, *_]:
await self.post(scrape_item, user, post_id)
- case ["profile", user]:
+ case ["profile", user] | ["profile", user, "posts"]:
await self.user(scrape_item, user, "posts_and_author_threads")
+ case ["profile", user, "media"]:
+ await self.user(scrape_item, user, "posts_with_media")
+ case ["profile", user, "replies"]:
+ await self.user(scrape_item, user, "posts_with_replies")
+ case ["profile", user, "video"]:
+ await self.user(scrape_item, user, "posts_with_video")
case _:
raise ValueError
@@ -49,6 +57,8 @@ class BlueskyCrawler(Crawler):
async def post(self, scrape_item: ScrapeItem, actor: str, post_id: str) -> None:
post, replies = await self.api.thread(actor, post_id)
self._post(scrape_item, post)
+ if not self.__config__.threads:
+ return
for reply in replies:
new_item = scrape_item.create_child(self.PRIMARY_URL / reply.web_path)
self._post(new_item, reply)
@@ -57,7 +67,17 @@ class BlueskyCrawler(Crawler):
@error_handling_wrapper
async def user(self, scrape_item: ScrapeItem, actor: str, feed_filter: FeedFilter) -> None:
scrape_item.setup_as_profile("")
+ user_did = await self.api.resolve_handle(actor)
async for post in self.api.author_feed(actor, feed_filter):
+ if not self.__config__.reposts and post.author.did != user_did:
+ self.log.warning(
+ "Skipping post %s by config options [repost]. Original author: @%s, reposted by: @%s",
+ post.id,
+ user_did,
+ post.author.did,
+ )
+ continue
+
new_item = scrape_item.create_child(self.PRIMARY_URL / post.web_path)
self._post(new_item, post)
scrape_item.add_children()
@@ -70,10 +90,22 @@ class BlueskyCrawler(Crawler):
self.create_eager_task(self.write_metadata(scrape_item, f"post {post.id}", post))
for media in _extract_media(post.record):
+ if "external" in media.type and not self.__config__.external:
+ self.log.info(
+ "Skipping external media (cid=%s) in post %s by config options [%s]", media.cid, post.id, media.type
+ )
+ self.tui.files.stats.skipped += 1
+ continue
+
self.create_eager_task(self._media(scrape_item, media, post.author.did))
scrape_item.add_children()
for url in _extract_links(post.record):
+ if not self.__config__.content_urls:
+ self.log.info("Skipping %s in post %s by config options [content_urls]", url, post.id)
+ self.tui.files.stats.skipped += 1
+ continue
+
self.handle_external_links(scrape_item.create_child(self.parse_url(url)))
scrape_item.add_children()
diff --git a/cyberdrop_dl/crawlers/bluesky/types.py b/cyberdrop_dl/crawlers/bluesky/types.py
index 91254c3b4..0d61708aa 100644
--- a/cyberdrop_dl/crawlers/bluesky/types.py
+++ b/cyberdrop_dl/crawlers/bluesky/types.py
@@ -110,7 +110,7 @@ class External(Asset):
type MediaAsset = Video | Image | Images | Gallery | External
[email protected](frozen=True, slots=True)
[email protected](frozen=True, slots=True, kw_only=True)
class Media:
type: str
cid: str