#!/usr/bin/perl my $topdir= "/data"; my @genres= qw(metal jazz classical instrumental); my %genrenames= ( "metal" => "Heavy Metal", "jazz" => "Jazz", "classical" => "Classical Music", "instrumental" => "Instrumental Music" ); my $menudir= "menu"; # must be next to genre directories my $imgglob= "*.{png,jpg,jpeg,gif}"; my $audioglob= "*.{ogg,mp3,wma,aac,wav,flac,mp4}"; # Make album name from directory # -> directory (may include path) # <- name sub dir2name { my ($dir)= @_; $dir =~ s/^.*\///; $dir= join " ", map ucfirst($_), split /\W+/, $dir; return $dir; } # Get title image and first audio file of an album directory, and create # "dirpath" file, which contains the name of its own directory (needed to make # links pass the directory path to the mplayer script, because it insists on # copying the hyperlinked file). # -> album directory # <- ref to hash with image and firstplay entries, which give their paths sub getalbum { my ($basedir)= @_; my ($firstimg)= sort grep -f, glob "$basedir/$imgglob"; my ($firstaudio)= sort grep -f, glob "$basedir/$audioglob"; open DP, ">$basedir/path.dir" and print DP "$topdir/$menudir/$basedir" and close DP; return { "image" => $firstimg, "firstplay" => $firstaudio, "name" => dir2name($basedir), "path" => $basedir }; } # Get list of albums for one artist # -> artist directory # <- ref to array of album hashes sub getartist { my ($basedir)= @_; my @subdirs= grep -d, glob "$basedir/*"; my @albums; for my $dir (@subdirs) { my $alb= getalbum($dir); push @albums, $alb if $alb->{"firstplay"}; } return \@albums; } chdir "$topdir/$menudir" or die "Could not cd to menu dir"; for my $gen (@genres) { # my $dirtime= ${[stat "../$gen"]}[9]; # my $htmltime= ${[stat "gen.html"]}[9]; # next if $htmltime > $dirtime; my @subdirs= grep -d, glob "../$gen/*"; my @artists; for my $dir (@subdirs) { my $albums= getartist($dir); push @artists, { "albums" => $albums, "name" => dir2name($dir) } if @$albums > 0; } open HTML, ">", "$gen.html" or die "Could not open $gen.html for writing"; print HTML < $genrenames{$gen}

Top menu


$genrenames{$gen}

EOF for my $art (@artists) { print HTML <

$$art{"name"}

EOF for my $alb (@{$art->{"albums"}}) { print HTML "{"path"}, "/path.dir\">"; if( $alb->{"image"} ) { print HTML "{"image"}, "\" alt=\"", $alb->{"name"}, "\">   \n\n"; } else { print HTML "

", $alb->{"name"}, "

\n\n"; } } } print HTML < EOF close HTML; }