Graham wrote:
Hello all,

I need a script to do the following; if anyone's seen a pre-existing
script which does the same thing, or could do the same thing with a little
modification, I'd be happy to use it.  As of yet, I can't find anything,
and the Perl documentation i've looked at hasn't been too helpful.  I know
it's important to understand octal, hex, and escape sequences, but I need
to do this in days, not weeks or months.

1 - Read in a directory listing (i'm using linux)
2 - Assign each line (filename) to a variable
3 - extract ID3 tag, or other tag information from the file
4 - run a program, (like ogg123) using a given variable as the output
filename, with a different extension. (variable taken from the directory
listing)
5 - reattach the ID3 or other tag to the new file.
6 - delete the old file
7 - repeat on all files in a given directory.

This can't be that hard.  I do have some basic programming experience, I
understand structure, but have no idea what functions to call (or how to
call a free-standing linux program from within Perl.)

As you can probably tell, I'm looking for a script to convert ogg files to
mp3 en-masse, while retaining filenames and important tag information.
I've got a bash script which sort-of works, but does not retain any file
information and leaves me with new filenames like 01.mp3, 02.mp3, etc.

If anyone could help it would be greatly appreciated.  Also if anyone
knows of a site where I can find existing, functional, and EXPLICITLY
notated Perl scripts I would be forever indebted.  I learn much better by
dissecting someone else's work than I do from "Hello, World" programs.
I've written too many of those already.

If this can be done in BASH, let me know.


Well assuming you install the MP3::Info module from CPAN, and know more than I do about ogg123 then the attached script might prove to be a good starting place. It should be relatively easy from my starting point if you look at:


perldoc MP3::Info
perldoc -f system
perldoc -f unlink

To round out what the script does. The script I attached I had laying around from an earlier start to producing database insert statements to get my collection online finally, but I have since put it off while I make other preparations and intend on finishing it at a later date. Sorry I couldn't provide an exact solution, but assuming no one else has a better idea it will definitely get you started....

The script is UNTESTED and use at your own peril, backup your collection before doing this!!

http://danconia.org
#!/usr/bin/perl
#
# $Id$
#
#############################################################################
use strict;
use warnings;
use 5.6.1;
my $VERSION = '0.01';

use MP3::Info;
use File::Find;

no warnings 'File::Find';

my @topdirs = ('/opt/mp3','/opt/storage/mp3');
our $current_main_dir = '';
our $total_count = 0;

find(\&process_file, @topdirs);

sub process_file {
    my ($path, $filename, $file) = ($File::Find::dir, $_, $File::Find::name);
    if ($filename eq '.') {
        # just hit a top dir, reset the current main dir
        $current_main_dir = $path;
    }
    elsif ($filename !~ /\.mp3/) {
        # should be a directory, stat it to make sure can probably skip
    }
    else {
        # should be an mp3 file, get the info that we can
        (my $mainpath = $path) =~ s/$current_main_dir\///;

        return unless $mainpath =~ /^MP3/;

        my ($cd,$artist,$album, @rest) = split(/\//,$mainpath);

        my $info = get_mp3info($file);
        my $tag = get_mp3tag($file);

        print "MP3 ($mainpath): $filename \n";
        foreach my $key 
('STEREO','VBR','BITRATE','FREQUENCY','SIZE','SECS','MM','SS','MODE') {
            print "\t(i) ",ucfirst($key),': ',$info->{$key},"\n" if 
(defined($info->{$key}));
        }
        foreach my $key ('TITLE','ARTIST','ALBUM','YEAR','TRACKNUM','GENRE') {
            print "\t(t) ",ucfirst($key),': ',$tag->{$key},"\n" if 
(defined($tag->{$key}));
        }
        $total_count++;
    }
}


#############################################################################
__END__

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to