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]);

Recursive Directory Listing in Perl

#!/usr/bin/perl -w
use strict;
sub recurse($)
{
my($path) = @_;
$path .= '/' if($path !~ /\/$/);
print $path,"\n";
for my $eachFile (glob($path.'*'))
{
## if the file is a directory
if( -d $eachFile) {
## pass the directory to the routine ( recursion )
recurse($eachFile);
}
else
{
## print the file ... tabbed for readability
open (MYFILE, '>>data.csv');
print MYFILE "\t",$eachFile,"\n";
}
}
close (MYFILE);
}
## initial call ... $ARGV[0] is the first command line argument

recurse($ARGV[0]);

Wednesday, 1 April 2009

Getting Transaction details from Paypal in PHP

Below is code for getting transaction details if you are using Paypal for payment purposes. Auto-return and PDT has to be enabled in paypal system for below code to work.
}
else
{
fputs ($fp, $header . $req);
// read the body data
$res = '';
$headerdone = false;
while (!feof($fp))
{
$line = fgets ($fp, 1024);
if (strcmp($line, "\r\n") == 0)
{
// read the header
$headerdone = true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}
 
// parse the data
$lines = explode("\n", $res);
$keyarray = array();
//print_r($lines);
if (strcmp ($lines[0], "SUCCESS") == 0)
{
for ($i=1; $i

Java Archive Header in PHP

Header for Java-archive.

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 ...