Saturday, 25 April 2009

Getting mp3 files from directories

Quite useful if you want to find mp3 files from directory recursively. I used while developing CMS for my company. Getting Podcast libraries is important.

#!/usr/bin/perl -w
use strict;
use MP3::PodcastFetch::TagManager;
use File::Basename;
sub recurse($)
{
my($path) = @_;
my $duration=0;
my $ftype= "";
my $manager = MP3::PodcastFetch::TagManager->new();
my $filename="";
$path .= '/' if($path !~ /\/$/);
print $path,"\n";
## loop through the files contained in the directory
for my $eachFile (glob($path.'*')) {
## if the file is a directory
if( -d $eachFile)
{
recurse($eachFile);
}
else
{
($filename, undef, $ftype) = fileparse($eachFile,qr"\..*");
$filename =~ s/_+/ /g;
print "$ftype
\n";
if ($ftype eq ".mp3")
{
if($eachFile =~ m/GUID/)
{ ## print the file ... tabbed for readability
my $filesize = -s $eachFile;
$duration = $manager->get_duration($eachFile);
open (MYFILE, '>>datafulltracks.csv');
print MYFILE $filename,", Duration - ",$duration,", Size- ",$filesize,"\n";
}
}
}
}
close (MYFILE);
}
## initial call ... $ARGV[0] is the first command line argument

recurse($ARGV[0]);

No comments:

Efficient and Reliable UI automation without Selenium

I have been experiencing satisfaction over UI automation efforts after a half-decade of my work in automation. The reason is new age tools ...