random script dump
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

flac-to-mp3.zsh 828B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env zsh
  2. read_tags() {
  3. metaflac $1 --show-tag=ALBUM --show-tag=ARTIST --show-tag=GENRE --show-tag=DATE --show-tag=TITLE --show-tag=TRACKNUMBER --show-tag=TRACKTOTAL |\
  4. sed s/=/~..~/ |\
  5. awk -F'~..~' '{print $1"='\''"$2"'\''"}'
  6. }
  7. mime_is() {
  8. mimetype=$(file -b --mime-type $1)
  9. if [[ $mimetype == $2 ]]; then
  10. return 0
  11. else
  12. return 1
  13. fi
  14. }
  15. for i in $argv[@]; do
  16. if mime_is $i 'audio/x-flac'; then
  17. local original=$i
  18. eval $(read_tags $original)
  19. local out_dir=/home/von/Music/\[UNSORTED\]/$ARTIST/$ALBUM
  20. [[ -d $out_dir ]] || mkdir -p $out_dir
  21. local converted=$out_dir/${i%.*}.mp3
  22. flac -c -d $original | lame -V0 --add-id3v2 --pad-id3v2 --ignore-tag-errors \
  23. --ta $ARTIST --tt $TITLE --tl $ALBUM --tg ${GENRE:-12} --tn ${TRACKNUMBER:-0} --ty $DATE \
  24. - $converted
  25. else
  26. return 1
  27. fi
  28. done
  29. exit 0