Skip to content

Instantly share code, notes, and snippets.

@tobbez
Created July 8, 2010 22:59
Show Gist options
  • Save tobbez/468774 to your computer and use it in GitHub Desktop.
Save tobbez/468774 to your computer and use it in GitHub Desktop.
Create a list of albums from flac tags
#!/bin/bash
#
# Created by tobbez
#
# Issues:
# Does not handle Various Artists-albums properly
function get_artist () {
metaflac --show-tag=ARTIST "$1" | cut -d= -f2
}
function get_album () {
metaflac --show-tag=ALBUM "$1" | cut -d= -f2
}
if [ ! $# -eq 2 ]
then
echo "Usage: ${0} <output file> <directory>"
exit
fi
output="${1}"
scan_dir="${2}"
output_arg="-o "${output}""
if [ "${output}" == "-" ]
then
output_arg=""
fi
num_files=`find "${scan_dir}" -type f -iname '*.flac' | wc -l`
let scanned_files=0
find "${scan_dir}" -type f -iname '*.flac' | while read file
do
echo "`get_artist "${file}" | tr '/' ' '` / `get_album "${file}" | tr '/' ' '`"
let scanned_files=$scanned_files+1
echo -ne "\r${scanned_files}/${num_files} scanned..." >&2
if [ $scanned_files -eq $num_files ]
then
echo >&2
fi
done | sort -t "/" -k 2 -u $output_arg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment