Skip to content

Instantly share code, notes, and snippets.

@haroldtreen
Created October 31, 2016 06:09
Show Gist options
  • Save haroldtreen/83a4ece070c5b61d92e41e78ddb575cf to your computer and use it in GitHub Desktop.
Save haroldtreen/83a4ece070c5b61d92e41e78ddb575cf to your computer and use it in GitHub Desktop.
Easier downloading from hypem.com 🎵
(function() {
function getTracks() {
var tracks = [];
$('.section-player').each(function() {
tracks.push({
title: $(this).find('.track_name').text().replace(/\s+/g, ' ').trim() + '.mp3',
url: $(this).find('.dl').find('a').attr('href'),
});
});
return tracks;
}
function downloadTrack(track) {
var xhr = new XMLHttpRequest();
xhr.open('GET', track.url, true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
var link = document.createElement('a');
link.download = track.title;
link.href = (URL || webkitURL).createObjectURL(this.response);
link.target = '_blank';
document.body.appendChild(link);
link.click();
};
xhr.send();
}
var downloadLimit = Number(prompt('How many tracks to download?'));
getTracks().forEach(function(track, index) {
if (index < downloadLimit) {
downloadTrack(track);
}
});
}())
@haroldtreen
Copy link
Author

There's a really handy Chrome Extension for adding download buttons to HypeMachine.

Unfortunately it has some problems:

  1. You need to right click on the button and use Save Link As...
  2. The default name is garbage. You need to select the track title before saving if you want to replace it.
  3. Downloading song requires selecting each individually.

This bookmarklet:

  1. Extracts the correct song title.
  2. Downloads the top X songs specified.
  3. Works with a single click.

It makes my life easier.
Maybe yours too ¯_(ツ)_/¯.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment