Skip to content

Instantly share code, notes, and snippets.

@yursan9
Created March 2, 2019 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yursan9/f96d48d9e4141c8b803fccb16964ed11 to your computer and use it in GitHub Desktop.
Save yursan9/f96d48d9e4141c8b803fccb16964ed11 to your computer and use it in GitHub Desktop.
Simple scripts for tagging audio file using mutagen
#!/usr/bin/fish
function print_help
printf "\n%s\n" "Usage: tag-music [options] [filename]"
printf "\n%s\n" "Options:"
printf "%s\t%s\n" "-h, --help" "Show this help message and exit"
printf "%s\t%s\n" "-e, --edit" "Edit the tag, use the preexisting values if available"
end
# Exit if no argument
if test (count $argv) -lt 1
echo "Need to have one argument"
print_help
exit
end
# Setup Argparse
set -l options (fish_opt -s h -l help)
set options $options (fish_opt -s e -l edit --required-val)
# Parse flag and parameter
argparse --name "tag-music" $options -- $argv
or exit
if set -q _flag_h; or set -q _flag_help
print_help
exit
end
# Process if flag -e or --edit used
if set -q _flag_e; or set -q _flag_edit
# Get the filename from flag parameter
set -l filename $_flag_e
# Get the information from the available tag
set -l title (mid3v2 $filename | grep TIT2 | cut -d = -f 2)
set -l artist (mid3v2 $filename | grep TPE1 | cut -d = -f 2)
set -l album (mid3v2 $filename | grep TALB | cut -d = -f 2)
set -l year (mid3v2 $filename | grep TDRC | cut -d = -f 2)
set -l genre (mid3v2 $filename | grep TCON | cut -d = -f 2)
echo "Fill the form to tag your music"
# Read input for each column, with available value as default
read -c "$title" -P "Title: " title
read -c "$artist" -P "Artist: " artist
read -c "$album" -P "Album: " album
read -c "$year" -P "Year: " year
read -c "$genre" -P "Genre: " genre
mid3v2 \
--artist="$artist" \
--song="$title" \
--album="$album" \
--year="$year" \
--genre="$genre" \
$filename
exit
end
# Show tag only if the parameter is a path
mid3v2 $argv[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment