2024-12-02 19:58:33 +00:00
|
|
|
default: recent
|
|
|
|
|
|
|
|
recent: select-download-recent convert refile
|
|
|
|
@tree M4B/
|
|
|
|
|
|
|
|
full: select-download-full convert refile
|
2024-10-20 16:50:58 +01:00
|
|
|
@tree M4B/
|
|
|
|
|
2024-12-26 08:47:04 +00:00
|
|
|
doctor: # Check all required executables are found
|
2024-10-20 16:50:58 +01:00
|
|
|
@echo "Verify required executables are on the path:"
|
|
|
|
just _doc_require_exec_all audible just fzf jq ffmpeg refile-m4b
|
|
|
|
|
|
|
|
_doc_require_exec_all *exec:
|
|
|
|
for one in {{ exec }} ; do just _doc_require_exec ${one} ; done
|
|
|
|
|
|
|
|
_doc_require_exec exec:
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
export EXEC=$(which {{ exec }})
|
|
|
|
if test -z ${EXEC} ; then
|
|
|
|
echo "- MISSING : {{ exec }}"
|
|
|
|
else
|
|
|
|
echo "- OKAY : {{ exec }} => ${EXEC}"
|
|
|
|
fi
|
|
|
|
|
2024-12-26 08:47:04 +00:00
|
|
|
select-download-recent: # Select titles from those added in the latest library, and download them
|
2024-12-02 19:43:22 +00:00
|
|
|
just select-download library-recent.txt
|
|
|
|
|
2024-12-26 08:47:04 +00:00
|
|
|
select-download-full: # Select titles from the full latest library, and download them
|
2024-12-02 19:43:22 +00:00
|
|
|
just select-download $(just latest-library)
|
|
|
|
|
2024-12-26 08:47:04 +00:00
|
|
|
select-download library: # Select titles from the {{ library }}, and download them
|
2024-10-20 16:50:58 +01:00
|
|
|
#!/usr/bin/env bash
|
2024-12-26 11:50:49 +00:00
|
|
|
SELECTION=$(cat {{library}} | sort -k 2 | fzf --exact --multi --cycle --scroll-off=3 --reverse)
|
2024-10-20 16:50:58 +01:00
|
|
|
ASINS=""
|
|
|
|
while IFS= read -r LINE ; do
|
|
|
|
echo "$LINE"
|
|
|
|
export ASIN=$(echo $LINE | cut -d: -f 1)
|
|
|
|
echo "ASIN: $ASIN"
|
|
|
|
ASINS="${ASINS} --asin ${ASIN}"
|
|
|
|
done <<< $SELECTION
|
|
|
|
just _download-asin $ASINS
|
|
|
|
|
2024-12-26 08:47:04 +00:00
|
|
|
fetch-library: # Download the latest version of the Library
|
2024-12-02 19:43:22 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
PREVIOUS=$(just latest-library)
|
|
|
|
audible library list | sort > library-$(date +%Y-%m-%d).txt
|
|
|
|
CURRENT=$(just latest-library)
|
|
|
|
comm -23 $CURRENT $PREVIOUS > library-recent.txt
|
|
|
|
echo "New additions:"
|
|
|
|
cat library-recent.txt
|
2024-10-20 16:50:58 +01:00
|
|
|
|
|
|
|
@latest-library:
|
2024-12-02 19:43:22 +00:00
|
|
|
ls library-*.txt | grep -v recent | tail -n 1
|
2024-10-20 16:50:58 +01:00
|
|
|
|
|
|
|
_require_dir *dirs:
|
|
|
|
mkdir {{ dirs }} 2>/dev/null || true
|
|
|
|
|
|
|
|
_move target *files:
|
2024-11-03 09:39:26 +00:00
|
|
|
mv {{ files }} {{ target }} 2>/dev/null || true
|
2024-10-20 16:50:58 +01:00
|
|
|
|
|
|
|
_download-asin *asins:
|
|
|
|
just _require_dir TEMP
|
|
|
|
cd TEMP && audible download --aax-fallback {{ asins }}
|
|
|
|
just post-download
|
|
|
|
|
2024-12-26 08:47:04 +00:00
|
|
|
post-download: # Move successfully downloaded aax, aaxc and voucher sinto AAX or AAXC
|
2024-10-20 16:50:58 +01:00
|
|
|
just _require_dir AAX AAXC
|
|
|
|
just _move AAX/ TEMP/*.aax
|
|
|
|
just _move AAXC/ TEMP/*.aaxc TEMP/*.voucher
|
|
|
|
|
|
|
|
convert: convert-aax convert-aaxc
|
|
|
|
|
2024-12-26 08:47:04 +00:00
|
|
|
convert-aax: # Convert all the AAX files to M4B
|
2024-11-03 09:19:33 +00:00
|
|
|
#!/usr/bin/env bash
|
2024-10-20 16:50:58 +01:00
|
|
|
just _require_dir M4B
|
2024-11-03 09:39:26 +00:00
|
|
|
if [ $(fd . AAX | wc -l) -gt 0 ]
|
2024-11-03 09:19:33 +00:00
|
|
|
then
|
|
|
|
for F in AAX/*.aax
|
|
|
|
do
|
|
|
|
O=M4B/$(basename $F .aax).m4b
|
|
|
|
ffmpeg \
|
|
|
|
-y \
|
|
|
|
-activation_bytes $(jq .activation_bytes ~/.audible/audible.json | tr '\"' ' ') \
|
|
|
|
-i $F \
|
|
|
|
-codec copy \
|
|
|
|
$O
|
|
|
|
rm $F
|
|
|
|
done
|
2024-11-03 09:39:26 +00:00
|
|
|
else
|
|
|
|
echo No AAX to convert
|
2024-11-03 09:19:33 +00:00
|
|
|
fi
|
2024-10-20 16:50:58 +01:00
|
|
|
|
2024-12-26 08:47:04 +00:00
|
|
|
convert-aaxc: # Convert all the AAXC files to M4B
|
2024-11-03 09:19:33 +00:00
|
|
|
#!/usr/bin/env bash
|
2024-10-20 16:50:58 +01:00
|
|
|
just _require_dir M4B
|
2024-11-03 09:39:26 +00:00
|
|
|
if [ $(fd . AAXC | wc -l) -gt 0 ]
|
2024-11-03 09:19:33 +00:00
|
|
|
then
|
|
|
|
for AAXC in AAXC/*.aaxc
|
|
|
|
do
|
|
|
|
VOUCHER="${AAXC%.aaxc}.voucher"
|
|
|
|
M4B="M4B/$(basename ${AAXC%.aaxc}).m4b"
|
|
|
|
just _convert-one-aaxc $AAXC $VOUCHER $M4B
|
|
|
|
done
|
2024-11-03 09:39:26 +00:00
|
|
|
else
|
|
|
|
echo No AAXC to convert
|
2024-11-03 09:19:33 +00:00
|
|
|
fi
|
2024-10-20 16:50:58 +01:00
|
|
|
|
|
|
|
_convert-one-aaxc aaxc_file voucher_file m4b_file:
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
export KEY="$(jq .content_license.license_response.key {{ voucher_file }} | tr '\"' ' ')"
|
|
|
|
export IV="$(jq .content_license.license_response.iv {{ voucher_file }} | tr '\"' ' ')"
|
|
|
|
ffmpeg \
|
|
|
|
-audible_key $KEY \
|
|
|
|
-audible_iv $IV \
|
|
|
|
-i {{ aaxc_file }} \
|
|
|
|
-vn \
|
|
|
|
-c:a copy \
|
|
|
|
-map_metadata 0:g \
|
|
|
|
{{ m4b_file }} && \
|
|
|
|
rm {{ aaxc_file }} {{ voucher_file }}
|
|
|
|
|
2024-12-26 08:47:04 +00:00
|
|
|
refile: # Rename and move files in M4B based on their metadata
|
2024-10-20 16:50:58 +01:00
|
|
|
refile-m4b M4B
|
|
|
|
|
2024-12-26 08:47:04 +00:00
|
|
|
archive: # Move the contents of M4B to the archive
|
2024-11-03 09:19:33 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
if [ -d M4B ] && [ -n "${AUDIOBOOK_ARCHIVE}" ] && [ -d "${AUDIOBOOK_ARCHIVE}" ];
|
|
|
|
then
|
|
|
|
if [ $(fd . M4B | wc -l) -eq 0 ]
|
|
|
|
then
|
|
|
|
echo "WARN: Nothing to be archived"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
cd M4B && cp -v -R * "${AUDIOBOOK_ARCHIVE}"
|
2024-12-26 08:47:04 +00:00
|
|
|
just _clean M4B
|
2024-11-03 09:19:33 +00:00
|
|
|
else
|
|
|
|
echo "ERROR: No archive specified or no M4B directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-10-20 16:50:58 +01:00
|
|
|
|
2024-12-26 08:47:04 +00:00
|
|
|
clean: # Delete the directories TEMP, AAX, AAXC and M4B, including all files within
|
2024-12-02 19:43:22 +00:00
|
|
|
for target in TEMP AAX AAXC M4B ; do just _clean $target ; done
|
2024-10-20 16:50:58 +01:00
|
|
|
|
|
|
|
_clean target:
|
|
|
|
if [ -f {{ target }} -o -d {{ target }} ] ; then rm -r {{ target }} ; fi
|