Developer Forums | About Us | Site Map
Search  
HOME > TUTORIALS > SERVER SIDE CODING > PERL TUTORIALS > CULTURED PERL: FUN WITH MP3 AND PERL, PART 2


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

Cultured Perl: Fun with MP3 and Perl, Part 2
By Teodor Zlatanov - 2004-04-08 Page:  1 2 3 4 5 6

Select the disks of interest

I now have a list of albums that correspond to what the user thinks he wants. This is usually a list bigger than what the user really wants, so now I give the user a chance to select only the albums of interest. This is also a chance for the user to quit if the albums found were not those they wanted. The -accept_all switch to autotag.pl will bypass the selection menu and let the user operate on all the found albums. The final results, regardless of how I get there, will reside in the @selecteddiscs list.

Listing 6: Select the disks and print the list

my @selecteddiscs;
if ($config->ACCEPT_ALL())
{
 @selecteddiscs = keys %discs;
}
else
{
 print "Enter the albums of interest for files [@ARGV]\n";
 @selecteddiscs = $cddb->ask4discurls(\%discs);
}

unless (scalar @selecteddiscs)
{
 print "You selected no albums, exiting...\n";
 exit 0;
}

%olddiscinfo = %discs;                  # save the old data for ask2discurls
%discs = ();                            # clear the search results

# populate %discs with full search results
foreach my $disc (@selecteddiscs)
{
 my %discinfo = $cddb->getdiscinfo($disc);
 $discs{$disc} = \%discinfo;
}

if ($config->DUMP())
{
 print Dumper \%discs;
 exit 0;
}

The WebService::FreeDB module has an ask4discurls() function that was nice, because I would have had to write it otherwise. It prints a list of albums and lets the user pick the desired ones.

Now that the final list of albums is in @selecteddiscs, %discs gets only the albums whose ID is there. The getdiscinfo() function fills out the album entry with track and album information. It is a slow function, which is why I use it only now that a small number of albums are left.



View Cultured Perl: Fun with MP3 and Perl, Part 2 Discussion

Page:  1 2 3 4 5 6 Next Page: At last, the main loop

First published by IBM developerWorks


Copyright 2004-2024 GrindingGears.com. All rights reserved.
Article copyright and all rights retained by the author.