|
10. Tips and Tricks
Making your own template
Making your own template is not too difficult. Two templates are
provided already. You might want to read up on the XSLT specification,
and you may want to peek into the generate.command script which is in
the CCTunes package.
If you need any help, asking will never hurt. I don't always have time
to answer everything, but you may be lucky. If you feel like giving
back the template once it's finished that would be nice. If you want
to link to me for giving inspirational credit, that would be nice too.
Combining templates
At the moment there are two templates. One for making a list-like
html page, and one for making a "peephole" view of the library in
one big html page. These two approaches can be combined by using
the same destination folder for outputting.
Using ImageMagic or GraphicConverter
If you are dissatisfied with the quality of the small images in the
peephole view, like I am, you can choose to use ImageMagick to
convert the images from higher size to lower size.
You will need to install it using fink or compile
it yourself, both should be easy and with a simple set of commands on the prompt
you convert all images like this:
Code listing 10.1: Generating thumbnails with ImageMagick convert |
find outputdir -name *-high -type f -exec convert -resize 60x60 {} {}-low.png \;
|
If you have a utility like GraphicConverter, which came for free with my laptop,
you can easily generate 60 by 60 thumbnails from the images by using the batch
mode to set the Max Size.
Using perl to get the images out of the mp3 files
Warning: This section is outdated with respect to CCTunes. It is here for
documentation purposes only.
|
It used to be so that the images were extracted from the MP3
files using perl libraries and a little perl script. This is
how it was done.
A link that got me on the way was on the ever interesting
macosxhints website,
http://www.macosxhints.com/article.php?story=20030429003250559,
in which one of the comments describes almost perfectly what needs to be
done. Almost, but for the fact on how to get to open a file based on the
url. Of course, this is not hard to do, using some parsing, and I have
my "Perl in a Nutshell" book on my desktop, but getting used to this perl
thing I thought there must be a module already out there that does this
for me. Now, that's the URI::URL module we've installed, and it was
mentioned in the book.
There we have our perl script, which takes as argument a unix file path
and a filename to write the png file to. If this script does not find
the corresponding tag, it just creates a link to a nopic.png file instead
of the destination file, so that we can put in a nice icon when the image
is missing in the mp3.
Code listing 10.2: The getPicture script gets the image from the mp3 file |
#!/usr/bin/perl
no strict 'refs';
use Getopt::Long;
use IO::File;
use MP3::Info;
use URI::URL;
$url1 = new URI::URL shift;
$unixpath = $url1->unix_path();
$e = $ARGV[0];
if ( -e $e || -l $e ) {
system("/bin/rm " . $e);
}
if (my $mp3tag_id3v2 = get_mp3tag($unixpath, 2, 1)) {
my $tag = "PIC";
my $result = $mp3tag_id3v2->{$tag};
$result =~ s/^(.....).//;
if (length($result) > 0)
{
open $f, "> $e";
print $f $result;
}
else
{
system("/bin/ln -s ./nopic.png " . $e);
}
}
else
{
system("/bin/ln -s ./nopic.png " . $e);
}
|
To invoke this for the set of MP3's that the library existed of, a little hack
was needed which added a little comment in the XML file so that when grepping
for the getPicture command a bash script was generated that used the perl script
to extract all the images.
I have understood that a Microsoft implementation of the XSLT parsing implements
something like callbacks, in which you can call a script from within your
XSL file. That's a good idea, nice, but since it isn't in the XSLT specification
it is not very compatible to depend upon it. But if you do, you might want
to check that out. The approach described did work too, however.
|