]>
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
::Entities qw
/encode_entities/;
8 use HTML
::Template
::Compiled qw
//;
9 use Memoize qw
/memoize/;
11 use URI
::Escape qw
/uri_escape/;
14 use File
::Basename qw
/fileparse/;
15 use Fcntl qw
/O_RDWR O_CREAT/;
17 use Storable qw
/thaw freeze/;
19 ##################################################
23 our $prefix='/music/';
24 our $cache='cache.db';
29 "template=s" => \
$template,
30 "prefix=s" => \
$prefix,
32 "caching!" => \
$caching,
38 encode_entities
($_[0])
43 my $flac=Audio
::FLAC
::Header
->new($file);
44 $file = $prefix . uri_escape
scalar fileparse
$file;
48 title
=> fix
($flac->tags('TITLE') // '?'),
49 artist
=> fix
($flac->tags('ARTIST') // '?'),
50 year
=> fix
($flac->tags('DATE') // '?'),
51 album
=> fix
($flac->tags('ALBUM') // '?'),
52 tracknumber
=> fix
($flac->tags('TRACKNUMBER') // '?'),
53 tracktotal
=> fix
($flac->tags('TRACKTOTAL') // '?'),
54 genre
=> fix
($flac->tags('GENRE') // '?'),
61 my $mp3=MP3
::Tag
->new($file);
62 $file = $prefix . uri_escape
scalar fileparse
$file;
66 title
=> fix
($mp3->title || '?'),
67 artist
=> fix
($mp3->artist || '?'),
68 year
=> fix
($mp3->year || '?'),
69 album
=> fix
($mp3->album || '?'),
70 tracknumber
=> fix
($mp3->track1 || '?'),
71 tracktotal
=> fix
($mp3->track2 || '?'),
72 genre
=> fix
($mp3->genre) || '?',
78 "$_[0]|".(stat $_[0])[9]
82 tie
my %cache, 'DB_File', $cache, O_RDWR
|O_CREAT
, 0644 if $caching;
83 memoize
'flacinfo', NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] if $caching;
84 memoize
'mp3info' , NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] if $caching;
87 for my $file (@ARGV) {
88 push @files, thaw flacinfo
$file if $file =~ /.flac$/i;
89 push @files, thaw mp3info
$file if $file =~ /.mp3$/i;
92 my $ht=HTML
::Template
::Compiled
->new( $template eq '' ?
(scalarref
=> \
$default_template) : (filename
=> $template));
93 $ht->param(files
=>[sort { $a->{title
} cmp $b->{title
} } @files]);
97 $default_template = <<'HTML';
100 <meta charset="utf-8">
101 <link rel="stylesheet" href="/music.css">
105 <tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
106 <tbody><tmpl_loop files>
107 <tr><td><a href="<tmpl_var 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>
117 App::MusicExpo - script which generates a HTML table of music tags
126 App::MusicExpo creates a HTML table from a list of songs.
128 The default template looks like:
130 | Title | Artist | Album | Genre | Track | Year | Type |
131 |---------+---------+-----------------+---------+-------+------+------|
132 | Cellule | Silence | L'autre endroit | Electro | 01/09 | 2005 | FLAC |
134 where the title is a download link.
140 =item B<--template> I<template>
142 Path to the HTML::Template::Compiled template used for generating the music table. If '' (empty), uses the default format. Is empty by default.
144 =item B<--prefix> I<prefix>
146 Prefix for download links. Defaults to '/music/'.
148 =item B<--cache> I<filename>
150 Path to the cache file. Created if it does not exist. Defaults to 'cache.db'
152 =item B<--caching>, B<--no-caching>
154 Enables or disables caching. Defaults to B<--caching>
160 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
162 =head1 COPYRIGHT AND LICENSE
164 Copyright (C) 2013 by Marius Gavrilescu
166 This library is free software; you can redistribute it and/or modify
167 it under the same terms as Perl itself, either Perl version 5.14.2 or,
168 at your option, any later version of Perl 5 you may have available.
This page took 0.061138 seconds and 4 git commands to generate.