]>
iEval git - app-musicexpo.git/blob - lib/App/MusicExpo.pm
1 package App
::MusicExpo
;
6 our $VERSION = '1.001_000';
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/;
14 use Audio
::Opusfile qw
//;
17 use Encode qw
/encode/;
18 use File
::Basename qw
/fileparse/;
19 use Fcntl qw
/O_RDWR O_CREAT/;
21 use Storable qw
/thaw freeze/;
24 ##################################################
28 our $prefix='/music/';
33 'template:s' => \
$template,
34 'prefix:s' => \
$prefix,
40 my $flac=Audio
::FLAC
::Header
->new($file);
44 title
=> $flac->tags('TITLE'),
45 artist
=> $flac->tags('ARTIST'),
46 year
=> $flac->tags('DATE'),
47 album
=> $flac->tags('ALBUM'),
48 tracknumber
=> $flac->tags('TRACKNUMBER'),
49 tracktotal
=> $flac->tags('TRACKTOTAL'),
50 genre
=> $flac->tags('GENRE'),
51 file
=> scalar fileparse
$file,
57 my %tag = map { encode
'UTF-8', $_ } %{get_mp3tag
$file};
58 my @trkn = split m
#/#s, $tag{TRACKNUM} // '';
63 artist
=> $tag{ARTIST
},
66 tracknumber
=> $trkn[0],
67 tracktotal
=> $trkn[1],
69 file
=> scalar fileparse
$file,
75 my $ogg=Ogg
::Vorbis
::Header
::PurePerl
->new($file);
79 title
=> scalar $ogg->comment('TITLE'),
80 artist
=> scalar $ogg->comment('artist'),
81 year
=> scalar $ogg->comment('DATE'),
82 album
=> scalar $ogg->comment('ALBUM'),
83 tracknumber
=> scalar $ogg->comment('TRACKNUMBER'),
84 tracktotal
=> scalar $ogg->comment('TRACKTOTAL'),
85 genre
=> scalar $ogg->comment('GENRE'),
86 file
=> scalar fileparse
$file,
90 sub mp4_format
($){ ## no critic (ProhibitSubroutinePrototypes)
92 return 'AAC' if $encoding eq 'mp4a';
93 return 'ALAC' if $encoding eq 'alac';
99 my %tag = map { ref() ?
$_ : encode
'UTF-8', $_ } %{get_mp4tag
$file};
100 my %info = %{get_mp4info
$file};
103 format
=> mp4_format
$info{ENCODING
},
104 title
=> $tag{TITLE
},
105 artist
=> $tag{ARTIST
},
107 album
=> $tag{ALBUM
},
108 tracknumber
=> $tag{TRACKNUM
},
109 tracktotal
=> ($tag{TRKN
} ?
$tag{TRKN
}->[1] : undef),
110 genre
=> $tag{GENRE
},
111 file
=> scalar fileparse
$file,
117 my $of = Audio
::Opusfile
->new_from_file($file);
118 my $tags = $of->tags;
122 title
=> $tags->query('TITLE'),
123 artist
=> $tags->query('ARTIST'),
124 year
=> $tags->query('DATE'),
125 album
=> $tags->query('ALBUM'),
126 tracknumber
=> $tags->query('TRACKNUMBER'),
127 tracktotal
=> $tags->query('TRACKTOTAL'),
128 genre
=> $tags->query('GENRE'),
129 file
=> scalar fileparse
$file
136 '.flac' => \
&flacinfo
,
138 '.ogg' => \
&vorbisinfo
,
139 '.oga' => \
&vorbisinfo
,
143 '.opus' => \
&opusinfo
,
147 "$_[0]|".(stat $_[0])[9]
150 sub make_fragment
{ join '-', map { lc =~ y/a-z0-9/_/csr } @_ }
154 tie
my %cache, 'DB_File', $cache, O_RDWR
|O_CREAT
, 0644; ## no critic (ProhibitTie)
155 $info{$_} = memoize
$info{$_}, INSTALL
=> undef, NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'FAULT', SCALAR_CACHE
=> [HASH
=> \
%cache] for keys %info;
159 for my $file (@ARGV) {
160 my ($basename, undef, $suffix) = fileparse
$file, keys %info;
161 $files{$basename} //= [];
162 push @
{$files{$basename}}, thaw
scalar $info{$suffix}->($file);
165 my $ht=HTML
::Template
::Compiled
->new(
166 default_escape
=> 'HTML',
168 $template eq '' ?
(scalarref
=> \
$default_template) : (filename
=> $template),
172 for (sort keys %files) {
173 my @versions = @
{$files{$_}};
174 my %entry = (formats
=> [], map { $_ => '?' } qw
/title artist year album tracknumber tracktotal genre/);
175 for my $ver (@versions) {
176 push @
{$entry{formats
}}, {format
=> $ver->{format
}, file
=> $ver->{file
}};
177 for my $key (keys %$ver) {
178 $entry{$key} = $ver->{$key} if $ver->{$key} && $ver->{$key} ne '?';
181 delete $entry{$_} for qw
/format file/;
182 $entry{fragment
} = make_fragment
@entry{qw
/artist title/};
186 @files = sort { $a->{title
} cmp $b->{title
} } @files;
187 $ht->param(files
=> \
@files, prefix
=> $prefix);
188 print $ht->output; ## no critic (RequireCheckedSyscalls)
191 $default_template = <<'HTML';
194 <meta charset="utf-8">
195 <link rel="stylesheet" href="musicexpo.css">
196 <script async defer type="application/javascript" src="player.js"></script>
198 <div id="player"></div>
202 <tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
203 <tbody><tmpl_loop files>
204 <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>
216 App::MusicExpo - script which generates a HTML table of music tags
225 App::MusicExpo creates a HTML table from a list of songs.
227 The default template looks like:
229 | Title | Artist | Album | Genre | Track | Year | Type |
230 |---------+---------+-----------------+---------+-------+------+------|
231 | Cellule | Silence | L'autre endroit | Electro | 01/09 | 2005 | FLAC |
233 where the type is a download link. If you have multiple files with the same
234 basename (such as C<cellule.flac> and C<cellule.ogg>), they will be treated
235 as two versions of the same file, so a row will be created with two download
236 links, one for each format.
242 =item B<--template> I<template>
244 Path to the HTML::Template::Compiled template used for generating the music table. If '' (empty), uses the default format. Is empty by default.
246 =item B<--prefix> I<prefix>
248 Prefix for download links. Defaults to '/music/'.
250 =item B<--cache> I<filename>
252 Path to the cache file. Created if it does not exist. If '' (empty), disables caching. Is empty by default.
258 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
260 =head1 COPYRIGHT AND LICENSE
262 Copyright (C) 2013-2016 by Marius Gavrilescu
264 This library is free software; you can redistribute it and/or modify
265 it under the same terms as Perl itself, either Perl version 5.14.2 or,
266 at your option, any later version of Perl 5 you may have available.
This page took 0.06933 seconds and 5 git commands to generate.