Category Archives: Software

Organising my music collection with find and ffmpeg

Since I bought a Synology NAS I’ve been spending time sorting out my music library. Let’s say it’s been a very relaxing hobby as I get to listen to music I hadn’t listened to in years, and it brings back great memories and also brings me to research about “what happened to that indie artist whose protected demos I downloaded from MySpace using Firebug in 2007″ and I end up in a YouTube hole looking for remixes and live versions of my favourite tracks, so that’s fun.

People always ask me why do I bother keeping an MP3 collection, when “I could just use a service like Spotify”. The answer is: I like indie music and obscure music and bootlegs and all sorts of things that the record label won’t put on Spotify, mostly because often the record label has either disappeared or there isn’t even a record label to start with (as is the case with unsigned artists). So curating this sort of collection is a very interesting hobby–sometimes I feel like I own the last copies of the music of some artists as their myspace pages have disappeared, etc.

But there are things I do not really enjoy doing, namely repetitive stuff.

So whenever I can automate something I will do. The terminal is really great for that–and this is a bit of an exercise to improve my bash skills too! 😎

Task 1: remove unneeded files from a folder and its subdirectories

Sometimes you download a bunch of music files and they’re organised in directories. And maybe there’s a lot of .url or .rtf or .txt files you don’t care about. You could go and delete them manually, or you could just use find to remove them in just one command:

For example, to delete all .m3u playlists in a folder and its subdirectories:

find . -iname *.m3u -delete

You could just run it without the -delete switch to make sure you’re not deleting too much (there is NO going back with this! no recycle bin!)

find . -iname *.m3u

Task 2: Rename cover [whatever].jpg to folder.jpg

Apparently these Synology devices will use folder.jpg to display the cover art of each album, assuming each album is “a folder” and there is such a named imaged file in the folder. But these files are sometimes not named like that; they might be cover.jpg or random-string-of-letters-and-numbers.jpg. Again, you could rename them manually, or you press the turbo pedal and go megafaster with this:

find . -iname *.jpg -execdir mv {} folder.jpg \;

Warning: this is somehow a bit too “fire and forget”, and might fail if there are already existing folder.jpg files or just more than one file in the directory. I haven’t tested those scenarios, but what you can do before running the actual renamer is to use find to list the files that match the .jpg pattern. If you find one per folder, then you’re good to go:

find -iname *.jpg

Probably an over-the-top improvement would use ImageMagick‘s convert to list the size of the files and just rename to folder.jpg the largest one, or whatever, but I am not so obsessed with perfection, and besides I’m only running this on one artist’s folder. Also: maybe if you’re having so much logic, perhaps it’s better if you write that logic in an intelligible sort of script such as Python or Node.js. Your future self will thank you forever, unlike if you write Bash code full of back ticks and other mysterious powertricks you find in Stack Overflow and painfully assemble together, only to forget immediately.

Task 3: convert the files to a format you actually like

I’ve also got music files in formats I don’t like. I’m a bit of a savage and don’t care so much about FLAC or sound purity (here, I said that), because I don’t actually listen to music in high end equipment, and besides I used to listen to music in tapes that had been used and reused so many times you could still listen to the previous three or four recordings, so even the crappiest digital encoding is often like super state of the art for my ears.

I tend to just convert FLAC stuff to 320k MP3, but this also works for converting those horrid M4A files to MP3, and OGG to MP3, or WAV to MP3 (yeah, some artists think that WAV is a good distribution format!).

For example, this will convert all *.wav files in a directory to 320K MP3 while keeping the metadata. You’ll need ffmpeg installed (you can install it on a Mac with brew install ffmpeg).

(for FILE in *.wav; do ffmpeg -i "$FILE" -f mp3 -ab 320000 -map_metadata 0 -id3v2_version 3 "`basename "$FILE" .wav`.mp3" || break; done)

Replace .wav with the extension you hate the most: e.g. .m4a, and for grittiest results and even more savage souls than mine, you can drop the file size by reducing the bit rate to 128000 or even worse–use 64000 for a very convincing “Using an MP3 player from the 90s with 64 Megs of RAM with very shitty earphones” feeling.

It just occurred to me that maybe you could also use this one to convert a bunch of videos from talks into “podcasts” (by stripping out the video and just keeping the audio), but I haven’t tried that.

If you have cool music power tricks to process audio files do send them my way on the comments section–I’d love to add them to my arsenal :-)

Solving the “multiple MacVim instances” confusion

I somehow started to experience this confusing situation where I would have two instances of MacVim open, so I was able to Command-Tab between them, and it was really annoying because if I wanted to switch between different windows of MacVim I had to locate which of the instances contained the window I wanted to edit files on. See where am I getting? No? I understand, it was very confusing.

However I found what had happened: I had two versions of MacVim installed.

So when I opened something with the command line mvim shortcut, one of the instances would be executed. And when I opened some file with “open with MacVim” the other instance would be executed. Chaos ensued!

The solution was to delete the in the /Applications folder, and uninstall it from Homebrew:

brew uninstall macvim

and install it again:

brew install macvim

Now I’m back to just one MacVim instance. Yay!

Getting logs of your Firefox OS device

Often you want to output debugging data from your app, but the space on the screen is limited! And perhaps you don’t want to connect to the app with WebIDE and launch the debugger and etc, etc…

One solution is to use any of the console. functions in your code. They will be sent to the device’s log. For example:

console.log('hello friends!');

and you can also use console.error,, etc.

Then, if you have the adb utility installed, you can get instant access to those logs when your device is connected to your computer with USB.
Continue reading

Front-end mDNS: announcing and finding network services with JavaScript

Multicast DNS (or mDNS) lets you announce a service you’re offering in the network you’re connected to, and other devices can find (discover) it. For example, you could announce that your computer is running an FTP service. It’s the same thing that Apple does with its Bonjour protocol and that’s how you can find printers without knowing their IP address: they broadcast their existence, and your computer picks it up automatically for you.

Services have to be registered with a domain ending in .local. E.g. _ssh._tcp.local. The Wikipedia page has some background on why.

However, the title of this post has “front-end” on it, and that’s because I wanted to talk about dns-sd.js, a library that lets you both register and discover services in the network. It’s all written in JavaScript so it can run on a browser environment, in this case Firefox OS.
Continue reading

Superturbocharging Firefox OS app development with node-firefox

Well, that’s funny–I finish writing a few modules for (potentially) node-firefox and then on the same day I discover the recording for my FOSDEM talk on node-firefox is online!

It’s probably not the best recording you’ve ever seen, as it is not recording the output of my laptop, but here are the slides too if you want to see my fabulously curated GIFs (and you know you want to). Here’s also the source of the slides, and the article for Mozilla Hacks that presents node-firefox and which might probably help you more than watching the video with the slides.

If you’re interested in watching the other Mozilla talks at FOSDEM they’re here.