Last active
December 15, 2015 20:48
-
-
Save corpix/5320966 to your computer and use it in GitHub Desktop.
wgetify vk.com/audio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var isUnix = navigator.appVersion.indexOf('Windows') === -1, | |
titleDelim = ' – ', | |
repeats = { }, | |
capitalize = function(s) { | |
if(!s) return s; | |
return s[0].toUpperCase() + s.substr(1); | |
}; | |
var sideEffect = ''; | |
function log(msg) { | |
sideEffect += msg + '\n'; | |
} | |
function scriptTag(src, callback) { | |
var s = document.createElement('script'); | |
s.type = 'text/' + (src.type || 'javascript'); | |
s.src = src.src || src; | |
s.async = false; | |
s.onreadystatechange = s.onload = function() { | |
var state = s.readyState; | |
if(!callback.done && (!state || /loaded|complete/.test(state))) { | |
callback.done = true; | |
callback(); | |
} | |
}; | |
(document.body || head).appendChild(s); | |
}; | |
scriptTag('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', function(){ | |
var $ = jQuery; | |
$('a') | |
.each(function(i, a){ | |
var area = $(a).closest('.area'), | |
val = area.find('input[type=hidden]').val(); | |
if(!val) return; | |
var wget = 'wget' + (isUnix? '' : '.exe') + ' ', | |
title = area | |
.find('.title_wrap') | |
.text() | |
.replace(/^[^A-Za-zА-Яа-я\d_\(\)-]+$/g, '') | |
.replace(/\s+/g, ' ') | |
.replace(/^\s+/, '') | |
.replace(/\s+$/, '') | |
.toLowerCase(); | |
title = title.split(titleDelim).map(capitalize).join(titleDelim); | |
title.length > 150 && | |
(title = title.substr(0, 150) + '... '); | |
if(repeats[title.toLowerCase()]) return; | |
repeats[title.toLowerCase()] = true; | |
title = title + '.mp3'; | |
wget += "-O '" + title + "' "; | |
wget += val.split(',')[0].split('?')[0]; | |
if(isUnix) wget = "[ ! -f '" + title + "' ] && " + wget; | |
log(wget); | |
}); | |
document.write('<pre>'+sideEffect+'</pre>'); | |
}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment