Sorry missed the new file!

Rob

-- 
----------------------------------------------------
Remember: You are unique - just like everybody else.
#!/usr/bin/perl -w
#____________________________________________________________________________
#
#   Obsequeium -- the Internet MP3 Jukebox 
#
#   Copyright (C) 1998 Robert Kaye
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#   $Id: editalbum.pl,v 1.3 2001/09/09 01:03:31 robert Exp $
#____________________________________________________________________________

use CGI;
use Obs::Defs;
use DBI;
use strict;
my $o = new CGI;
print $o->header();
print $o->start_html(-title=>"Merging tracks",
                     -text=>'#FFFFFF',
                     -bgcolor=>'#000000',
                     -link=>'#FF0000',
                     -vlink=>'#E00000',
                     -alink=>'#FFFF00');
print '<meta http-equiv="pragma" content="no-cache">';

print "Merging tracks....\n";

if (!Obs::Defs::IsAdmin)
{
    print $o->redirect(-location=>'playlist.pl',
                       -target=>'playlist');
    exit(0);
}    
my $dbh = DBI->connect(Obs::Defs::DSN,Obs::Defs::DB_USER,Obs::Defs::DB_PASSWD);
if (!$dbh)
{
    print "<font size=+1 color=red>Sorry, the database is currently ";
    print "not available. Please try again in a few minutes.</font>";
    print "(Error: ",$DBI::errstr,")";
} 
else
{
    #Id of an Album to take name from.
    my $album= $o->param('album');
    if ($album eq '') {print "No album\n"; exit();}

    #find the compilation meta-artist.
    my $sth=$dbh->prepare("select Artist.id from Artist " . 
                          "where Artist.name = \"Compilation\" limit 1");
    $sth->execute();
    my ($compart, @row);
    if (@row=$sth->fetchrow_array){
        $compart=$row[0];
    } else {
        #Create the meta-artist
        $dbh->do("insert into Artist set Name='Compilation', SortName='Compilation'");
        my $sth2=$dbh->prepare("select LAST_INSERT_ID()");
        $sth2->execute();
        @row = $sth2->fetchrow_array;
        $sth2->finish;
        $compart=$row[0];
    }
    $sth->finish();

    #move the album to the compilation meta-artist.
    $dbh->do("update Album set Artist=$compart where Album.id=$album");

    #find the title of the album
    $sth=$dbh->prepare("select Name from Album where Album.id=$album");
    $sth->execute();
    @row=$sth->fetchrow_array();
    my $albumname=$row[0];
    $sth->finish();

    #find albums with the same name
    $sth=$dbh->prepare("select Id from Album where Album.name='$albumname' " . 
                       "and Album.Id <> $album");
    $sth->execute();
    my @albumids;
    while (@row=$sth->fetchrow_array){
        push @albumids, $row[0];
    }
    $sth->finish();
    
    #move tracks to destination album, and delete source album.
    foreach my $albumid (@albumids) {
        $dbh->do("update Track set Album=$album where Album=$albumid");
        $dbh->do("delete from Album where Id=$albumid");
    }

}       

print "Done.\n";
$dbh->disconnect();
 
print $o->end_html;

Reply via email to