tag 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. err() { echo "Usage:
  3. tag [OPTIONS] file
  4. Options:
  5. -a: artist/author
  6. -t: song/chapter title
  7. -A: album/book title
  8. -n: track/chapter number
  9. -N: total number of tracks/chapters
  10. -d: year of publication
  11. -g: genre
  12. -c: comment
  13. You will be prompted for title, artist, album and track if not given." && exit 1 ;}
  14. while getopts "a:t:A:n:N:d:g:c:f:" o; do case "${o}" in
  15. a) artist="${OPTARG}" ;;
  16. t) title="${OPTARG}" ;;
  17. A) album="${OPTARG}" ;;
  18. n) track="${OPTARG}" ;;
  19. N) total="${OPTARG}" ;;
  20. d) date="${OPTARG}" ;;
  21. g) genre="${OPTARG}" ;;
  22. c) comment="${OPTARG}" ;;
  23. f) file="${OPTARG}" ;;
  24. *) printf "Invalid option: -%s\\n" "$OPTARG" && err ;;
  25. esac done
  26. shift $((OPTIND - 1))
  27. file="$1"
  28. [ ! -f "$file" ] && echo "Provide file to tag." && err
  29. [ -z "$title" ] && echo "Enter a title." && read -r title
  30. [ -z "$artist" ] && echo "Enter an artist." && read -r artist
  31. [ -z "$album" ] && echo "Enter an album." && read -r album
  32. [ -z "$track" ] && echo "Enter a track number." && read -r track
  33. case "$file" in
  34. *.ogg) echo "Title=$title
  35. Artist=$artist
  36. Album=$album
  37. Track=$track
  38. Total=$total
  39. Date=$date
  40. Genre=$genre
  41. Comment=$comment" | vorbiscomment -w "$file" ;;
  42. *.opus) echo "Title=$title
  43. Artist=$artist
  44. Album=$album
  45. Track=$track
  46. Total=$total
  47. Date=$date
  48. Genre=$genre
  49. Comment=$comment" | opustags -i -S "$file" ;;
  50. *.mp3) eyeD3 -Q --remove-all -a "$artist" -A "$album" -t "$title" -n "$track" -N "$total" -Y "$date" "$file" ;;
  51. *.flac) echo "TITLE=$title
  52. ARTIST=$artist
  53. ALBUM=$album
  54. TRACKNUMBER=$track
  55. TOTALTRACKS=$total
  56. DATE=$date
  57. GENRE=$genre
  58. DESCRIPTION=$comment" | metaflac --remove-all-tags --import-tags-from=- "$file" ;;
  59. *) echo "File type not implemented yet." ;;
  60. esac