Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use IO::File;
  5. use File::Basename;
  6. use IO::Uncompress::Unzip qw(unzip $UnzipError);
  7. use Image::Magick;
  8. no warnings 'uninitialized';
  9. no warnings 'experimental';
  10. my $rootdir; my $dh; my $anchor; my $line; my $dir; my $item; my $title; my $dotcnt; my $imgcnt; my $year; my $vol; my $enc;
  11. my @rootlist; my @list; my @numbers; my @nfo; my @vid; my @img; my @pdfchm;
  12. my (@enc) = qw( 1080 720 540 480 360 240 );
  13. $rootdir = "$ARGV[0]";
  14. #if (length $ARGV[0]) {} #test if $ARGV[0] has been passed
  15. sub get_list {
  16. if ($anchor == '0') {
  17. print "set anchor\n";
  18. $anchor = '1';
  19. opendir ($dh, "@_") or die $!;
  20. @rootlist = grep !/^\.\.?$/, readdir($dh);
  21. closedir ($dh);
  22. } else {
  23. opendir ($dh, "@_") or die $!;
  24. @list = grep !/^\.\.?$/, readdir($dh);
  25. closedir ($dh);
  26. }
  27. }
  28.  
  29. sub parse_item {
  30. $dotcnt = @{["@_" =~ /(\.)/g]};
  31. @numbers = "@_" =~ /(\d+)/g;
  32. $title = ("@_");
  33. if ("@_" =~ /^(\d+)/) {
  34. print "$title seems to begin with a number\n";
  35. shift @numbers;
  36. }
  37. foreach my $number (@numbers) {
  38. if ($number < 480) { #Work on better volume checking
  39. $vol = $number;
  40. } elsif ($number ~~ @enc) {
  41. $enc = $number;
  42. } elsif ($number > 1970) {
  43. $year = $number;
  44. if ($dotcnt > 1) {
  45. $title =~ s/($year)//;
  46. #$title =~ s/\s+$//;
  47. $title =~ s/\.+$//; #Remove trailing dot
  48. }
  49. }
  50. }
  51. }
  52.  
  53. get_list($rootdir);
  54. foreach my $i (@rootlist) {
  55. parse_item($i);
  56. $dir = $rootdir . '/' . $i;
  57. if (-d $dir) {
  58. get_list($dir);
  59. foreach my $s (@list) {
  60. if (-d "$dir/$s") {
  61. print "$dir/$s seems to be a directory\n";
  62. } elsif (-f "$dir/$s") {
  63. if ($s =~ m{\.nfo$}) {
  64. push @nfo, $s;
  65. } elsif ($s =~ m{\.mp4$|\.avi$|\.mkv$|\.mpg$|\.mpeg$|\.mov$|\.m4v$}) {
  66. push @vid, $s;
  67. } elsif ($s =~ m{\.jpg$|\.tbn$|\.jpeg$|\.png$}) {
  68. push @img, $s;
  69. #`display "$dir/$s"`;
  70. } elsif ($s =~ m{\.pdf$|\.chm$}) {
  71. push @pdfchm, $s;
  72. } else {
  73. print "Unknown file type: $s\n";
  74. }
  75. }
  76. }
  77. $imgcnt = scalar(grep {defined $_} @images);
  78. if ($imgcnt > 1) {
  79. foreach my $p (@images) {
  80. my $im = Image::Magick->new();
  81. my (my $width, my $height, my $size, my $format) = $im->Ping("$dir/$p");
  82. print "The image height for $p is $height\n";
  83. print "The image size is: $size\n";
  84. print "The image format is: $format\n";
  85. }
  86. }
  87. }
  88. }
  89. exit 0;
  90. #This template will be used to test code.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement