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/;
12 use Ogg
::Vorbis
::Header
::PurePerl
;
13 use MP4
::Info qw
/get_mp4tag get_mp4info/;
16 use File
::Basename qw
/fileparse/;
17 use Fcntl qw
/O_RDWR O_CREAT/;
19 use Storable qw
/thaw freeze/;
21 ##################################################
25 our $prefix='/music/';
30 "template:s" => \
$template,
31 "prefix:s" => \
$prefix,
37 my $flac=Audio
::FLAC
::Header
->new($file);
38 $file = scalar fileparse
$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') // '?',
55 my $mp3=MP3
::Tag
->new($file);
56 $file = scalar fileparse
$file;
60 title
=> $mp3->title || '?',
61 artist
=> $mp3->artist || '?',
62 year
=> $mp3->year || '?',
63 album
=> $mp3->album || '?',
64 tracknumber
=> $mp3->track1 || '?',
65 tracktotal
=> $mp3->track2 || '?',
66 genre
=> $mp3->genre || '?',
73 my $ogg=Ogg
::Vorbis
::Header
::PurePerl
->new($file);
74 $file = scalar fileparse
$file;
78 title
=> $ogg->comment('TITLE') || '?',
79 artist
=> $ogg->comment('artist') || '?',
80 year
=> $ogg->comment('DATE') || '?',
81 album
=> $ogg->comment('ALBUM') || '?',
82 tracknumber
=> $ogg->comment('TRACKNUMBER') || '?',
83 tracktotal
=> $ogg->comment('TRACKTOTAL') || '?',
84 genre
=> $ogg->comment('GENRE') || '?',
91 return 'AAC' if $encoding eq 'mp4a';
92 return 'ALAC' if $encoding eq 'alac';
98 my %tag = %{get_mp4tag
$file};
99 my %info = %{get_mp4info
$file};
100 $file = scalar fileparse
$file;
103 format
=> mp4_format
$info{ENCODING
},
104 title
=> $tag{TITLE
} || '?',
105 artist
=> $tag{ARTIST
} || '?',
106 year
=> $tag{YEAR
} || '?',
107 album
=> $tag{ALBUM
} || '?',
108 tracknumber
=> $tag{TRACKNUM
} || '?',
109 tracktotal
=> ($tag{TRKN
} ?
$tag{TRKN
}->[1] : undef) || '?',
110 genre
=> $tag{GENRE
} || '?',
116 '.flac' => \
&flacinfo
,
118 '.ogg' => \
&vorbisinfo
,
119 '.oga' => \
&vorbisinfo
,
126 "$_[0]|".(stat $_[0])[9]
129 sub make_fragment
{ join '-', map { lc =~ y/a-z0-9/_/csr } @_ }
134 tie
my %cache, 'DB_File', $cache, O_RDWR
|O_CREAT
, 0644;
135 $info{$_} = memoize
$info{$_}, INSTALL
=> undef, NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'FAULT', SCALAR_CACHE
=> [HASH
=> \
%cache] for keys %info;
139 for my $file (@ARGV) {
140 my ($basename, undef, $suffix) = fileparse
$file, keys %info;
141 $files{$basename} //= [];
142 push @
{$files{$basename}}, thaw
scalar $info{$suffix}->($file);
145 my $ht=HTML
::Template
::Compiled
->new(
146 default_escape
=> 'HTML',
148 $template eq '' ?
(scalarref
=> \
$default_template) : (filename
=> $template),
152 for (values %files) {
154 my %entry = (%{$versions[0]}, formats
=> []);
155 for my $ver (@versions) {
156 push @
{$entry{formats
}}, {format
=> $ver->{format
}, file
=> $ver->{file
}};
157 for my $key (keys %$ver) {
158 $entry{$key} = $ver->{$key} if $ver->{$key} ne '?';
161 delete $entry{$_} for qw
/format file/;
162 $entry{fragment
} = make_fragment
@entry{qw
/artist title/};
166 @files = sort { $a->{title
} cmp $b->{title
} } @files;
167 $ht->param(files
=> \
@files, prefix
=> $prefix);
171 $default_template = <<'HTML';
174 <meta charset="utf-8">
175 <link rel="stylesheet" href="musicexpo.css">
176 <script async defer type="application/javascript" src="player.js"></script>
178 <div id="player"></div>
182 <tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
183 <tbody><tmpl_loop files>
184 <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>
196 App::MusicExpo - script which generates a HTML table of music tags
205 App::MusicExpo creates a HTML table from a list of songs.
207 The default template looks like:
209 | Title | Artist | Album | Genre | Track | Year | Type |
210 |---------+---------+-----------------+---------+-------+------+------|
211 | Cellule | Silence | L'autre endroit | Electro | 01/09 | 2005 | FLAC |
213 where the type is a download link. If you have multiple files with the same
214 basename (such as C<cellule.flac> and C<cellule.ogg>), they will be treated
215 as two versions of the same file, so a row will be created with two download
216 links, one for each format.
222 =item B<--template> I<template>
224 Path to the HTML::Template::Compiled template used for generating the music table. If '' (empty), uses the default format. Is empty by default.
226 =item B<--prefix> I<prefix>
228 Prefix for download links. Defaults to '/music/'.
230 =item B<--cache> I<filename>
232 Path to the cache file. Created if it does not exist. If '' (empty), disables caching. Is empty by default.
238 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
240 =head1 COPYRIGHT AND LICENSE
242 Copyright (C) 2013-2015 by Marius Gavrilescu
244 This library is free software; you can redistribute it and/or modify
245 it under the same terms as Perl itself, either Perl version 5.14.2 or,
246 at your option, any later version of Perl 5 you may have available.
This page took 0.038491 seconds and 4 git commands to generate.