1 package App
::MusicExpo
;
6 our $VERSION = '0.005';
8 use Audio
::FLAC
::Header qw
//;
9 use HTML
::Template
::Compiled qw
//;
10 use Memoize qw
/memoize/;
11 use MP3
::Info qw
/get_mp3tag/;
12 use Ogg
::Vorbis
::Header
::PurePerl
;
13 use MP4
::Info qw
/get_mp4tag get_mp4info/;
16 use Encode qw
/encode/;
17 use File
::Basename qw
/fileparse/;
18 use Fcntl qw
/O_RDWR O_CREAT/;
20 use Storable qw
/thaw freeze/;
22 ##################################################
26 our $prefix='/music/';
31 "template:s" => \
$template,
32 "prefix:s" => \
$prefix,
38 my $flac=Audio
::FLAC
::Header
->new($file);
42 title
=> $flac->tags('TITLE') // '?',
43 artist
=> $flac->tags('ARTIST') // '?',
44 year
=> $flac->tags('DATE') // '?',
45 album
=> $flac->tags('ALBUM') // '?',
46 tracknumber
=> $flac->tags('TRACKNUMBER') // '?',
47 tracktotal
=> $flac->tags('TRACKTOTAL') // '?',
48 genre
=> $flac->tags('GENRE') // '?',
49 file
=> scalar fileparse
$file,
55 my %tag = map { encode
'UTF-8', $_ } %{get_mp3tag
$file};
56 my @trkn = split '/', $tag{TRACKNUM
} // '';
60 title
=> $tag{TITLE
} || '?',
61 artist
=> $tag{ARTIST
} || '?',
62 year
=> $tag{YEAR
} || '?',
63 album
=> $tag{ALBUM
} || '?',
64 tracknumber
=> $trkn[0] || '?',
65 tracktotal
=> $trkn[1] || '?',
66 genre
=> $tag{GENRE
} || '?',
67 file
=> scalar fileparse
$file,
73 my $ogg=Ogg
::Vorbis
::Header
::PurePerl
->new($file);
77 title
=> $ogg->comment('TITLE') || '?',
78 artist
=> $ogg->comment('artist') || '?',
79 year
=> $ogg->comment('DATE') || '?',
80 album
=> $ogg->comment('ALBUM') || '?',
81 tracknumber
=> $ogg->comment('TRACKNUMBER') || '?',
82 tracktotal
=> $ogg->comment('TRACKTOTAL') || '?',
83 genre
=> $ogg->comment('GENRE') || '?',
84 file
=> scalar fileparse
$file,
90 return 'AAC' if $encoding eq 'mp4a';
91 return 'ALAC' if $encoding eq 'alac';
97 my %tag = map { ref() ?
$_ : encode
'UTF-8', $_ } %{get_mp4tag
$file};
98 my %info = %{get_mp4info
$file};
101 format
=> mp4_format
$info{ENCODING
},
102 title
=> $tag{TITLE
} || '?',
103 artist
=> $tag{ARTIST
} || '?',
104 year
=> $tag{YEAR
} || '?',
105 album
=> $tag{ALBUM
} || '?',
106 tracknumber
=> $tag{TRACKNUM
} || '?',
107 tracktotal
=> ($tag{TRKN
} ?
$tag{TRKN
}->[1] : undef) || '?',
108 genre
=> $tag{GENRE
} || '?',
109 file
=> scalar fileparse
$file,
114 '.flac' => \
&flacinfo
,
116 '.ogg' => \
&vorbisinfo
,
117 '.oga' => \
&vorbisinfo
,
124 "$_[0]|".(stat $_[0])[9]
127 sub make_fragment
{ join '-', map { lc =~ y/a-z0-9/_/csr } @_ }
132 tie
my %cache, 'DB_File', $cache, O_RDWR
|O_CREAT
, 0644;
133 $info{$_} = memoize
$info{$_}, INSTALL
=> undef, NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'FAULT', SCALAR_CACHE
=> [HASH
=> \
%cache] for keys %info;
137 for my $file (@ARGV) {
138 my ($basename, undef, $suffix) = fileparse
$file, keys %info;
139 $files{$basename} //= [];
140 push @
{$files{$basename}}, thaw
scalar $info{$suffix}->($file);
143 my $ht=HTML
::Template
::Compiled
->new(
144 default_escape
=> 'HTML',
146 $template eq '' ?
(scalarref
=> \
$default_template) : (filename
=> $template),
150 for (values %files) {
152 my %entry = (%{$versions[0]}, formats
=> []);
153 for my $ver (@versions) {
154 push @
{$entry{formats
}}, {format
=> $ver->{format
}, file
=> $ver->{file
}};
155 for my $key (keys %$ver) {
156 $entry{$key} = $ver->{$key} if $ver->{$key} ne '?';
159 delete $entry{$_} for qw
/format file/;
160 $entry{fragment
} = make_fragment
@entry{qw
/artist title/};
164 @files = sort { $a->{title
} cmp $b->{title
} } @files;
165 $ht->param(files
=> \
@files, prefix
=> $prefix);
169 $default_template = <<'HTML';
172 <meta charset="utf-8">
173 <link rel="stylesheet" href="musicexpo.css">
174 <script async defer type="application/javascript" src="player.js"></script>
176 <div id="player"></div>
180 <tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
181 <tbody><tmpl_loop files>
182 <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>
194 App::MusicExpo - script which generates a HTML table of music tags
203 App::MusicExpo creates a HTML table from a list of songs.
205 The default template looks like:
207 | Title | Artist | Album | Genre | Track | Year | Type |
208 |---------+---------+-----------------+---------+-------+------+------|
209 | Cellule | Silence | L'autre endroit | Electro | 01/09 | 2005 | FLAC |
211 where the type is a download link. If you have multiple files with the same
212 basename (such as C<cellule.flac> and C<cellule.ogg>), they will be treated
213 as two versions of the same file, so a row will be created with two download
214 links, one for each format.
220 =item B<--template> I<template>
222 Path to the HTML::Template::Compiled template used for generating the music table. If '' (empty), uses the default format. Is empty by default.
224 =item B<--prefix> I<prefix>
226 Prefix for download links. Defaults to '/music/'.
228 =item B<--cache> I<filename>
230 Path to the cache file. Created if it does not exist. If '' (empty), disables caching. Is empty by default.
236 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
238 =head1 COPYRIGHT AND LICENSE
240 Copyright (C) 2013-2015 by Marius Gavrilescu
242 This library is free software; you can redistribute it and/or modify
243 it under the same terms as Perl itself, either Perl version 5.14.2 or,
244 at your option, any later version of Perl 5 you may have available.
This page took 0.036772 seconds and 4 git commands to generate.