Batch Download Tracks from YouTube Music Library

The YouTube Music Library is a good resource of free music. But when quickly trying to find a suitable track, I was slightly annoyed that the YouTube Music Library doesn’t allow you to scrub through the track. This forces me to listen to the whole intro. I wrote a small script that batch downloads all track on the current page. This way you can easily listen to the tracks in your favorite media player and scrub as much as you like 🙂

// Anonymous "self-invoking" function
(function() {
    // Load the script
    var script = document.createElement("SCRIPT");
    script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js';
    script.type = 'text/javascript';
    document.getElementsByTagName("head")[0].appendChild(script);

    // Poll for jQuery to come into existance
    var checkReady = function(callback) {
        if (window.jQuery) {
            callback(jQuery);
        }
        else {
            window.setTimeout(function() { checkReady(callback); }, 100);
        }
    };

    // Start polling...
    checkReady(function($) {
        // Start download
        
        $('.download-link').each(function(){
            $this = $(this);
            $this.prop("download", "");
            this.click();
        });
    });
})();

Run this code in the JavaScript console (Command+Option+J on the Mac in Google Chrome) or execute it through this Batch Download YouTube Music Tracks Bookmarklet. Drag the link to your bookmarks and click it when in the YouTube Music Library.

Resources used: Stackoverflow.com

Update:
The same method works on the Vimeo Music Library too (where you’re also unable to scrub through songs). You only need to change the class selector from .download-link to .download. Vimeo doesn’t show all tracks on one page so you may need to run it a few times. Here is the Vimeo bookmarklet: Batch Download Vimeo Music Tracks Bookmarklet.

Leave a Reply