#!/usr/bin/perl # Written to suppliment crip with a tag editor. # Supports both .ogg and .flac files. # Put preferred editor here $editor = "vim"; $file = $ARGV[0]; unless (-e "$file") { die "File \"$file\" does not exist.\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; $file =~ s/\;/\\\;/g; $file =~ s/,/\\,/g; $file =~ s/&/\\&/g; if ($file =~ m/\.ogg$/) { # First check for vorbiscomment existence: $out = `which vorbiscomment`; if ($out eq "") { die "Cannot find `vorbiscomment` for tagging the Ogg Vorbis files!\n"; } 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"; } elsif ($file =~ m/\.flac$/) { # First check for metaflac existence: $out = `which metaflac`; if ($out eq "") { die "Cannot find `metaflac` for tagging the flac files!\n"; } system "metaflac --export-tags-to=/tmp/$file.tag.tmp $file"; system "$editor /tmp/$file.tag.tmp"; print "Writing new tag info...\n"; system "metaflac --remove-all-tags --import-tags-from=/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 "metaflac --export-tags-to=- $file"; } else { die "File \"$file\" does not have the .ogg or .flac extension.\n"; } print "\n";