What movement helps you when you are trying to run out a batsman

Aug 17, 2008

I wrote a commandline downloader for emusic's EMX files. It requires Beautiful Soup and seems not to be obviously broken.

It does sane things as is but the behavior can be altered with a ~/.emxdownloader file, which should have lines of the form "optionname = optionvalue" (comments can begin with a "#", and actually anything unrecognized is ignored). Options are either boolean (which can have a value of "t", "f", "true", or "false", case insensitively), or string options, which can be any string. The current options are "replace_underscores", "replace_apostrophe_identity", and "get_art", which are all boolean, the first replacing '_' with ' ', the second replacing "'" with an apostrophe, and the third either downloading or not downloading album art, and "dlfmt", "dlfmt_multidisc", and "dldir", which are string options. "dldir" is the directory relative to which files will be downloaded and should be absolute lest undesired things happen; "dlfmt" and "dlfmt_multidisc" are used in conjunction with "dldir" to determine the final download location. "dlfmt_multidisc" is just like "dlfmt", except it will be used (if it is defined, which it needn't be) if the track being downloaded is part of a multi-disc set. Each of "dlfmt" and "dlfmt_multidisc" can have any of the following format codes embedded within it:

  • "%(a)" expands to the artist.
  • "%(A)" expands to the album name.
  • "%(n)" expands to the track number.
  • "%(e)" expands to the file's extension. (NB: if the calculated download location does not end with the file's extension, it will be added anyway.)
  • "%(t)" expands to the track title.
  • "%(l)" expands to the label (which might not be what you think, since it depends on who the real label's gotten to work with emusic for them; eg, stuff downloaded from Clean Feed will have a label field of "Clean Feed / IODA").
  • "%(d)" expands to the disc number.
  • "%(D)" expands to the total number of discs.

So, for instance, my dotfile looks like this:

dldir = /home/wolfson/mp3/new
dlfmt = %(a)/%(A)/%(a) - %(A) - %(n) - %(t)
dlfmt_multidisc = %(a)/%(A): %(d)/%(a) - %(A): %(d) - %(n) - %(t)
get_art = false

Note that I haven't ended the download format options with "%(e)" since the extension is added automatically. It is an error to include anything of the form "%(...)" other than what's listed above. All of the boolean options default to being true, dldir defaults to being whatever directory the script is run in, and dlfmt defaults to being what it is above (except the forward slashes will be replaced with whatever the local directory separation character is, though I should say I've only actually used this on linux), and dlfmt_multidisc defaults to being undefined.  (When dlfmt_multidisc is undefined, multidisc sets are treated the same as single discs.)

While it would be possible to make these things also be configurable from the commandline, I haven't done that, because it seems unlikely that you'd want to download this album to some other location, say.

Comments

on 2008-08-19 7:58:54.0, Tom commented:

Neat! And another good reminder that I should really learn Python.

[permalink]