audible-cli icon indicating copy to clipboard operation
audible-cli copied to clipboard

Remove and add items to library

Open mkb79 opened this issue 2 years ago • 5 comments

Hmm iis there any command to clean all library at once?

Also, how can i add a book to library using audible cli and asin?

(im not good using apis)

Originally posted by @tdguchi in https://github.com/mkb79/audible-cli/issues/118#issuecomment-1237925261

mkb79 avatar Sep 07 '22 07:09 mkb79

There is no command for this yet. But you can use the API with audible api -m put -b '{"asin": "ASIN_TO_ADD"}' -i 4 library/item

I'm sure this is a me issue. I made a script following what you said above (also figured this git would be better for this comment):

readarray -t asin < asin.txt;

for a in "${asin[@]}"
do  
    echo $a;
    audible api -m put -b '{"asin": $a}' -i 4 library/item
done;

asin.txt contains all the asin I would like to auto-add. My script returns the following:

$ bash audible_add_to_library.sh 
887558828
Uncaught Exception
Traceback (most recent call last):
  File "/home/joey/audible-test8/lib/python3.8/site-packages/audible_cli/cli.py", line 60, in main
    sys.exit(cli(*args, **kwargs))
  File "/home/joey/audible-test8/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/joey/audible-test8/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/joey/audible-test8/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/joey/audible-test8/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/joey/audible-test8/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/joey/audible-test8/lib/python3.8/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/joey/audible-test8/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/joey/audible-test8/lib/python3.8/site-packages/audible_cli/cmds/cmd_api.py", line 82, in cli
    body = json.loads(body)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 10 (char 9)

Just hoping I can have some help here.

johnlescault avatar Sep 18 '22 21:09 johnlescault

Solved my own issue. Had to do with the single quotes. Here is how I solved it

readarray -t asin < asin.txt;

for a in "${asin[@]}"
do  
    a='{"asin": "'"$a"'"}'
    echo $a;
    audible api -m put -b "$a" -i 4 library/item
done;

johnlescault avatar Sep 19 '22 00:09 johnlescault

@johnlescault Thank you for writing the script. I'll work now on an implementation for adding and removing books. It will look similar to the wishlist command.

mkb79 avatar Sep 21 '22 11:09 mkb79

It could be useful to implement a subfunction to detect which asins are downloaded and flag them, so if you delete the .aaxc chapters or covers from the folder it doesnt download again (for large library and small disk space) unless you add another flag to force re-download

tdguchi avatar Oct 01 '22 10:10 tdguchi

You can provide a --start-date and --end-date for this. So you can initially use audible download ... --all --end-date 2022-10-1 after that successfully download of all items you can remove them and next time you run audible download ... --all --start-date 2022-10-1.

mkb79 avatar Oct 01 '22 10:10 mkb79