summaryrefslogtreecommitdiff
path: root/tagimg
diff options
context:
space:
mode:
authorzachir <zachir@librem.one>2022-08-24 01:04:29 -0500
committerzachir <zachir@librem.one>2022-08-24 01:04:29 -0500
commit794bb7296982776183c5819351aca94aee4231a2 (patch)
treede051efb5645e7596b571a2b7cedbbfe34f952ed /tagimg
parentacdb2a06bd7b6ca864ba5d999a324d78be867189 (diff)
support more options in tagimg
Diffstat (limited to 'tagimg')
-rwxr-xr-xtagimg59
1 files 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
+