Copyright 2022 - Custom text here

amcxml2html.pl

#!/tools/perl/bin/perl

use Net::FTP;
#use Data::Dumper;
use XML::Simple;
use File::Basename;

#print H "<HTML><HEAD><TITLE>AMC</TITLE></HEAD>\n<BODY>\n

$html_file = "C:\\local\\films.html";
init_html($html_file);
xml2html("C:\\local\\amc_olds\\cinematheque.xml", $html_file,0);
xml2html("C:\\local\\amc\\films.xml", $html_file,10000);
end_html($html_file);
send_1and1($html_file);

$html_file = "C:\\local\\films_enfants.html";
init_html($html_file);
xml2html("C:\\local\\amc_olds\\cinematheque enfant.xml", $html_file,0);
xml2html("C:\\local\\amc_enfants\\films_enfants.xml", $html_file,10000);
end_html($html_file);
send_1and1($html_file);

sub init_html($) {
  my $html_file = shift;

    open(H,">$html_file") || die "Cannot open $html_file:$_\n";
    print H "<HTML><HEAD><TITLE>AMC</TITLE></HEAD>\n<BODY>\n";
    close(H);
}
 
sub end_html($) {
  my $html_file = shift;

    open(H,">>$html_file") || die "Cannot open $html_file:$_\n";
    print H "</BODY></HTML>\n";
    close(H);
}

sub send_1and1($) {
  my $html_file = shift;

    my $basen = basename($html_file);
    
    print "$basen\n";
    $ftp = Net::FTP->new("ftp.claudihome.com", Debug => 0)
    or die "Cannot connect to ftp.claudihome.com: $@";
    
    $ftp->login("u48396339",'nEASdYny')
    or die "Cannot login ", $ftp->message;
    
    $ftp->put("$html_file", "amc/$basen")
      or die "put failed ", $ftp->message;
      
    $ftp->quit;
}

sub xml2html($) {
  my $amc_file = shift;
  my $html_file = shift;
  my $offset = shift;
 
    $amc_dir = dirname($amc_file);
        
    open(H,">>$html_file") || die "Cannot open $html_file:$_\n";
    print H "<HR><TABLE BORDER=\"1\">\n";
    $config = XMLin($amc_file,forcearray => [ "Movie" ]);
    #$config = XMLin($amc_file);
    foreach $m (@{$config->{Catalog}->{Contents}->{Movie}}){
        $num = $m->{Number} + $offset;
        if( $m->{OriginalTitle} eq $m->{TranslatedTitle} ){
            $title = $m->{OriginalTitle};
        }else{
            $title = $m->{FormattedTitle};
        }
        print H "<TR><TD>$num</TD><TD>$title</TD><TD><FONT SIZE=\"-2\">$m->{Description}</FONT></TD></TR>\n";
#        print H "<TR><TD>$m->{Number}</TD><TD>$m->{FormattedTitle}</TD><TD><FONT SIZE=\"-2\">$m->{Description}</FONT></TD><TD><IMG WIDTH=\"120\" HEIGHT=\"160\" src=\"$m->{Picture}\"></TD></TR>\n";
    }
    print H "</TABLE>\n";
    close(H);
}












#    print Dumper($m);
#    print "$m->{Number} - $m->{FormattedTitle} - $m->{Actors} - $m->{Year} - $m->{Category} - $m->{Description} - $m->{Picture}\n";
#    print Dumper($config->{Catalog}->{Contents}->{Movie}->{$m});



#%movies = $config->{Catalog}->{Contents}->{Movie};

#print Dumper($movies[2]);
#print "n=$#($config->{Catalog}->{Contents}->{Movie})\n";
#print Dumper($config->{Catalog}->{Contents}->{Movie}[2]);

#print Dumper($config->{Catalog}->{Contents}->{Movie}->[1]);


#opendir D, $amc_dir || die "Cannot open $amc_dir:";
#foreach $f (readdir D) {
        # We leave the special directories alone, or we'll never finish.
#        next if $f =~ /^\.{1,2}$/ ;

#                $ftp->put("$amc_dir\\$f", "amc/$f")
#                  or die "put failed ", $ftp->message;
#                print "PUT $f\n";
#}
#closedir D || die "Cannot close $amc_dir: $!";
#$ftp->quit;
f t g m