From 794bb7296982776183c5819351aca94aee4231a2 Mon Sep 17 00:00:00 2001 From: zachir Date: Wed, 24 Aug 2022 01:04:29 -0500 Subject: support more options in tagimg --- tagimg | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/tagimg b/tagimg index 4aca06e..10017a2 100755 --- a/tagimg +++ b/tagimg @@ -1,7 +1,58 @@ #!/sbin/sh -ls | while read i; do - ls "$i"| while read j; do - mid3v2 -p "$i"/"$j"/thumb.jpg "$i"/"$j"/*.{mp3,flac} - done +# check for flags +for i in $@; do + case "$i" in + "-"*) unset DIRSFLAG LOCALFLAG + ;; + esac + [ -n "$DIRSFLAG" ] && unset LOCALFLAG + [ -n "$LOCALFLAG" ] && unset DIRSFLAG + [ -n "$THUMBFLAG" ] && THUMBNAIL="$i" && unset THUMBFLAG + [ -n "$FILEFLAG" ] && FILENAME="$(printf "$i\n$FILENAME" | paste -s -d'|')" && unset FILEFLAG + case "$i" in + "-d") + DIRSFLAG="y" + ;; + "-l") + LOCALFLAG="y" + ;; + "-t") + THUMBFLAG="y" + ;; + "-f") + FILEFLAG="y" + ;; + *) + printf "Unrecognized flag! I only know -d and -l!\n" + exit 1 + ;; + esac done + +[ -z "$THUMBNAIL" ] && THUMBNAIL="thumb.jpg" + +if [ -n "$DIRSFLAG" ]; then + ls | while read i; do + [ ! -d "$i" ] && continue + ls "$i"| while read j; do + [ ! -d "$j" ] && continue + ls "$i/$j" | while read k; do + [ ! -f "$k" ] && continue + case "$k" in + *.mp3 | *.flac ) + mid3v2 -p "$i/$j/$THUMBNAIL" "$i/$j/$k" + ;; + esac + done + done + done +elif [ -n "$LOCALFLAG" ]; then + [ -z "$FILENAME" ] && exit 1 + IFS='|' + for i in "$FILENAME"; do + mid3v2 -p "$THUMBNAIL" "$i" + done + unset IFS +fi + -- cgit v1.2.3