Tagged as LISP
Written on 2009-08-25 20:04:17
I'm hoping to get back on track with my blogging (and following other folks blogs) in the next few days. I wanted to post this code real quick though before I forget about it. I've had a lot of fun playing with lisp lately and have written...4 silly, small scripts in the last week.
- The first goes through 12 months of CSV call logs from AT&T to find out the 5 people I spend the most minutes talking to.
- The second recurses through a directory running an external program to find the bpm on each one and logging the difference from the current BPM in id3 tag to a file. It's 90% done, I just have to clean up some of the output parsing from the external process. Very rarely, my cl-ppcre regex doesn't match. Silly corner cases.
- The third takes a directory of 20 or fewer *.ogg files, maps them to keystrokes and I'm working on a simple loop so that they play in a spawned "ogg123" whenever I press said keys. The main hold-up at present is that (read-char) blocks while waiting for a #\Newline and (read-char-no-hang) gave me some other error I forgot.
More on all that later. Some M3U files (playlists) I had laying around weren't importing into a different mp3 player. The reason? They weren't using absolute pathnames. My solution was hackish but I coded it, fixed them and moved on with my life in about 3-5 minutes. Hard to argue with that. And the code:
(defun fix-m3u (path)
(let ((new-m3u (make-array 16 :adjustable t :fill-pointer 0)))
(with-open-file (in path)
(loop for line = (read-line in nil) while line do
(let ((abspath (concatenate 'string "/home/redline/music/" line)))
(vector-push-extend abspath new-m3u))))
(with-open-file (out path :direction :output
(loop for line across new-m3u do
(format out "~a~%" line)))))