A CLI for downloading posts in bulk from Bluesky from specified a account
Project description
mass-downloader-for-bluesky
mass-downloader-for-bluesky (mdfb) is a Python cli application that can download large amounts of posts from bluesky from any given account.
Installation
You will need Python to be installed to use this CLI.
You can install via pip by:
pip install mdfb
Manual
Have Poetry installed.
Then clone the project, open a poetry shell and then install all dependencies.
git clone git@github.com:IbrahimHajiAbdi/mass-downloader-for-bluesky.git
cd mdfb
poetry shell
poetry install
Usage
mdfb works by using the public API offered by bluesky to retrieve posts liked, reposted or posted by the desired account.
mdfb will download the information for a post and the accompanying media, video or image(s). If there is no image(s) or video, it will just download the information of the post. The information of the post will be a JSON file and have lots of accompanying data, such as the text in the post, creation time of the post and author details. Currently, the retrieved posts start from the latest post to the oldest.
You will need to be inside a poetry shell to use mdfb if installed manually
Examples
Some example commands would be:
mdfb download --handle bsky.app -l 10 --like --threads 3 --format "{RKEY}_{HANDLE}" ./media/
mdfb download -d did:plc:z72i7hdynmk6r22z27h6tvur --archive --like --threads 3 --format "{DID}_{HANDLE}" ./media/
mdfb download --handle bsky.app --update --like --threads 3 --format "{RKEY}_{HANDLE}" ./media/
mdfb download --restore bsky.app --like --threads 3 --format "{RKEY}_{HANDLE}" ./media/
Naming Convention
By default, mdfb's naming convention is: "{rkey}_{handle}_{text}". If it is downloading a post with multiple images then the naming will be: "{rkey}_{handle}_{text}_{i}", where "i" represents the order of the images in the post ranging from 1 - 4. In addition, the filenames are limited to 256 bytes and will be truncated down to that size.
However, you can specify the name of the files by using the --format flag and passing a valid format string, e.g. "{RKEY}_{DID}". You can put anything in the format string inbetween the keywords. This is case-sensitive.
For --format, the valid keywords are:
RKEYDIDHANDLETEXTDISPLAY_NAME
Download Amount
When specifying the limit, this will be true for all types of post downloaded. For example:
mdfb download --handle bsky.app -l 100 --like --repost --post ./media/
This would download 100 likes, reposts and post, totalling 300 posts downloaded.
Furthermore, you can archive whole accounts. For exmaple:
mdfb download --handle bsky.app --archive --like --repost --threads 3 --format "{DID}_{HANDLE}" ./media/
This would download all likes and reposts.
Database
When downloading posts, mdfb inserts into the database some post identifiers. This allows for you to download only new posts from an account that you haven't downloaded yet.
However, there are some constraints, if you delete a file, this is not reflected in the database and thus, if you use the --update flag, it will not redownload it. Furthermore, the posts identifiers are only committed to the database once all posts have been downloaded, so if mdfb topples over during downloading, none of the posts downloaded will be reflected into the database.
The database is stored in: (Linux) ~/.local/share/mdfb/, (Windows) C:\\Users\\$USER\\AppData\\Local\\mdfb and (macOS) /Users/$USER/Library/Application Support/mdfb.
Example
mdfb db --delete_user bsky.app
Note
The maximum number of threads is currently 3, that can be changed in the mdfb/utils/constants.py file. Furthermore, there are more constants that can be changed in that file, such as delay between each request and the number of retires before marking that post as a failure and continuing.
Subcommands and arguments
download--handle- The handle of the target account.
--did, -d- The DID of the target account.
--limit, -l- The amount of posts that want to be downloaded.
--archive- Downloads all posts from the selected post type.
--update, -u- Downloads all of the latest posts that haven't been downloaded.
directory- Positional argument, where all the downloaded files are to be located. Required.
--threads, -t- The amount of threads wanted to download posts more efficiently, maximum number of threads is 3.
--format, -f- Format string that file's will use for their name. Furthermore the keywords used are case-sensitive and should be all upper case.
--like- To retrieved liked posts
--repost- To retrieved reposts
--post- To retrieved posts
--media-types- Only download posts that contain this specified type of media. Valid keywords are: image, video and text.
--include, -i- Whether to include only json information or media from the post.
--restore- Downloads all posts stored in the database, can optionally pass a did or handle to only restore posts from that account.
db--delete_user- Deletes all posts associated with the given user from the database. Have to pass the handle of the user.
generic commands--resource, -r- Logs resource usage for memory and cpu every 5 seconds.
Note
At least one of the flags: --like, --repost, --post are required (when using download).
Both (--did, -d and --handle) and (--archive, --limit, -l and --update) are mutually exclusive, and one of each of them is required as well (when using download).
The argument --media-types needs to be either before or after any positional arguments.
E.g.
mdfb download --handle bsky.app --update --like --threads 3 --media-types image --format "{RKEY}_{HANDLE}" ./media/`
Furthermore, if you want to filter by text and image or media and then use --include by media, this would not include any post filter by text. E.g.
mdfb download --handle bsky.app --update --like --threads 3 --media-types image text -i media ./media/`
This would just download images only.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdfb-1.5.4.tar.gz.
File metadata
- Download URL: mdfb-1.5.4.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
130458ebb903fecca539facf26df4244a2f28948b2b984f4ea4eefbe599fc301
|
|
| MD5 |
b359fa75d6e1169c88c96a7ea719fc14
|
|
| BLAKE2b-256 |
1039068b4e3257bcd5f9d2f32d69b776d26d308f59671e5db17eac022cd070af
|
File details
Details for the file mdfb-1.5.4-py3-none-any.whl.
File metadata
- Download URL: mdfb-1.5.4-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fc972c5a491c7b8ec30f7ff80bf984790091f8f31a78841c0a9b16baa4dc3b4
|
|
| MD5 |
fe12b563d6e94c5c5056da086dcc8ed6
|
|
| BLAKE2b-256 |
eac84a1d1685f836b38952a606a4b1702c78cea9ffaeae1eff52fbf9d8f6638b
|