Skip to content

Instantly share code, notes, and snippets.

@yursan9
Created Mar 2, 2019
Embed
What would you like to do?
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