Fix caching
[app-musicexpo.git] / lib / App / MusicExpo.pm
index 0b3276cab35784406e1f29a145af1276d9362ea4..3bdef011a6d7086d7ee766068e190a0271eba187 100644 (file)
@@ -3,7 +3,7 @@ use v5.14;
 use strict;
 use warnings;
 
-our $VERSION = '0.003003';
+our $VERSION = '0.005';
 
 use Audio::FLAC::Header qw//;
 use HTML::Template::Compiled qw//;
@@ -16,7 +16,6 @@ use DB_File qw//;
 use File::Basename qw/fileparse/;
 use Fcntl qw/O_RDWR O_CREAT/;
 use Getopt::Long;
-use JSON::MaybeXS;
 use Storable qw/thaw freeze/;
 
 ##################################################
@@ -124,6 +123,8 @@ sub normalizer{
        "$_[0]|".(stat $_[0])[9]
 }
 
+sub make_fragment{ join '-', map { lc =~ y/a-z0-9/_/csr } @_ }
+
 sub run {
        if ($cache) {
                tie my %cache, 'DB_File', $cache, O_RDWR|O_CREAT, 0644;
@@ -133,10 +134,10 @@ sub run {
        my %files;
        for my $file (@ARGV) {
                my $info;
-               $info = thaw flacinfo $file if $file =~ /\.flac$/i;
-               $info = thaw mp3info $file if $file =~ /\.mp3$/i;
-               $info = thaw vorbisinfo $file if $file =~ /\.og(?:g|a)$/i;
-               $info = thaw mp4info $file if $file =~ /\.mp4|\.aac|\.m4a$/i;
+               $info = thaw scalar flacinfo $file if $file =~ /\.flac$/i;
+               $info = thaw scalar mp3info $file if $file =~ /\.mp3$/i;
+               $info = thaw scalar vorbisinfo $file if $file =~ /\.og(?:g|a)$/i;
+               $info = thaw scalar mp4info $file if $file =~ /\.mp4|\.aac|\.m4a$/i;
                next unless defined $info;
                my $basename = fileparse $file, '.flac', '.mp3', '.ogg', '.oga', '.mp4', '.aac', '.m4a';
                $files{$basename} //= [];
@@ -160,13 +161,12 @@ sub run {
                        }
                }
                delete $entry{$_} for qw/format file/;
+               $entry{fragment} = make_fragment @entry{qw/artist title/};
                push @files, \%entry
        }
 
-       my $json = JSON::MaybeXS->new(canonical => 1)->encode({files => \@files, prefix => $prefix});
-       $json =~ s/</&lt;/g;
-       $json =~ s/>/&gt;/g;
-       $ht->param(files=>[sort { $a->{title} cmp $b->{title} } @files], prefix => $prefix, json => $json);
+       @files = sort { $a->{title} cmp $b->{title} } @files;
+       $ht->param(files => \@files, prefix => $prefix);
        print $ht->output;
 }
 
@@ -174,16 +174,17 @@ $default_template = <<'HTML';
 <!DOCTYPE html>
 <title>Music</title>
 <meta charset="utf-8">
-<link rel="stylesheet" href="/music.css">
+<link rel="stylesheet" href="musicexpo.css">
+<script async defer type="application/javascript" src="player.js"></script>
+
+<div id="player"></div>
 
 <table border>
 <thead>
 <tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
 <tbody><tmpl_loop files>
-<tr><td><tmpl_var title><td><tmpl_var artist><td><tmpl_var album><td><tmpl_var genre><td><tmpl_var tracknumber>/<tmpl_var tracktotal><td><tmpl_var year><td><tmpl_loop formats><a href="<tmpl_var ...prefix><tmpl_var ESCAPE=URL file>"><tmpl_var format></a> </tmpl_loop></tmpl_loop>
+<tr><td class="title"><a href="#<tmpl_var fragment>" data-hash="#<tmpl_var fragment>"><tmpl_var title></a><td class="artist"><tmpl_var artist><td class="album"><tmpl_var album><td class="genre"><tmpl_var genre><td class="track"><tmpl_var tracknumber>/<tmpl_var tracktotal><td class="year"><tmpl_var year><td class="formats"><tmpl_loop formats><a href="<tmpl_var ...prefix><tmpl_var ESCAPE=URL file>"><tmpl_var format></a> </tmpl_loop></tmpl_loop>
 </table>
-
-<pre id="json" style="display: none"><tmpl_var ESCAPE=0 json></pre>
 HTML
 
 1;
@@ -240,7 +241,7 @@ Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright (C) 2013-2014 by Marius Gavrilescu
+Copyright (C) 2013-2015 by Marius Gavrilescu
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself, either Perl version 5.14.2 or,
This page took 0.010876 seconds and 4 git commands to generate.