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

# Put preferred editor here
$editor = "sensible-editor";

$file = $ARGV[0];

use File::Temp;
(undef, $tmpfile) = File::Temp::tempfile(UNLINK => 1, OPEN => 0, SUFFIX => ".tag.tmp");

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

unless ($file =~ m/\.ogg$/) {
	die "File \"$file\" does not have the .ogg extension.\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 > $tmpfile";

system "$editor $tmpfile";

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

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

print "\n";


