]>
iEval git - app-musicexpo.git/blob - MusicExpo.pm
d6ce05e4d168b4f352e9f4d6cae48536ae62be43
1 package App
::MusicExpo
;
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/;
18 use Storable qw
/thaw freeze/;
20 ##################################################
24 our $prefix='/music/';
29 "template=s" => \
$template,
30 "prefix=s" => \
$prefix,
42 my $flac=Audio
::FLAC
::Header
->new($file);
43 $file = scalar fileparse
$file;
47 title
=> fix
($flac->tags('TITLE') // '?'),
48 artist
=> fix
($flac->tags('ARTIST') // '?'),
49 year
=> fix
($flac->tags('DATE') // '?'),
50 album
=> fix
($flac->tags('ALBUM') // '?'),
51 tracknumber
=> fix
($flac->tags('TRACKNUMBER') // '?'),
52 tracktotal
=> fix
($flac->tags('TRACKTOTAL') // '?'),
53 genre
=> fix
($flac->tags('GENRE') // '?'),
60 my $mp3=MP3
::Tag
->new($file);
61 $file = scalar fileparse
$file;
65 title
=> fix
($mp3->title || '?'),
66 artist
=> fix
($mp3->artist || '?'),
67 year
=> fix
($mp3->year || '?'),
68 album
=> fix
($mp3->album || '?'),
69 tracknumber
=> fix
($mp3->track1 || '?'),
70 tracktotal
=> fix
($mp3->track2 || '?'),
71 genre
=> fix
($mp3->genre) || '?',
78 my $ogg=Ogg
::Vorbis
::Header
::PurePerl
->new($file);
79 $file = scalar fileparse
$file;
83 title
=> fix
($ogg->comment('TITLE') || '?'),
84 artist
=> fix
($ogg->comment('artist') || '?'),
85 year
=> fix
($ogg->comment('DATE') || '?'),
86 album
=> fix
($ogg->comment('ALBUM') || '?'),
87 tracknumber
=> fix
($ogg->comment('TRACKNUMBER') || '?'),
88 tracktotal
=> fix
($ogg->comment('TRACKTOTAL') || '?'),
89 genre
=> fix
($ogg->comment('GENRE')) || '?',
95 "$_[0]|".(stat $_[0])[9]
99 tie
my %cache, 'DB_File', $cache, O_RDWR
|O_CREAT
, 0644 unless $cache eq '';
100 memoize
'flacinfo', NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
101 memoize
'mp3info' , NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
102 memoize
'vorbisinfo' , NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
105 for my $file (@ARGV) {
107 $info = thaw flacinfo
$file if $file =~ /.flac$/i;
108 $info = thaw mp3info
$file if $file =~ /.mp3$/i;
109 $info = thaw vorbisinfo
$file if $file =~ /.og(?:g|a)$/i;
110 next unless defined $info;
111 my $basename = fileparse
$file, '.flac', '.mp3', '.ogg', '.oga';
112 $files{$basename} //= [];
113 push $files{$basename}, $info;
116 my $ht=HTML
::Template
::Compiled
->new(
117 default_escape
=> 'HTML',
119 $template eq '' ?
(scalarref
=> \
$default_template) : (filename
=> $template),
123 for (values %files) {
125 my %entry = (%{$versions[0]}, formats
=> []);
126 push $entry{formats
}, {format
=> $_->{format
}, file
=> $_->{file
}} for @versions;
130 $ht->param(files
=>[sort { $a->{title
} cmp $b->{title
} } @files], prefix
=> $prefix);
134 $default_template = <<'HTML';
137 <meta charset="utf-8">
138 <link rel="stylesheet" href="/music.css">
142 <tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
143 <tbody><tmpl_loop files>
144 <tr><td><a href=<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>
154 App::MusicExpo - script which generates a HTML table of music tags
163 App::MusicExpo creates a HTML table from a list of songs.
165 The default template looks like:
167 | Title | Artist | Album | Genre | Track | Year | Type |
168 |---------+---------+-----------------+---------+-------+------+------|
169 | Cellule | Silence | L'autre endroit | Electro | 01/09 | 2005 | FLAC |
171 where the type is a download link. If you have multiple files with the same
172 basename (such as C<cellule.flac> and C<cellule.ogg>), they will be treated
173 as two versions of the same file, so a row will be created with two download
174 links, one for each format.
180 =item B<--template> I<template>
182 Path to the HTML::Template::Compiled template used for generating the music table. If '' (empty), uses the default format. Is empty by default.
184 =item B<--prefix> I<prefix>
186 Prefix for download links. Defaults to '/music/'.
188 =item B<--cache> I<filename>
190 Path to the cache file. Created if it does not exist. If '' (empty), disables caching. Is empty by default.
196 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
198 =head1 COPYRIGHT AND LICENSE
200 Copyright (C) 2013 by Marius Gavrilescu
202 This library is free software; you can redistribute it and/or modify
203 it under the same terms as Perl itself, either Perl version 5.14.2 or,
204 at your option, any later version of Perl 5 you may have available.
This page took 0.061124 seconds and 3 git commands to generate.