]>
iEval git - app-musicexpo.git/blob - lib/App/MusicExpo.pm
1 package App
::MusicExpo
;
6 our $VERSION = 0.003001;
8 use Audio
::FLAC
::Header qw
//;
9 use HTML
::Template
::Compiled qw
//;
10 use Memoize qw
/memoize/;
12 use Ogg
::Vorbis
::Header
::PurePerl
;
15 use File
::Basename qw
/fileparse/;
16 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,
44 my $flac=Audio
::FLAC
::Header
->new($file);
45 $file = scalar fileparse
$file;
49 title
=> fix
($flac->tags('TITLE') // '?'),
50 artist
=> fix
($flac->tags('ARTIST') // '?'),
51 year
=> fix
($flac->tags('DATE') // '?'),
52 album
=> fix
($flac->tags('ALBUM') // '?'),
53 tracknumber
=> fix
($flac->tags('TRACKNUMBER') // '?'),
54 tracktotal
=> fix
($flac->tags('TRACKTOTAL') // '?'),
55 genre
=> fix
($flac->tags('GENRE') // '?'),
62 my $mp3=MP3
::Tag
->new($file);
63 $file = scalar fileparse
$file;
67 title
=> fix
($mp3->title || '?'),
68 artist
=> fix
($mp3->artist || '?'),
69 year
=> fix
($mp3->year || '?'),
70 album
=> fix
($mp3->album || '?'),
71 tracknumber
=> fix
($mp3->track1 || '?'),
72 tracktotal
=> fix
($mp3->track2 || '?'),
73 genre
=> fix
($mp3->genre) || '?',
80 my $ogg=Ogg
::Vorbis
::Header
::PurePerl
->new($file);
81 $file = scalar fileparse
$file;
85 title
=> fix
($ogg->comment('TITLE') || '?'),
86 artist
=> fix
($ogg->comment('artist') || '?'),
87 year
=> fix
($ogg->comment('DATE') || '?'),
88 album
=> fix
($ogg->comment('ALBUM') || '?'),
89 tracknumber
=> fix
($ogg->comment('TRACKNUMBER') || '?'),
90 tracktotal
=> fix
($ogg->comment('TRACKTOTAL') || '?'),
91 genre
=> fix
($ogg->comment('GENRE')) || '?',
97 "$_[0]|".(stat $_[0])[9]
101 tie
my %cache, 'DB_File', $cache, O_RDWR
|O_CREAT
, 0644 unless $cache eq '';
102 memoize
'flacinfo', NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
103 memoize
'mp3info' , NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
104 memoize
'vorbisinfo' , NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
107 for my $file (@ARGV) {
109 $info = thaw flacinfo
$file if $file =~ /.flac$/i;
110 $info = thaw mp3info
$file if $file =~ /.mp3$/i;
111 $info = thaw vorbisinfo
$file if $file =~ /.og(?:g|a)$/i;
112 next unless defined $info;
113 my $basename = fileparse
$file, '.flac', '.mp3', '.ogg', '.oga';
114 $files{$basename} //= [];
115 push $files{$basename}, $info;
118 my $ht=HTML
::Template
::Compiled
->new(
119 default_escape
=> 'HTML',
121 $template eq '' ?
(scalarref
=> \
$default_template) : (filename
=> $template),
125 for (values %files) {
127 my %entry = (%{$versions[0]}, formats
=> []);
128 push $entry{formats
}, {format
=> $_->{format
}, file
=> $_->{file
}} for @versions;
132 my $json = JSON
->new->utf8->canonical->encode({files
=> \
@files, prefix
=> $prefix});
135 $ht->param(files
=>[sort { $a->{title
} cmp $b->{title
} } @files], prefix
=> $prefix, json
=> $json);
139 $default_template = <<'HTML';
142 <meta charset="utf-8">
143 <link rel="stylesheet" href="/music.css">
147 <tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
148 <tbody><tmpl_loop files>
149 <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>
152 <pre id="json" style="display: none"><tmpl_var ESCAPE=0 json></pre>
163 App::MusicExpo - script which generates a HTML table of music tags
172 App::MusicExpo creates a HTML table from a list of songs.
174 The default template looks like:
176 | Title | Artist | Album | Genre | Track | Year | Type |
177 |---------+---------+-----------------+---------+-------+------+------|
178 | Cellule | Silence | L'autre endroit | Electro | 01/09 | 2005 | FLAC |
180 where the type is a download link. If you have multiple files with the same
181 basename (such as C<cellule.flac> and C<cellule.ogg>), they will be treated
182 as two versions of the same file, so a row will be created with two download
183 links, one for each format.
189 =item B<--template> I<template>
191 Path to the HTML::Template::Compiled template used for generating the music table. If '' (empty), uses the default format. Is empty by default.
193 =item B<--prefix> I<prefix>
195 Prefix for download links. Defaults to '/music/'.
197 =item B<--cache> I<filename>
199 Path to the cache file. Created if it does not exist. If '' (empty), disables caching. Is empty by default.
205 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
207 =head1 COPYRIGHT AND LICENSE
209 Copyright (C) 2013 by Marius Gavrilescu
211 This library is free software; you can redistribute it and/or modify
212 it under the same terms as Perl itself, either Perl version 5.14.2 or,
213 at your option, any later version of Perl 5 you may have available.
This page took 0.080734 seconds and 4 git commands to generate.