]>
iEval git - app-musicexpo.git/blob - lib/App/MusicExpo.pm
1 package App
::MusicExpo
0.002;
6 use Audio
::FLAC
::Header qw
//;
7 use HTML
::Template
::Compiled qw
//;
8 use Memoize qw
/memoize/;
10 use Ogg
::Vorbis
::Header
::PurePerl
;
13 use File
::Basename qw
/fileparse/;
14 use Fcntl qw
/O_RDWR O_CREAT/;
16 use Storable qw
/thaw freeze/;
18 ##################################################
22 our $prefix='/music/';
27 "template=s" => \
$template,
28 "prefix=s" => \
$prefix,
40 my $flac=Audio
::FLAC
::Header
->new($file);
41 $file = scalar fileparse
$file;
45 title
=> fix
($flac->tags('TITLE') // '?'),
46 artist
=> fix
($flac->tags('ARTIST') // '?'),
47 year
=> fix
($flac->tags('DATE') // '?'),
48 album
=> fix
($flac->tags('ALBUM') // '?'),
49 tracknumber
=> fix
($flac->tags('TRACKNUMBER') // '?'),
50 tracktotal
=> fix
($flac->tags('TRACKTOTAL') // '?'),
51 genre
=> fix
($flac->tags('GENRE') // '?'),
58 my $mp3=MP3
::Tag
->new($file);
59 $file = scalar fileparse
$file;
63 title
=> fix
($mp3->title || '?'),
64 artist
=> fix
($mp3->artist || '?'),
65 year
=> fix
($mp3->year || '?'),
66 album
=> fix
($mp3->album || '?'),
67 tracknumber
=> fix
($mp3->track1 || '?'),
68 tracktotal
=> fix
($mp3->track2 || '?'),
69 genre
=> fix
($mp3->genre) || '?',
76 my $ogg=Ogg
::Vorbis
::Header
::PurePerl
->new($file);
77 $file = scalar fileparse
$file;
81 title
=> fix
($ogg->comment('TITLE') || '?'),
82 artist
=> fix
($ogg->comment('artist') || '?'),
83 year
=> fix
($ogg->comment('DATE') || '?'),
84 album
=> fix
($ogg->comment('ALBUM') || '?'),
85 tracknumber
=> fix
($ogg->comment('TRACKNUMBER') || '?'),
86 tracktotal
=> fix
($ogg->comment('TRACKTOTAL') || '?'),
87 genre
=> fix
($ogg->comment('GENRE')) || '?',
93 "$_[0]|".(stat $_[0])[9]
97 tie
my %cache, 'DB_File', $cache, O_RDWR
|O_CREAT
, 0644 unless $cache eq '';
98 memoize
'flacinfo', NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
99 memoize
'mp3info' , NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
100 memoize
'vorbisinfo' , NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
103 for my $file (@ARGV) {
105 $info = thaw flacinfo
$file if $file =~ /.flac$/i;
106 $info = thaw mp3info
$file if $file =~ /.mp3$/i;
107 $info = thaw vorbisinfo
$file if $file =~ /.og(?:g|a)$/i;
108 next unless defined $info;
109 my $basename = fileparse
$file, '.flac', '.mp3', '.ogg', '.oga';
110 $files{$basename} //= [];
111 push $files{$basename}, $info;
114 my $ht=HTML
::Template
::Compiled
->new(
115 default_escape
=> 'HTML',
117 $template eq '' ?
(scalarref
=> \
$default_template) : (filename
=> $template),
121 for (values %files) {
123 my %entry = (%{$versions[0]}, formats
=> []);
124 push $entry{formats
}, {format
=> $_->{format
}, file
=> $_->{file
}} for @versions;
128 $ht->param(files
=>[sort { $a->{title
} cmp $b->{title
} } @files], prefix
=> $prefix);
132 $default_template = <<'HTML';
135 <meta charset="utf-8">
136 <link rel="stylesheet" href="/music.css">
140 <tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
141 <tbody><tmpl_loop files>
142 <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>
152 App::MusicExpo - script which generates a HTML table of music tags
161 App::MusicExpo creates a HTML table from a list of songs.
163 The default template looks like:
165 | Title | Artist | Album | Genre | Track | Year | Type |
166 |---------+---------+-----------------+---------+-------+------+------|
167 | Cellule | Silence | L'autre endroit | Electro | 01/09 | 2005 | FLAC |
169 where the type is a download link. If you have multiple files with the same
170 basename (such as C<cellule.flac> and C<cellule.ogg>), they will be treated
171 as two versions of the same file, so a row will be created with two download
172 links, one for each format.
178 =item B<--template> I<template>
180 Path to the HTML::Template::Compiled template used for generating the music table. If '' (empty), uses the default format. Is empty by default.
182 =item B<--prefix> I<prefix>
184 Prefix for download links. Defaults to '/music/'.
186 =item B<--cache> I<filename>
188 Path to the cache file. Created if it does not exist. If '' (empty), disables caching. Is empty by default.
194 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
196 =head1 COPYRIGHT AND LICENSE
198 Copyright (C) 2013 by Marius Gavrilescu
200 This library is free software; you can redistribute it and/or modify
201 it under the same terms as Perl itself, either Perl version 5.14.2 or,
202 at your option, any later version of Perl 5 you may have available.
This page took 0.074709 seconds and 4 git commands to generate.