]>
iEval git - app-musicexpo.git/blob - lib/App/MusicExpo.pm
3fccfbb333b36f430eb9d94e6f0d6dfa127f3d57
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/;
23 ##################################################
27 our $prefix='/music/';
32 "template:s" => \
$template,
33 "prefix:s" => \
$prefix,
39 my $flac=Audio
::FLAC
::Header
->new($file);
43 title
=> $flac->tags('TITLE') // '?',
44 artist
=> $flac->tags('ARTIST') // '?',
45 year
=> $flac->tags('DATE') // '?',
46 album
=> $flac->tags('ALBUM') // '?',
47 tracknumber
=> $flac->tags('TRACKNUMBER') // '?',
48 tracktotal
=> $flac->tags('TRACKTOTAL') // '?',
49 genre
=> $flac->tags('GENRE') // '?',
50 file
=> scalar fileparse
$file,
56 my %tag = map { encode
'UTF-8', $_ } %{get_mp3tag
$file};
57 my @trkn = split '/', $tag{TRACKNUM
} // '';
61 title
=> $tag{TITLE
} || '?',
62 artist
=> $tag{ARTIST
} || '?',
63 year
=> $tag{YEAR
} || '?',
64 album
=> $tag{ALBUM
} || '?',
65 tracknumber
=> $trkn[0] || '?',
66 tracktotal
=> $trkn[1] || '?',
67 genre
=> $tag{GENRE
} || '?',
68 file
=> scalar fileparse
$file,
74 my $ogg=Ogg
::Vorbis
::Header
::PurePerl
->new($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') || '?',
85 file
=> scalar fileparse
$file,
91 return 'AAC' if $encoding eq 'mp4a';
92 return 'ALAC' if $encoding eq 'alac';
98 my %tag = map { ref() ?
$_ : encode
'UTF-8', $_ } %{get_mp4tag
$file};
99 my %info = %{get_mp4info
$file};
102 format
=> mp4_format
$info{ENCODING
},
103 title
=> $tag{TITLE
} || '?',
104 artist
=> $tag{ARTIST
} || '?',
105 year
=> $tag{YEAR
} || '?',
106 album
=> $tag{ALBUM
} || '?',
107 tracknumber
=> $tag{TRACKNUM
} || '?',
108 tracktotal
=> ($tag{TRKN
} ?
$tag{TRKN
}->[1] : undef) || '?',
109 genre
=> $tag{GENRE
} || '?',
110 file
=> scalar fileparse
$file,
115 '.flac' => \
&flacinfo
,
117 '.ogg' => \
&vorbisinfo
,
118 '.oga' => \
&vorbisinfo
,
125 "$_[0]|".(stat $_[0])[9]
128 sub make_fragment
{ join '-', map { lc =~ y/a-z0-9/_/csr } @_ }
133 tie
my %cache, 'DB_File', $cache, O_RDWR
|O_CREAT
, 0644;
134 $info{$_} = memoize
$info{$_}, INSTALL
=> undef, NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'FAULT', SCALAR_CACHE
=> [HASH
=> \
%cache] for keys %info;
138 for my $file (@ARGV) {
139 my ($basename, undef, $suffix) = fileparse
$file, keys %info;
140 $files{$basename} //= [];
141 push @
{$files{$basename}}, thaw
scalar $info{$suffix}->($file);
144 my $ht=HTML
::Template
::Compiled
->new(
145 default_escape
=> 'HTML',
147 $template eq '' ?
(scalarref
=> \
$default_template) : (filename
=> $template),
151 for (sort keys %files) {
152 my @versions = @
{$files{$_}};
153 my %entry = (%{$versions[0]}, formats
=> []);
154 for my $ver (@versions) {
155 push @
{$entry{formats
}}, {format
=> $ver->{format
}, file
=> $ver->{file
}};
156 for my $key (keys %$ver) {
157 $entry{$key} = $ver->{$key} if $ver->{$key} ne '?';
160 delete $entry{$_} for qw
/format file/;
161 $entry{fragment
} = make_fragment
@entry{qw
/artist title/};
165 @files = sort { $a->{title
} cmp $b->{title
} } @files;
166 $ht->param(files
=> \
@files, prefix
=> $prefix);
170 $default_template = <<'HTML';
173 <meta charset="utf-8">
174 <link rel="stylesheet" href="musicexpo.css">
175 <script async defer type="application/javascript" src="player.js"></script>
177 <div id="player"></div>
181 <tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
182 <tbody><tmpl_loop files>
183 <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>
195 App::MusicExpo - script which generates a HTML table of music tags
204 App::MusicExpo creates a HTML table from a list of songs.
206 The default template looks like:
208 | Title | Artist | Album | Genre | Track | Year | Type |
209 |---------+---------+-----------------+---------+-------+------+------|
210 | Cellule | Silence | L'autre endroit | Electro | 01/09 | 2005 | FLAC |
212 where the type is a download link. If you have multiple files with the same
213 basename (such as C<cellule.flac> and C<cellule.ogg>), they will be treated
214 as two versions of the same file, so a row will be created with two download
215 links, one for each format.
221 =item B<--template> I<template>
223 Path to the HTML::Template::Compiled template used for generating the music table. If '' (empty), uses the default format. Is empty by default.
225 =item B<--prefix> I<prefix>
227 Prefix for download links. Defaults to '/music/'.
229 =item B<--cache> I<filename>
231 Path to the cache file. Created if it does not exist. If '' (empty), disables caching. Is empty by default.
237 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
239 =head1 COPYRIGHT AND LICENSE
241 Copyright (C) 2013-2015 by Marius Gavrilescu
243 This library is free software; you can redistribute it and/or modify
244 it under the same terms as Perl itself, either Perl version 5.14.2 or,
245 at your option, any later version of Perl 5 you may have available.
This page took 0.065653 seconds and 3 git commands to generate.