Help with Perl script

0

I would need help with a script that I do not quite understand how it works and that I think it would have to be adapted to run it in Windows (my operating system).

The script is as follows:

#!/usr/bin/perl
use strict;

#------------------------------------------------------------------------
# This code is open-source as defined by the GPL, 2002
# by Willie Northway - http://www.willienorthway.com/
# http://www.gnu.org/copyleft/gpl.html
# $Id: clam_covers.pl,v 1.8 2003/04/15 14:08:45 willn Exp $ 
#
# Note: I've noticed some problems in Mac OS X when trying to read
# the pdf from a UFS drive. It reports "Macintosh system error
# (-39)" This is a eofErr - End of File Error. These seem to be readable
# from an HFS+ partition though.
#-------------------------------------------------------------------------

my ($path) = shift;
my (@Data, @Temp);
my ($entry, $file, $line, $query, $grabbed, $data, $datafile, $name);
my ($debug) = 0;

if ($path) { $data = $path; } 
else
{
$data = "./data/";
$datafile = 1;
}

if (opendir (DIR, $data))
{
if ($datafile)  #read individual data files
{
    foreach $entry (sort (readdir (DIR)))
    {
        $file = $data.$entry;

        if (( $entry =~ /^\./ ) || ( $entry =~ /^Desktop D\w/ )) { ; }
        elsif ($datafile)
        {
            if (open (INDATA, "$file"))
            {
                @Data = <INDATA>;
                close (INDATA);
                chomp (@Data);

                $query = ProcessAlbum( $entry, 1, @Data );

                if (!$debug) { '$query'; }
                else { print "Q: $query\n\n"; }
            }
            else { print "Couldn't open data file: $file, $!\n"; }
        }
    }

  }
  else          #read from CD directory
  {
    foreach $entry (sort (readdir (DIR)))
    {
        if (( $entry =~ /^\./ ) || ( $entry =~ /^Desktop D\w/ )) { ; }
        elsif (-d $data.$entry) 
        {
            if (opendir (DIR2, $data.$entry))
            {
                foreach $name (sort (readdir (DIR2)))
                { if ( $name !~ /^\./ ) { push (@Data, "$entry - $name");        } }
                close( DIR2 );
            }
        }
        else
        {
            $entry =~ s/'//;
            $entry =~ s/\.aiff$//;
            push (@Data, $entry);
        }
    }

    @Temp = split /\//, $data;
    while (!$data && $#Temp) { $data = pop (@Temp); }

    $data =~ s/^.*\/([^\/]+)\/?$/$1/;
    $query = ProcessAlbum( $data, 0, @Data );

    if (!$debug) { '$query'; }
    else { print "Q: $query\n\n"; }
   }

   }
   else { print "Couldn't open data directory: $!\n"; }

   sub Numerically { $a <=> $b; }

  sub ProcessAlbum
{
my ($title, $fromfile, @Tracks) = @_;
my ($request, $line_num) = 0;

$title =~ s/ /_/g;

$request = "wget 'http://papercdcase.com/papercdcase.cgi/".
    "papercdcase.pdf?artist=$title";

if ( !$fromfile ) { @Tracks = sort Numerically( @Tracks ); }
foreach $line ( @Tracks )
{
    $line = CleanName ($line);
    $line_num++;
    $request .= "&track".$line_num."=$line";
}
$request .= "&template=jewel&size=letter&lang=western".
"&submit.x=0&submit.y=0' --output-document=$title.pdf";

print "\nREQ: $request\n\n";
return $request;
}


sub CleanName
{
my ($line) = @_;

$line =~ s/\+/%2B/g;
$line =~ s/ /+/g;
$line =~ s/&/%26/g;
$line =~ s/'/%27/g;
$line =~ s/#/%23/g;

return $line;
}
    
asked by Moises 19.04.2018 в 21:44
source

1 answer

0

I have made a couple of modifications to the script and at least I have managed to make it work, although badly. Note: You must have the wget.exe application in the PATH variable

To these two lines I have removed the apostrophe and to the second I have substituted $ title.pdf for papercdcase.pdf:

Original: $ request="wget ' link ". "& submit.x = 0 & submit.y = 0 '--output-document = $ title.pdf";

Modified: $ request="wget link ". "& submit.x = 0 & submit.y = 0 --output-document = papercdcase.pdf";

I suppose that the program waits as an argument the path of a directory, although this is not clear to me. From the command line at the command prompt run: clam_covers.pl "% USERPROFILE% \ Music \ Ennio Morricone \ A Fistful Of Dollars"

This creates a PDF (of covers) as intended, but it looks bad. Also the directory seems that it can not have subdirectories.

    
answered by 21.04.2018 в 16:27