#!/usr/bin/perl -w use strict; use File::Find; use File::Basename; my $startdir = $ARGV[0]; my $filecounter=1; my $htmlfile="thumb-index"; my $curdir; my $curfile; my $dircounter=1; my @directoryfiles; my @directories; my %tree; sub wanted { my ($dev,$ino,$mode,$nlink,$uid,$gid); # (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -d _ && push @directories, $File::Find::name; # (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -f _ && push @candidates, $File::Find::name; if(lstat($_) && -f _) { my $filename = $File::Find::name; my $candidatefile=dirsubtract($filename, $startdir); my $candidatedir=&File::Basename::dirname($candidatefile); push @{ $tree{$candidatedir}{files} },$candidatefile; if (!$tree{$candidatedir}{dirfile}) { $tree{$candidatedir}{dirfile}=$htmlfile.$dircounter.".html";$dircounter++;} } } sub dirsubtract { my ($a, $b) = @_; my @alist = split /\//,$a ; my @blist = split /\//,$b ; while (($#blist >=0) && ($alist[0] eq $blist[0])) { shift @alist; shift @blist;}; return join( "/", @alist); } sub makethumb { my ($moviefile, $thumbnailfile) = @_; my $framefile; my @runcommand; my @mplayercommand=("/usr/bin/mplayer","-vo", "png", "-nosound", "-ss", "0:29", "-frames", "6", "-osdlevel", "0","-z","5", "-x", "320","-y","200"); my @convertcommand=("/usr/bin/convert","-resize","320x200"); $framefile="00000005.png"; @runcommand=(@mplayercommand,$moviefile); system(@runcommand); if ( (stat($framefile))[7] > 0 ) { @runcommand=(@convertcommand,$framefile,$thumbnailfile); system(@runcommand); unlink($framefile); # rename "$framefile","$thumbnailfile"; return 1; } else { return 0 }; } sub makethumbtable { my ($topdir,$currentdir,@inputfiles) = @_; my $thumbfile; my $colcounter; my $tablecols=3; my $filename; my $basename; print HTML "
| ";
$colcounter=1;
foreach $filename (@inputfiles) {
$thumbfile="pix-$filecounter.png";
$basename = File::Basename::basename($filename);
if(&makethumb($topdir.$filename,$thumbfile)){
print HTML "$basename | ";
$filecounter++;
if ($colcounter==$tablecols){print HTML "|
| ";$colcounter=1;} else {print HTML " | ";$colcounter++;}; } else { print HTML "$basename | "; if ($colcounter==$tablecols){print HTML "
| ";$colcounter=1;} else {print HTML " | ";$colcounter++;}; }; } print HTML " |
| \n";
foreach $curfile (sort keys %tree) {
print HTML "$curfile \n"; }; print HTML " | \n"; @directoryfiles=@{ $tree{$curdir}{files} }; #print "\n\n @directoryfiles\n\n"; makethumbtable($startdir, "hmm", @directoryfiles); print HTML " |