Skip to content

Instantly share code, notes, and snippets.

@corpix
Last active December 15, 2015 20:48
Show Gist options
  • Save corpix/5320966 to your computer and use it in GitHub Desktop.
Save corpix/5320966 to your computer and use it in GitHub Desktop.
wgetify vk.com/audio
(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