From e22f229f3702335e11900c4f28da0c41fec06607 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 3 Nov 2024 09:19:33 +0000 Subject: [PATCH] fix: better detection of files for each step --- .mise.toml | 1 + README.md | 1 + justfile | 60 +++++++++++++++++++++++++++++++++++------------------- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/.mise.toml b/.mise.toml index c8adb6e..3986447 100644 --- a/.mise.toml +++ b/.mise.toml @@ -3,6 +3,7 @@ ffmpeg = "latest" jq = "latest" "pipx:mkb79/audible-cli" = "master" "cargo:refile-m4b" = "latest" +fd = "latest" fzf = "latest" python = "latest" pipx = "latest" diff --git a/README.md b/README.md index 0a5e4e9..5cc09ce 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Mise will be used to install the other dependencies. If you don't want to use `m - [just](https://just.systems/) - [audible-cli](https://github.com/mkb79/audible-cli) (recommended installation instuctions below) +- [fd](https://github.com/sharkdp/fd) - [fzf](https://github.com/junegunn/fzf) - [jq](https://jqlang.github.io/jq/) - [ffmpeg](https://ffmpeg.org) diff --git a/justfile b/justfile index c5e12af..aed0051 100644 --- a/justfile +++ b/justfile @@ -54,27 +54,35 @@ post-download: convert: convert-aax convert-aaxc convert-aax: + #!/usr/bin/env bash just _require_dir M4B - [ -f AAX/*.aax ] && 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 || true + if [ $(fd --glob 'AAX/*.aax' | wc -l) -gt 0 ] + 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 + fi convert-aaxc: + #!/usr/bin/env bash just _require_dir M4B - [ -f AAXC/*.aaxc ] && for AAXC in AAXC/*.aaxc ; \ - do \ - VOUCHER="${AAXC%.aaxc}.voucher" ; \ - M4B="M4B/$(basename ${AAXC%.aaxc}).m4b" ; \ - just _convert-one-aaxc $AAXC $VOUCHER $M4B ; \ - done || true + if [ $(fd --glob 'AAXC/*.aaxc' | wc -l) -gt 0 ] + 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 + fi _convert-one-aaxc aaxc_file voucher_file m4b_file: #!/usr/bin/env bash @@ -94,10 +102,20 @@ refile: refile-m4b M4B archive: - [ -d "${AUDIOBOOK_ARCHIVE}" ] || (echo "ERROR: No archive specified" ; exit 1) - [ -f M4B/* ] || (echo "WARN: Nothing to be archived" ; exit 1) - cd M4B && cp -v -R * "${AUDIOBOOK_ARCHIVE}" - just _clean M4B + #!/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}" + just _clean M4B/* + else + echo "ERROR: No archive specified or no M4B directory" + exit 1 + fi clean: for target in TEMP/* AAX/* AAXC/* M4B/* ; do just _clean $target ; done