January 2011 Archives

How Perl helped me with my mythmas presents, part 2

Another gift I prepare for the annual winter gift-giving season [0] is a mixtape [1] containing my favorite songs of the past year. As you might know, I still buy (most) of my music, and I buy it on vinyl. So once I year I haul my second turntable into our office (where my other turntable and mixer lives), set up an impromptu studio, and spend a few hours preparing the mixtape. You can view my past mixtapes here (if you can read German..).

I also create a nice cover and write up some liner notes, maybe fiddle a bit with the raw recording (using audacity) and then burn some CDs. As my mixtape is a continuous stream of ~75 minutes of music, I want to burn the CD without gaps between tracks, i.e. using DAO (Disk At Once). My preferred tool used to be gcdmaster, which lets me load one big 80 minutes wav file, set some track marks and burn the CD.

To set track marks, you have to listen to the audio, because it is impossible [2] to see the track bounderies in the wave form rendering. Unfortunately, gcdmaster doesn't seem to work with recent linux audio interfaces (or I wasn't able to set it up). So I used audacity to set the track marks using the "label track" feature and export those labels.

Now I needed to convert those time marks into the format used by gcdmaster (or cdrdao, which gcdmaster is using). This is where Perl comes to the rescue:

How Perl helped me with my mythmas presents, part 1

For the annual winter gift-giving season [0], I usually prepare a printout of nice pictures I took during the past year for the grandparents of my kids and other relatives. This involves going through 2839 photos [1] and filtering out the 10 to 30 pictures a given relative might care most about (there is some overlap, eg. the birthday of one of my kids, but not that much).

So the task is:

  • go through a lot of photos quickly
  • select/tag some with different criteria
  • export the selected photos.

I once wrote a thing called fotagger, but currently my SDL is broken and I wasn't in the mood to fix it. So I took a closer look at the tool I'm usually using to view pictures: qiv.

qiv "is a very small and pretty fast gdk/Imlib image viewer" [2]. I knew you can select and delete pictures using a and d, which copies the current picture into .qiv-select and .qiv-trash, respectively. But that's not enough for my needs, because I want some pictures to go to my mother, and different ones for my father, etc.

Further reading of the man-page revealed a workable solution based on true Unix mindset: If you hit any number (or ^some_string), qiv will run a program called qiv-command, passing the number you pressed (or 'some_string') and the filename of the picture you're currently watching to said program.

But: qiv comes without qiv-command. It is up to you, the user, to implement this program, using whatever language you like and implementing whatever features you need. Fucking Brilliant!

So I now have this in my $PATH:

#!/usr/bin/perl
use strict;
use warnings;
use 5.010;

use Path::Class;
use File::Copy;

my ($action, $in_file_name) = @ARGV;
my $out = Path::Class::dir('/home/domm/media/fotos/select',$action);
die "no such dir $out" unless -d $out;

my $in = Path::Class::dir->file($in_file_name);
$in_file_name =~ s{/+}{_}g;
copy($in->stringify,$out->file($in_file_name)->stringify);

I just have to remember which relative gets what number, and now just have to press the according number to have the image I'm currently watching copied to a convenient location with a convenient filename [3].

So, a big THANKS to whoever though of providing this very easy to extend API. And of course another THANKS to all people working on Perl etc, which makes it absurdly easy for me to cobble something like the above together.


0: Even though I'm an atheist I usually say 'Christmas', but I sort of like mythmas, a funny term a search for alternative names for the annual winter gift-giving season suggested.
1: tree -F ~/media/fotos/2010/2010* | grep \* | wc -l
2: qiv website.
3: My pictures live in something like 2010/20100501_island/img_NNNNN.jpg. After pressing eg 3 this image would be found in select/3/20100501_island_img_NNNNN.jpg

About domm

user-pic Just in case you like to know, I'm currently full-time father of 2 kids, half-time Perl hacker, sort-of DJ, bicyclist, no longer dreadlocked and more than 34 years old but too lazy to update my profile once a year. I'm also head of Vienna.pm, no longer maintainer of the CPANTS project, member of the TPF Grants Commitee and the YAPC Europe Foundation. I've got stuff on CPAN, held various talks and organise the Austrian Perl Workshops and YAPC::Europe 2007.