]>
iEval git - app-musicexpo.git/blob - lib/App/MusicExpo.pm
1 package App
::MusicExpo
;
6 our $VERSION = '0.003003';
8 use Audio
::FLAC
::Header qw
//;
9 use HTML
::Template
::Compiled qw
//;
10 use Memoize qw
/memoize/;
12 use Ogg
::Vorbis
::Header
::PurePerl
;
13 use MP4
::Info qw
/get_mp4tag get_mp4info/;
16 use File
::Basename qw
/fileparse/;
17 use Fcntl qw
/O_RDWR O_CREAT/;
20 use Storable qw
/thaw freeze/;
22 ##################################################
26 our $prefix='/music/';
31 "template:s" => \
$template,
32 "prefix:s" => \
$prefix,
45 my $flac=Audio
::FLAC
::Header
->new($file);
46 $file = scalar fileparse
$file;
50 title
=> fix
($flac->tags('TITLE') // '?'),
51 artist
=> fix
($flac->tags('ARTIST') // '?'),
52 year
=> fix
($flac->tags('DATE') // '?'),
53 album
=> fix
($flac->tags('ALBUM') // '?'),
54 tracknumber
=> fix
($flac->tags('TRACKNUMBER') // '?'),
55 tracktotal
=> fix
($flac->tags('TRACKTOTAL') // '?'),
56 genre
=> fix
($flac->tags('GENRE') // '?'),
63 my $mp3=MP3
::Tag
->new($file);
64 $file = scalar fileparse
$file;
68 title
=> fix
($mp3->title || '?'),
69 artist
=> fix
($mp3->artist || '?'),
70 year
=> fix
($mp3->year || '?'),
71 album
=> fix
($mp3->album || '?'),
72 tracknumber
=> fix
($mp3->track1 || '?'),
73 tracktotal
=> fix
($mp3->track2 || '?'),
74 genre
=> fix
($mp3->genre) || '?',
81 my $ogg=Ogg
::Vorbis
::Header
::PurePerl
->new($file);
82 $file = scalar fileparse
$file;
86 title
=> fix
($ogg->comment('TITLE') || '?'),
87 artist
=> fix
($ogg->comment('artist') || '?'),
88 year
=> fix
($ogg->comment('DATE') || '?'),
89 album
=> fix
($ogg->comment('ALBUM') || '?'),
90 tracknumber
=> fix
($ogg->comment('TRACKNUMBER') || '?'),
91 tracktotal
=> fix
($ogg->comment('TRACKTOTAL') || '?'),
92 genre
=> fix
($ogg->comment('GENRE')) || '?',
99 return 'AAC' if $encoding eq 'mp4a';
100 return 'ALAC' if $encoding eq 'alac';
106 my %tag = %{get_mp4tag
$file};
107 my %info = %{get_mp4info
$file};
108 $file = scalar fileparse
$file;
111 format
=> mp4_format
$info{ENCODING
},
112 title
=> $tag{TITLE
} || '?',
113 artist
=> $tag{ARTIST
} || '?',
114 year
=> $tag{YEAR
} || '?',
115 album
=> $tag{ALBUM
} || '?',
116 tracknumber
=> $tag{TRACKNUM
} || '?',
117 tracktotal
=> ($tag{TRKN
} ?
$tag{TRKN
}->[1] : undef) || '?',
118 genre
=> $tag{GENRE
} || '?',
124 "$_[0]|".(stat $_[0])[9]
129 tie
my %cache, 'DB_File', $cache, O_RDWR
|O_CREAT
, 0644;
130 memoize
$_, NORMALIZER
=> \
&normalizer
, LIST_CACHE
=> 'MERGE', SCALAR_CACHE
=> [HASH
=> \
%cache] for qw
/flacinfo mp3info vorbisinfo mp4info/;
134 for my $file (@ARGV) {
136 $info = thaw flacinfo
$file if $file =~ /\.flac$/i;
137 $info = thaw mp3info
$file if $file =~ /\.mp3$/i;
138 $info = thaw vorbisinfo
$file if $file =~ /\.og(?:g|a)$/i;
139 $info = thaw mp4info
$file if $file =~ /\.mp4|\.aac|\.m4a$/i;
140 next unless defined $info;
141 my $basename = fileparse
$file, '.flac', '.mp3', '.ogg', '.oga', '.mp4', '.aac', '.m4a';
142 $files{$basename} //= [];
143 push $files{$basename}, $info;
146 my $ht=HTML
::Template
::Compiled
->new(
147 default_escape
=> 'HTML',
149 $template eq '' ?
(scalarref
=> \
$default_template) : (filename
=> $template),
153 for (values %files) {
155 my %entry = (%{$versions[0]}, formats
=> []);
156 push $entry{formats
}, {format
=> $_->{format
}, file
=> $_->{file
}} for @versions;
160 my $json = JSON
::MaybeXS
->new(canonical
=> 1)->encode({files
=> \
@files, prefix
=> $prefix});
163 $ht->param(files
=>[sort { $a->{title
} cmp $b->{title
} } @files], prefix
=> $prefix, json
=> $json);
167 $default_template = <<'HTML';
170 <meta charset="utf-8">
171 <link rel="stylesheet" href="/music.css">
175 <tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
176 <tbody><tmpl_loop files>
177 <tr><td><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>
180 <pre id="json" style="display: none"><tmpl_var ESCAPE=0 json></pre>
191 App::MusicExpo - script which generates a HTML table of music tags
200 App::MusicExpo creates a HTML table from a list of songs.
202 The default template looks like:
204 | Title | Artist | Album | Genre | Track | Year | Type |
205 |---------+---------+-----------------+---------+-------+------+------|
206 | Cellule | Silence | L'autre endroit | Electro | 01/09 | 2005 | FLAC |
208 where the type is a download link. If you have multiple files with the same
209 basename (such as C<cellule.flac> and C<cellule.ogg>), they will be treated
210 as two versions of the same file, so a row will be created with two download
211 links, one for each format.
217 =item B<--template> I<template>
219 Path to the HTML::Template::Compiled template used for generating the music table. If '' (empty), uses the default format. Is empty by default.
221 =item B<--prefix> I<prefix>
223 Prefix for download links. Defaults to '/music/'.
225 =item B<--cache> I<filename>
227 Path to the cache file. Created if it does not exist. If '' (empty), disables caching. Is empty by default.
233 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
235 =head1 COPYRIGHT AND LICENSE
237 Copyright (C) 2013-2014 by Marius Gavrilescu
239 This library is free software; you can redistribute it and/or modify
240 it under the same terms as Perl itself, either Perl version 5.14.2 or,
241 at your option, any later version of Perl 5 you may have available.
This page took 0.076196 seconds and 5 git commands to generate.