Skip to content

Instantly share code, notes, and snippets.

@sod
Created January 8, 2020 20:47
Show Gist options
  • Save sod/46bde54b66cd2a1ad637b471d9c2660d to your computer and use it in GitHub Desktop.
Save sod/46bde54b66cd2a1ad637b471d9c2660d to your computer and use it in GitHub Desktop.
// https://bsaber.com/songs/top/page/2/?time=3-months&difficulty=expert-plus&ranked=false#038;difficulty=expert-plus&ranked=false
function getTitle(node) {
let artist = node.querySelector('.mapper_id').innerText;
let song = node.querySelector('.entry-title').innerText;
return `${artist} (${song})`.replace(/[^().-_a-z0-9[\] ]+/ig, '');
}
function getFile(node) {
return node.querySelector('.-download-zip').href;
}
downloadLogfile = 'log.txt';
songs = Array.from(document.querySelectorAll('article.post'));
files = songs.map((song) => ({title: getTitle(song), zip: getTitle(song) + '.zip', download: getFile(song)}))
downloads = files.map(({zip, download}) => `wget "${download}" -O "${zip}" -o ${downloadLogfile}`)
unzip = files.map(({zip, title}) => `unzip "${zip}" -d "${title}"`)
remove = files.map(({zip}) => `rm "${zip}"`)
console.log(
downloads.concat('wait;').join(' & \\\n') + '\n\n' +
unzip.concat('wait;').join(' & \\\n') + '\n\n' +
remove.concat(['rm ' + downloadLogfile, 'wait;']).join(' & \\\n')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment