1ad37688f7af720bfd2e73c7efb8c6cf2cb8b0e4
1 package App
::MusicExpo
0.001;
6 use Audio
::FLAC
::Header qw
//;
7 use HTML
::Template
::Compiled qw
//;
8 use Memoize qw
/memoize/;
12 use File
::Basename qw
/fileparse/;
13 use Fcntl qw
/O_RDWR O_CREAT/;
15 use Storable qw
/thaw freeze/;
17 ##################################################
21 our $prefix='/music/';
26 "template=s" => \
$template,
27 "prefix=s" => \
$prefix,
39 my $flac=Audio
::FLAC
::Header
->new($file);
40 $file = $prefix . scalar fileparse
$file;
44 title
=> fix
($flac->tags('TITLE') // '?'),
45 artist
=> fix
($flac->tags('ARTIST') // '?'),
46 year
=> fix
($flac->tags('DATE') // '?'),
47 album
=> fix
($flac->tags('ALBUM') // '?'),
48 tracknumber
=> fix
($flac->tags('TRACKNUMBER') // '?'),
49 tracktotal
=> fix
($flac->tags('TRACKTOTAL') // '?'),
50 genre
=> fix
($flac->tags('GENRE') // '?'),
57 my $mp3=MP3
::Tag
->new($file);
58 $file = $prefix . scalar fileparse
$file;
62 title
=> fix
($mp3->title || '?'),
63 artist
=> fix
($mp3->artist || '?'),
64 year
=> fix
($mp3->year || '?'),
65 album
=> fix
($mp3->album || '?'),
66 tracknumber
=> fix
($mp3->track1 || '?'),
67 tracktotal
=> fix
($mp3->track2 || '?'),
68 genre
=> fix
($mp3->genre) || '?',
74 "$_[0]|".(stat $_[0])[9]
78 tie
my %cache, 'DB_File', $cache, O_RDWR
|O_CREAT
, 0644 unless $cache eq '';
79 memoize
'flacinfo', NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
80 memoize
'mp3info' , NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
83 for my $file (@ARGV) {
84 push @files, thaw flacinfo
$file if $file =~ /.flac$/i;
85 push @files, thaw mp3info
$file if $file =~ /.mp3$/i;
88 my $ht=HTML
::Template
::Compiled
->new(
89 default_escape
=> 'HTML',
90 $template eq '' ?
(scalarref
=> \
$default_template) : (filename
=> $template),
92 $ht->param(files
=>[sort { $a->{title
} cmp $b->{title
} } @files]);
96 $default_template = <<'HTML';
99 <meta charset="utf-8">
100 <link rel="stylesheet" href="/music.css">
104 <tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
105 <tbody><tmpl_loop files>
106 <tr><td><a href="<tmpl_var ESCAPE=URL path>"><tmpl_var title></a><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_var format></tmpl_loop>
116 App::MusicExpo - script which generates a HTML table of music tags
125 App::MusicExpo creates a HTML table from a list of songs.
127 The default template looks like:
129 | Title | Artist | Album | Genre | Track | Year | Type |
130 |---------+---------+-----------------+---------+-------+------+------|
131 | Cellule | Silence | L'autre endroit | Electro | 01/09 | 2005 | FLAC |
133 where the title is a download link.
139 =item B<--template> I<template>
141 Path to the HTML::Template::Compiled template used for generating the music table. If '' (empty), uses the default format. Is empty by default.
143 =item B<--prefix> I<prefix>
145 Prefix for download links. Defaults to '/music/'.
147 =item B<--cache> I<filename>
149 Path to the cache file. Created if it does not exist. If '' (empty), disables caching. Is empty by default.
155 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
157 =head1 COPYRIGHT AND LICENSE
159 Copyright (C) 2013 by Marius Gavrilescu
161 This library is free software; you can redistribute it and/or modify
162 it under the same terms as Perl itself, either Perl version 5.14.2 or,
163 at your option, any later version of Perl 5 you may have available.
This page took 0.031777 seconds and 3 git commands to generate.