All pastes #1046721 Raw Edit

Anonymous

public text v1 · immutable
#1046721 ·published 2008-06-13 03:47 UTC
rendered paste body
#! /bin/bash

TAGDIR="$1"
declare -a albumArray
declare -a artistArray
declare -a yearArray
let num=0

##first, test for subdirectories and fail if they are detected
if `ls $TAGDIR/*/ > /dev/null 2>&1`; then 
	echo "Subdirectories detected! If this is a multi-disc album, you must create it manually."
	exit 1
fi

FILE=$( find $TAGDIR -iname *.flac | head -n 1 )
EXT=$( echo ${FILE##*/*.} )

##now, read the album tags for each file into an array element
for i in `metaflac --show-tag=album "$TAGDIR"/*.$EXT | sed -e 's/.*ALBUM/ALBUM/g' -e 's/ /,#,#,#/g'`; do
	albumArray[$num]=$i
	((num++))	
done

##now, make sure each element in the array is the same, and fail if they aren't.
num=0
while [ "$num" -lt "$((${#albumArray[@]}-1))" ]; do
	if [ "${albumArray[num]}" != "${albumArray[num+1]}" ]; then
		echo "Files have different values for albums. Sorry, upload manually or fix your tags"
		exit 1
	fi
	((num++))
done

##set album variable and fail if there is no album value
ALBUM=`echo ${albumArray[0]} | sed -e 's/,#,#,#/ /g' -e 's/ALBUM=\(.*\)/\1/g'`
if [[ "a$ALBUM" = "a" ]]; then
	echo "No album detected.  Tag your files properly!"
	exit 1
fi

##now read artist information
num=0
for i in `metaflac --show-tag=artist "$TAGDIR"/*.$EXT | sed -e 's/.*ARTIST/ARTIST/g' -e 's/ /,#,#,#/g'`; do
        artistArray[$num]=$i
        ((num++))
done

##now check to make sure artist information is the same
num=0
while [ "$num" -lt "$((${#artistArray[@]}-1))" ]; do
        if [ "${artistArray[num]}" != "${artistArray[num+1]}" ]; then
		if [[ "${artistArray[num]}" = "ARTIST=" ]]; then
			echo "No value for Artist detected, tag your album properly!"
			exit 1
		fi
		ARTIST="Various Artists"
		break
	else
		ARTIST=`echo ${artistArray[0]} | sed -e 's/,#,#,#/ /g' -e 's/ARTIST=\(.*\)/\1/g'`
        fi
        ((num++))
done

##now, read the year tags for each file into an array element
num=0
for i in `metaflac --show-tag=date "$TAGDIR"/*.$EXT | sed -e 's/.*DATE/DATE/g' -e 's/ /,#,#,#/g'`; do
	yearArray[$num]=$i
	((num++))	
done

##now, make sure each element in the array is the same, and fail if they aren't.
num=0
while [ "$num" -lt "$((${#yearArray[@]}-1))" ]; do
	if [ "${yearArray[num]}" != "${yearArray[num+1]}" ]; then
		echo "Files have different values for years. Sorry, upload manually or fix your tags"
		exit 1
	fi
	((num++))
done

##set year variable and fail if there is no value
YEAR=`echo ${yearArray[0]} | sed -e 's/,#,#,#/ /g' -e 's/DATE=\(.*\)/\1/g'`
if [[ "a$YEAR" = "a" ]]; then
	echo "No year detected.  Tag your files properly!"
	exit 1
fi

FORMAT="FLAC"
BITRATE="Lossless"

mktorrent --a google.com -p --output=/home/oorza/Desktop/torrent.torrent $TAGDIR