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 :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 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) 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.