Add db support for library
@devvythelopper @rmcrackan and all other GitHub users
The code in the feature/db-ibrary branch is most ready for now. Before I refactor and format it, I need your help. Can you test the code and report back when running the following commands:
-
audible db library sync --initHow many items do you have and how long does it take to sync your library. -
audible db library removeDoes it remove the file? -
audible db library restore --fresh -
Adding some free books to your library and remove some else and run
audible db library syncThis should run fast also if you have thousands of items. The client requests a delta update only for the changed items.
If you are ready you can remove the database by running audible db library remove.
If the work is done, I will rework the download command to use the database instead of fetching the whole library every time on execution. Maybe I will add another table to track downloaded items instead of searching in the download directory, if the files already exist.
Cool feature. I'll see when I'll find the time though, the coming week is a bit busy, hope you don't have any time constraints.
You'd need commands to check for non-existing files then too.
@devvythelopper
You'd need commands to check for non-existing files then too.
Do you mean a command like check-integrity which can verify that a db file exist and the schema is fine?
@mkb79 I just got back in town and unfortunately I'm leaving again soon. I cloned the branch but I'm not familiar with running python. For windows, how can I help?
@rmcrackan
As long as you have at least Python 3.10 and uv installed on your machine, you have two options:
Option A – with clone
- Clone the correct branch:
git clone --branch feature/db-library --single-branch https://github.com/mkb79/audible-cli.git - Change into the cloned directory.
- Prefix all commands with
uv run(for example:
).uv run audible db library sync --init
Option B – without clone
- Prefix all commands with:
Example:uvx --fresh --from git+https://github.com/mkb79/audible-cli@feature/db-library
Theuvx --fresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library sync --init--freshflag ensures that the repository is cloned from GitHub every time before executing the command.
If you are confident that there haven’t been any changes, you can omit--freshanduvxwill use the cached version instead.
💡 Almost forgot: if you use uv and uvx, you don’t need to have a Python interpreter installed.
uv will automatically handle that for you on the first run.
Manual setup with virtual environment
If you prefer to set up the project manually using a virtual environment instead of uv, follow these steps:
- Navigate into the cloned directory.
- Create a virtual environment:
python3 -m venv venv - Activate the virtual environment:
- On Windows with CMD:
.\venv\Scripts\activate.bat - On Windows with PowerShell:
.\venv\Scripts\activate.ps1
- On Windows with CMD:
- Run the initialization command:
audible db library --init
You'd need commands to check for non-existing files then too.
Do you mean a command like
check-integritywhich can verify that a db file exist and the schema is fine?
No, I mean that there needs to be a way to check the actual .aax, -annotations.json, etc. files for whether they exist instead of just checking whether the .aax file (etc) has been marked as downloaded in the database. And that I like the current default which is namely that file-existance is being checked for.
@mkb79 I just got back in town and unfortunately I'm leaving again soon. I cloned the branch but I'm not familiar with running python. For windows, how can I help?
@rmcrackan I usually use git worktree to check out different branches. That way you have only one git. Then I cd and use python3 -m venv .venv and then from fish shell source ./.venv/bin/activate.fish or source ./.venv/bin/activate from bash. I frankly don't know how to activate the venv on windows. If you make changes to the code, running can be done via PYTHONPATH=src python3 pyi_entrypoint.py db library --init. Well, in a unix shell; if you use windows, you'd have to set the PYTHONPATH environment variable in some windows specific way.
@mkb79 I just got back in town and unfortunately I'm leaving again soon. I cloned the branch but I'm not familiar with running python. For windows, how can I help?
@rmcrackan I usually use
git worktreeto check out different branches. That way you have only one git. Then Icdand usepython3 -m venv .venvand then from fish shellsource ./.venv/bin/activate.fishorsource ./.venv/bin/activatefrom bash. I frankly don't know how to activate the venv on windows. If you make changes to the code, running can be done viaPYTHONPATH=src python3 pyi_entrypoint.py db library --init. Well, in a unix shell; if you use windows, you'd have to set the PYTHONPATH environment variable in some windows specific way.
@rmcrackan
Alternatively, if you don’t plan to modify the code and therefore don’t need to clone the repository, you can simply use the uvx command. This will automatically provide the uv tool in an isolated environment, without requiring a system-wide Python installation or a local checkout of the repository.
Edit:
One important note I forgot to mention: if you haven’t used audible-cli before, you’ll need to run audible quickstart once to complete the initial setup.
I don't understand python's habits. From each of these folders:
- C:\Dev\audible-cli
- C:\Dev\audible-cli\src
- C:\Dev\audible-cli\src\audible_cli
I have tried each of these commands:
> audible quickstart
'audible' is not recognized as an internal or external command,
operable program or batch file.
> py audible quickstart
C:\Users\rmcrackan\AppData\Local\Programs\Python\Python313\python.exe:
can't open file 'C:\\Dev\\AUDIBLE_CLI\\audible-cli\\src\\audible_cli\\audible':
[Errno 2] No such file or directory
> py -m audible quickstart
C:\Users\rmcrackan\AppData\Local\Programs\Python\Python313\python.exe: No module named audible
Just to confirm, from those same folders, this works:
> py -V
Python 3.13.5
Can you use uv to run the package. It's very easy with uv to work with Python commands.
Can you use uv to run the package. It's very easy with uv to work with Python commands.
Trying that in each of these directories:
C:\Dev\audible-cli>uv audible quickstart
error: unrecognized subcommand 'audible'
tip: a similar subcommand exists: 'build'
Usage: uv [OPTIONS] <COMMAND>
For more information, try '--help'.
C:\Dev\audible-cli\src>uv audible quickstart
error: unrecognized subcommand 'audible'
tip: a similar subcommand exists: 'build'
Usage: uv [OPTIONS] <COMMAND>
For more information, try '--help'.
C:\Dev\audible-cli\src\audible_cli>uv audible quickstart
error: unrecognized subcommand 'audible'
tip: a similar subcommand exists: 'build'
Usage: uv [OPTIONS] <COMMAND>
For more information, try '--help'.
Take a look at Option B here.
Simple run uvx --fresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible -h
@rmcrackan Maybe my mistake. Try --refresh instead of --fresh! Thank you!
Progress:
@rmcrackan
You have to provide uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library before the audible command. Or you can install audible with uv tool install.
uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible quickstart
success
uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library sync --init [sync] mode=full Upserted=1582, Soft-deleted=0, new state_token=1757132213333
<30 seconds
audible db library remove Does it remove the file?
Where is the file? I'd like to locate it before this test.
Where is the file? I'd like to locate it before this test.
Ignore. I found it.
2:
audible db library remove Does it remove the file?
Yes. db file deleted. toml and json are unchanged
3:
uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library restore --fresh
Installed 29 packages in 416ms
Usage: audible db library restore [OPTIONS]
Try 'audible db library restore -h' for help.
Error: Missing option '--payload'.
uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library restore --refresh
Installed 29 packages in 413ms
Usage: audible db library restore [OPTIONS]
Try 'audible db library restore -h' for help.
Error: No such option: --refresh (Possible options: --fresh, --merge)
Do you tried sync --init? How long does it take to load your lib?
sync init is above -- https://github.com/mkb79/audible-cli/issues/240#issuecomment-3266396492
it took just under 30 seconds
Ah okay. Thanks. This is much for ~1.500 titles.
Do you have exported your db before you have used the restore command?
I just now deleted my files so I can start fresh. Each of the following is a separate command which seems to do some kind of environment initialization each time. That is: I seem to be creating a new session and incurring that overhead each time. I'm not familiar with uvx so I don't know if it's possible to do all of these in the same session instead. These are the only commands I have run:
uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible -h
result: prints the help "usage" options and commands
uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible quickstart
result: 2 files created:
C:\Users\rmcrackan\AppData\Local\Audible\config.toml
C:\Users\rmcrackan\AppData\Local\Audible\cupidneedsglasses_gmail.com.json
uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library sync --init
result:
[sync] mode=full Upserted=1582, Soft-deleted=0, new state_token=1757343637893
Ran for about 29 seconds
created: C:\Users\rmcrackan\AppData\Local\Audible\library_5f1f4017cbf7b590.sqlite
uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library remove
result:
deleted: C:\Users\rmcrackan\AppData\Local\Audible\library_5f1f4017cbf7b590.sqlite
unchanged: C:\Users\rmcrackan\AppData\Local\Audible\config.toml
unchanged: C:\Users\rmcrackan\AppData\Local\Audible\cupidneedsglasses_gmail.com.json
After the above, I was not able to run: audible db library restore --fresh
Error: Missing option '--payload'
@rmcrackan
Sorry my mistake. You have to run audible db library export to get your library.json. Then you can restore the db with this file.
I think this is a complete workflow of what you wanted tested:
-
> uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible -hresult: prints the help "usage" options and commands -
> uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible quickstartresult: 2 files created:
C:\Users\rmcrackan\AppData\Local\Audible\config.toml
C:\Users\rmcrackan\AppData\Local\Audible\cupidneedsglasses_gmail.com.json -
> uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library sync --initresult:
[sync] mode=full Upserted=1582, Soft-deleted=0, new state_token=1757343637893
Ran for about 29 seconds
created: C:\Users\rmcrackan\AppData\Local\Audible\library_5f1f4017cbf7b590.sqlite -
> uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library exportcreated: \library.json -
> uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library removeresult:
deleted: C:\Users\rmcrackan\AppData\Local\Audible\library_5f1f4017cbf7b590.sqlite
unchanged: C:\Users\rmcrackan\AppData\Local\Audible\config.toml
unchanged: C:\Users\rmcrackan\AppData\Local\Audible\cupidneedsglasses_gmail.com.json -
> uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library restore --fresh --payload library.json[restore] Upserted 1581 ? C:\Users\rmcrackan\AppData\Local\Audible\library_5f1f4017cbf7b590.sqlite (merge mode)
created: C:\Users\rmcrackan\AppData\Local\Audible\library_5f1f4017cbf7b590.sqlite -
Add to library: https://www.audible.com/pd/Headcase-Audiobook/B0F668ZJ4J
-
> uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library sync[sync] mode=delta Upserted=1, Soft-deleted=0, new state_token=1757431347606
3-4 sec. Reminder: each step is running in its own session with init overhead -
Remove from library: https://www.audible.com/pd/Headcase-Audiobook/B0F668ZJ4J
-
> uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library sync[sync] mode=delta Upserted=0, Soft-deleted=0, new state_token=1757431347606
NOTE: 'Headcase' not removed
> uvx --refresh --from git+https://github.com/mkb79/audible-cli@feature/db-library audible db library export[export] Wrote 1582 items to library.json
audible db library export: 'Headcase' is still present in export
@rmcrackan Thank you for testing. Step 10 is strange. I've tested it myself with 5 - 6 different asins. All without any sync issues when adding or removing.
I tested the following library commands:
sync --initexportremoverestore --fresh --payloadsync(with new book, and also after removing one book)countsearch-ftssearchlist-deletedinspect(with various parameters)
All good for me.
I wonder what can be the use of full as it looks like restore ?
@mkb79 Do you have basic usage of audible db assets ?
I tested the following library commands:
sync --initexportremoverestore --fresh --payloadsync(with new book, and also after removing one book)countsearch-ftssearchlist-deletedinspect(with various parameters)All good for me.
I wonder what can be the use of
fullas it looks likerestore?
Hi. How long did the initial synchronization take? And how many titles do you have in your library? I want to know how performant the process is.
Do you have basic usage of audible db assets ?
The db assets command should manage the assets of the library. So storage location, asset type, etc. The db should later make it possible to quickly check which assets are still missing and downloadable. However, the status is not yet far advanced. Or was your question meant differently?
Hi. How long did the initial synchronization take? And how many titles do you have in your library? I want to know how performant the process is.
time audible db library sync --init
[sync] mode=full Upserted=590, Soft-deleted=0, new state_token=***
real 0m10.846s
user 0m0.629s
sys 0m0.330s
The db assets command should manage the assets of the library. So storage location, asset type, etc. The db should later make it possible to quickly check which assets are still missing and downloadable. However, the status is not yet far advanced. Or was your question meant differently?
I wonder the use of this command to leverage the maximum of audible-cli on my personal audible workflow (https://github.com/damajor/BALD). Library db was one thing I wanted to have for some time.
@damajor
The only catch with my current implementation is that the initial loading of the library runs synchronously over a continuation-token. Therefore, especially with large libraries it can take longer than before. However, the syncs run very fast, because only the diff is loaded.
But when everything is ready, you can of course use the database for your project. There are a lot of interesting things in it. You can take a look at the file that is created by db export command. Maybe you can use this to tag your converted files!