2014-07-22

Download audio playlists with youtube-dl search function

I'm a nut for happy, uplifting, melodic, liquid drum & bass. While a thankful user of Clementine music player, which provides me a with a streaming fix of new tracks from Digitally Imported online radio, I do keep my collections traditionally on-disk.

From time to time, I get a list of new tracks to consider adding to personal favorites. Sometimes they are already in mp3 (or appropriate) form, sometimes it is a YouTube playlist. Often, though, they come in textual format listed as one track per line as a result of a little cd /path/to/liquid/dnb && find | pastebinit | xclip or awk filtering from Last.fm's exported TSV.

E.g. I get this:
Feint    Vision Driver
Fred V & Grafix    Games People Play
Temple Cloud    One Big Family (Hybrid Minds Remix)
Gradon    Trust
Hazem Beltagui    August (Rimshox Remix)
High Contrast    All There Is (ft. Liane Carroll)
High Contrast    Almost Human (ft. Clare Maguire)
High Contrast    Emotional Vampire
High Contrast    Fearful Symmetry
High Contrast    If We Ever
High Contrast    Pink Flamingos
High Contrast    The Road Goes On Forever
Keeno    Nocturne
Only a much longer list.

(If I get a playlist instead, something like this could work.)

Now, my old manual routine was to go through the list line by line, input the query into Google search, visit the first (or appropriate) YouTube link, listen to the track, and if likable, download a higher quality of it through BitTorrent if available, or through Offliberty if not. After five or so minutes, repeat with the next line. Pretty damn tedious!

But then, 192 kbps bitrate at which YouTube streams audio of high-quality uploads is perfectly enough for everyone.

And in this new light, with the help of a wonderful open-source project, youtube-dl, one like myself can download most of those tracks instantly with a single terminal command:

youtube-dl --extract-audio \
           --default-search="ytsearch2:" \
           --batch-file keywords.list

What this does is prepend "ytsearch2:" to each line of keywords.list file, as per youtube-dl extractor descriptions, then downloads the result videos and converts them all to audio. The gist of it is that you don't need to know specific video URLs because they are discovered through the YouTube API which the method uses. Not all tracks are downloaded this way because some channels disallow discovery through the API, but most are, and the time spent on copy-pasting queries around and waiting for the related browser plugin to load is reduced to a minimum.

If you know of any good, melodic DnB (no morbid dark stuff), particularly not unlike the one in the above list, please send it this way!