Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use IO::File;
- use File::Basename;
- use IO::Uncompress::Unzip qw(unzip $UnzipError);
- use Image::Magick;
- no warnings 'uninitialized';
- no warnings 'experimental';
- my $rootdir; my $dh; my $anchor; my $line; my $dir; my $item; my $title; my $dotcnt; my $imgcnt; my $year; my $vol; my $enc;
- my @rootlist; my @list; my @numbers; my @nfo; my @vid; my @img; my @pdfchm;
- my (@enc) = qw( 1080 720 540 480 360 240 );
- $rootdir = "$ARGV[0]";
- #if (length $ARGV[0]) {} #test if $ARGV[0] has been passed
- sub get_list {
- if ($anchor == '0') {
- print "set anchor\n";
- $anchor = '1';
- opendir ($dh, "@_") or die $!;
- @rootlist = grep !/^\.\.?$/, readdir($dh);
- closedir ($dh);
- } else {
- opendir ($dh, "@_") or die $!;
- @list = grep !/^\.\.?$/, readdir($dh);
- closedir ($dh);
- }
- }
- sub parse_item {
- $dotcnt = @{["@_" =~ /(\.)/g]};
- @numbers = "@_" =~ /(\d+)/g;
- $title = ("@_");
- if ("@_" =~ /^(\d+)/) {
- print "$title seems to begin with a number\n";
- shift @numbers;
- }
- foreach my $number (@numbers) {
- if ($number < 480) { #Work on better volume checking
- $vol = $number;
- } elsif ($number ~~ @enc) {
- $enc = $number;
- } elsif ($number > 1970) {
- $year = $number;
- if ($dotcnt > 1) {
- $title =~ s/($year)//;
- #$title =~ s/\s+$//;
- $title =~ s/\.+$//; #Remove trailing dot
- }
- }
- }
- }
- get_list($rootdir);
- foreach my $i (@rootlist) {
- parse_item($i);
- $dir = $rootdir . '/' . $i;
- if (-d $dir) {
- get_list($dir);
- foreach my $s (@list) {
- if (-d "$dir/$s") {
- print "$dir/$s seems to be a directory\n";
- } elsif (-f "$dir/$s") {
- if ($s =~ m{\.nfo$}) {
- push @nfo, $s;
- } elsif ($s =~ m{\.mp4$|\.avi$|\.mkv$|\.mpg$|\.mpeg$|\.mov$|\.m4v$}) {
- push @vid, $s;
- } elsif ($s =~ m{\.jpg$|\.tbn$|\.jpeg$|\.png$}) {
- push @img, $s;
- #`display "$dir/$s"`;
- } elsif ($s =~ m{\.pdf$|\.chm$}) {
- push @pdfchm, $s;
- } else {
- print "Unknown file type: $s\n";
- }
- }
- }
- $imgcnt = scalar(grep {defined $_} @images);
- if ($imgcnt > 1) {
- foreach my $p (@images) {
- my $im = Image::Magick->new();
- my (my $width, my $height, my $size, my $format) = $im->Ping("$dir/$p");
- print "The image height for $p is $height\n";
- print "The image size is: $size\n";
- print "The image format is: $format\n";
- }
- }
- }
- }
- exit 0;
- #This template will be used to test code.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement