]>
iEval git - app-musicexpo.git/blob - lib/App/MusicExpo.pm
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,
38 my $flac=Audio
::FLAC
::Header
->new($file);
39 $file = $prefix . scalar fileparse
$file;
43 title
=> fix
($flac->tags('TITLE') // '?'),
44 artist
=> fix
($flac->tags('ARTIST') // '?'),
45 year
=> fix
($flac->tags('DATE') // '?'),
46 album
=> fix
($flac->tags('ALBUM') // '?'),
47 tracknumber
=> fix
($flac->tags('TRACKNUMBER') // '?'),
48 tracktotal
=> fix
($flac->tags('TRACKTOTAL') // '?'),
49 genre
=> fix
($flac->tags('GENRE') // '?'),
56 my $mp3=MP3
::Tag
->new($file);
57 $file = $prefix . scalar fileparse
$file;
61 title
=> fix
($mp3->title || '?'),
62 artist
=> fix
($mp3->artist || '?'),
63 year
=> fix
($mp3->year || '?'),
64 album
=> fix
($mp3->album || '?'),
65 tracknumber
=> fix
($mp3->track1 || '?'),
66 tracktotal
=> fix
($mp3->track2 || '?'),
67 genre
=> fix
($mp3->genre) || '?',
73 "$_[0]|".(stat $_[0])[9]
77 tie
my %cache, 'DB_File', $cache, O_RDWR
|O_CREAT
, 0644 unless $cache eq '';
78 memoize
'flacinfo', NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
79 memoize
'mp3info' , NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] unless $cache eq '';
82 for my $file (@ARGV) {
83 push @files, thaw flacinfo
$file if $file =~ /.flac$/i;
84 push @files, thaw mp3info
$file if $file =~ /.mp3$/i;
87 my $ht=HTML
::Template
::Compiled
->new(
88 default_escape
=> 'HTML',
89 $template eq '' ?
(scalarref
=> \
$default_template) : (filename
=> $template),
91 $ht->param(files
=>[sort { $a->{title
} cmp $b->{title
} } @files]);
95 $default_template = <<'HTML';
98 <meta charset="utf-8">
99 <link rel="stylesheet" href="/music.css">
103 <tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
104 <tbody><tmpl_loop files>
105 <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>
115 App::MusicExpo - script which generates a HTML table of music tags
124 App::MusicExpo creates a HTML table from a list of songs.
126 The default template looks like:
128 | Title | Artist | Album | Genre | Track | Year | Type |
129 |---------+---------+-----------------+---------+-------+------+------|
130 | Cellule | Silence | L'autre endroit | Electro | 01/09 | 2005 | FLAC |
132 where the title is a download link.
138 =item B<--template> I<template>
140 Path to the HTML::Template::Compiled template used for generating the music table. If '' (empty), uses the default format. Is empty by default.
142 =item B<--prefix> I<prefix>
144 Prefix for download links. Defaults to '/music/'.
146 =item B<--cache> I<filename>
148 Path to the cache file. Created if it does not exist. If '' (empty), disables caching. Is empty by default.
154 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
156 =head1 COPYRIGHT AND LICENSE
158 Copyright (C) 2013 by Marius Gavrilescu
160 This library is free software; you can redistribute it and/or modify
161 it under the same terms as Perl itself, either Perl version 5.14.2 or,
162 at your option, any later version of Perl 5 you may have available.
This page took 0.064777 seconds and 5 git commands to generate.