#!/usr/bin/perl use File::Copy; # copychange # jody DeRidder, 7/11/09 # goes through /srv/archive # finds tiff files or wave files # creates derivatives # creates directories for them under /srv/www/htdocs/content # to match the source directories # puts the derivatives there # also picks up transcripts # depends on installation of ImageMagick and LAME # altered to chmod and chown the content directories so scripts run by MU and DS to distribute MODS will work # check links at http://libcontent1.lib.ua.edu/content # location hardcoded here: $inbase = "/srv/archive"; $outbase = "/srv/www/htdocs/content/"; push (@dirlist, $inbase); foreach $dir (@dirlist){ opendir (DIR, $dir) or die "can't look through $dir\n"; while ($file = readdir(DIR)){ # print "looking at $file in $dir\n"; if ($file =~ /^\./ ){ next; } # skip dot files if ($file =~ /^[a-z]{1}\d{4}/ || $file =~ /Transcripts/ || $file =~ /^\d{3,7}$/){ # if ($file =~ /^[a-z]{1}\d{4}/ || $file =~ /\d{3,7}/ ){ # not using Transcripts directories # must match pattern u0003, p0004,(etc) 3-7 numbers, etc $path = $dir."/".$file; if ( -d $path){ # must be a directory push (@dirlist, $path); } elsif ($file =~ /^(.*)\.tif/){ # tif file $filenum = $1; # here, capture the path. ($newdir = $dir) =~ s,archive,www\/htdocs\/content,; print "$file from $dir to $newdir\n"; # create the path in the new location if it doesn't exist if (! -e $newdir){ `mkdir -p $newdir`;} # create the derivatives if they don't exist # name them appropriately and put them in the new location $big = $newdir."/".$filenum."_2048.jpg"; # large $mid = $newdir."/".$filenum."_512.jpg"; #midsize $small = $newdir."/".$filenum."_128.jpg"; # thumbnail if (! -e $big){ `convert $path -strip -density 96 -resample 96x96 -resize 2048x2048 -filter Cubic -quiet $big`; } if (! -e $mid){ `convert $path -strip -density 96 -resample 96x96 -resize 512x512 -filter Cubic -quiet $mid`; } if (! -e $small){ `convert $path -strip -density 96 -resample 96x96 -resize 128x128 -filter Cubic -quiet $small`; } } elsif ($file =~ /^(.*)\.wav/){ # wav file $filenum = $1; # here, capture the path. ($newdir = $dir) =~ s,archive,www\/htdocs\/content,; print "$file from $dir to $newdir\n"; # create the path in the new location if it doesn't exist if (! -e $newdir){ `mkdir -p $newdir`;} # create the derivatives if they don't exist # name them appropriately and put them in the new location $mp3 = $newdir."/".$filenum.".mp3"; if (! -e $mp3){ `lame $path $mp3 -V4 --noreplaygain -S`; } # lame u0008_0000001_0000018_0002.wav u0008_0000001_0000018_0002.mp3 -V4 --noreplaygain -S } # get transcripts. .txt and .ocr.txt elsif ($file =~ /^(.*)\.txt/){ # transcripts file if ($file =~ /\.v\d{1,2}\./){ next;} # skip the versions please # here, capture the path. ($newdir = $dir) =~ s,archive,www\/htdocs\/content,; print "$file from $dir to $newdir\n"; # create the path in the new location if it doesn't exist if (! -e $newdir){ `mkdir -p $newdir`;} # create the derivatives if they don't exist # name them appropriately and put them in the new location $new = $newdir."/".$file; $old = $dir."/".$file; if (! -e $new){ copy($old, $new);} } } } close(DIR); } # clean up `chown -R taloewald:www $outbase`; `chmod -R 775 $outbase`;