#!/usr/bin/perl -w

# Tag an exiting audio file with the information from a .strec file
# Homepage: http://scara.com/strec/
# 
# Copyright (c) 2006 by Christian Wolff (scarabaeus.org)
# Released under the GPL, see http://www.gnu.org/copyleft/gpl.html
# 
# What you'll need:
# LibID3v2    http://id3lib.sourceforge.net/
# id3v2       http://id3v2.sourceforge.net/ [debian: 'apt-get install id3v2' (includes libid3)]
# 

use strict;

$| = 1;

my ($url, $name, $filename, $title, $artist, $album, $releaseyear, $recname);

print "strectag, (c) 2006 Christian Wolff\n";

$url = shift;

$name = $url;
$name = $1 if $url =~ /^(.*?)\.\w*$/;
open FILE, "$url" or die "can't open file ${url}!\n";
$url = <FILE>;
chomp $url;
my $desig = <FILE>;
chomp $desig;
($title, $artist, $album, $releaseyear) = split /\t/, $desig;
close FILE;

$artist = $name unless $artist;
$album = $artist unless $album;
$releaseyear = '2006' unless $releaseyear;
$filename = $name;
$recname = $filename . '.mp3';
print "Adding id3v1 tag to ${recname}\n";
print "id3v2 -t \'${title}\' -a \'${artist}\' -A \'${album}\' -y ${releaseyear} ${recname}\n";
system "id3v2 -t \'${title}\' -a \'${artist}\' -A \'${album}\' -y ${releaseyear} ${recname}";
