Skip to content

Instantly share code, notes, and snippets.

@korniychuk
Last active March 17, 2018 11:34
Show Gist options
  • Save korniychuk/2fc18c1706dbcbf00f7114cbc94891f9 to your computer and use it in GitHub Desktop.
Save korniychuk/2fc18c1706dbcbf00f7114cbc94891f9 to your computer and use it in GitHub Desktop.
zf.fm downloader bookmark URL
javascript: (() => {
window.ankorDownloader = window.ankorDownloader || {
download: (html) => {
/*
console.log('Downloading... html:', [html]);
const html = prompt('Enter html with links');
*/
const reg = /class="song-artist"[^>]*?>.+?<span>(.*?)<\/span>.+?class="song-name"[^>]*?>.+?<span>(.*?)<\/span>.+?data-sid="([^"]+)"/gs;
const songs = [];
let matches;
while (matches = reg.exec(html)) {
const artist = matches[1];
const name = matches[2];
const id = matches[3];
songs.push({ id, artist, name });
}
const downloadCommand = songs
.map((song) =>
`wget -O "${song.artist} - ${song.name}.mp3" http://zk.fm/download/${song.id}"`,
)
.join('\n');
console.log(`Total songs: ${songs.length}. Wget command:\n%s`, downloadCommand);
},
addToPlaylists: () => {
$('.songs-list').each((i, el) => {
const btn$ = $('<button>download</button>');
btn$.click(() => ankorDownloader.download($(el).html()));
$(el).parent().prepend(btn$);
});
}
};
ankorDownloader.addToPlaylists();
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment