#!/usr/bin/perl
#
# Written to suppliment crip with a Ogg Vorbis tag editor.
#

# Put preferred editor here
$editor = "vim";

$file = $ARGV[0];

unless (-e "$file") {
	die "File \"$file\" does not exist.\n";
}

unless ($file =~ m/\.ogg$/) {
	die "File \"$file\" does not have the .ogg extension.\n";
}

if (-e "$file.tag.tmp") {
	die "WTF is \"$file.tag.tmp\" already doing in /tmp ?!\n";
}

# Escape certain characters from $file
# code taken directly from crip actually (crip does the same
#  sort of thing 3 different times in its code)
# (don't ask me why it worked above but doesn't work below without escapes)
$file =~ s/\(/\\(/g;  $file =~ s/\)/\\)/g;
$file =~ s/'/\\'/g;  $file =~ s/`/\\`/g;
$file =~ s/\"/\\\"/g;  $file =~ s/ /\\ /g;

system "vorbiscomment -l $file > /tmp/$file.tag.tmp";

system "$editor /tmp/$file.tag.tmp";

print "Writing new tag info...\n";
system "vorbiscomment -w -c /tmp/$file.tag.tmp $file";
print "Done.\n";

print "Deleting temporary file /tmp/$file.tag.tmp\n";
system "rm /tmp/$file.tag.tmp";

print "\nTag info now reads:\n";
system "vorbiscomment -l $file";

print "\n";


