Skip to content

Instantly share code, notes, and snippets.

@Et7f3
Created August 30, 2018 08:19
Show Gist options
  • Save Et7f3/34d2001ae01a84ac180b8de6b78af67a to your computer and use it in GitHub Desktop.
Save Et7f3/34d2001ae01a84ac180b8de6b78af67a to your computer and use it in GitHub Desktop.
Deezer Reaper
// ==UserScript==
// @name deezer reaper
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author élie
// @match https://www.deezer.com/*
// @grant none
// ==/UserScript==
var exports = {}
exports.my_pause = HTMLAudioElement.prototype.pause;
exports.get_class = function get_class(el) {
return el.getAttribute('class') || '';
}
exports.pause_and_play_vid = function pause_and_play_vid() {
window.setTimeout(function () {
console.log("1 : title", document.querySelector(".control-play").title);
if (document.querySelector(".control-play").title == "Pause") {
document.querySelector(".control-play").click();
} else exports.pause_and_play_vid();
}, 1e3);
}
window.addEventListener("load", function (event) {
window.setTimeout(() => {
exports.obs_config = {
attributeOldValue: true,
attributes: true,
characterData: true,
characterDataOldValue: true,
childList: true,
subtree: true
};
exports.targetNode = document.querySelector("#player");
//document.querySelector(".player-track-link").parentNode.parentNode.parentNode.parentNode.parentNode;
//document.querySelectorAll(".control")[1].parentNode.parentNode;
exports.callback = function (mutationsList) {
for (var mutation of mutationsList) {
if ('attributes' != mutation.type) {
continue;
}
// if (!mutation.target) {
// continue;
// }
// if (mutation.target.tagName == 'SVG') {
// continue;
// }
if ('title' != mutation.attributeName) {
continue;
}
if (exports.get_class(mutation.target).indexOf('progress') >= 0) {
continue;
} else {
console.log("class: ", exports.get_class(mutation.target));
}
if ('Pause' == mutation.oldValue) {
continue;
}
console.log('un nouveau titre est chargé');
console.log(exports.get_class(mutation.target), '/', mutation.type, '/', mutation.target.tagName, ": ", mutation);
exports.observer.disconnect();
window.setTimeout(() => exports.pause_and_play_vid(), 1e4);
window.setTimeout(() => exports.observer.observe(exports.targetNode, exports.obs_config), 2 * 1e4);
continue;
if ('svg-icon svg-icon-play' == mutation.target.className && 'attributes' == mutation.type && 'SVG' == mutation.target.tagName) {
console.log("on lance une nouvelle musique.");
exports.play_vid();
break;
} else if ('volume-handler ui-draggable ui-draggable-handle' == mutation.target.className && 'attributes' == mutation.type && 'SPAN' == mutation.target.tagName) {
console.log("on lance une nouvelle musique.");
exports.play_vid();
break;
} else {
//console.log(mutation.target.classNam, '/', mutation.type, '/', mutation.target.tagName, ": ", mutation);
}
// if ('attributes' == mutation.type && 'A' == mutation.target.tagName
// /*'attributes' == mutation.type && 'SVG' == mutation.target.tagName*/) {
// console.log(mutation);
// console.log("on lance une nouvelle musique.");
// play_vid();
// break;
// } else {
// console.log(mutation.type, ": ", mutation);
// }
}
};
exports.observer = new MutationObserver(exports.callback);
exports.observer.observe(exports.targetNode, exports.obs_config);
console.log("toutes les ressources sont chargés!");
}, 5 * 1e3);
});
function dl(vid, name, author) {
var stream = vid.captureStream(0);
var vid_name = author + " - " + name;
var chunk = [];
var media_recorder = new MediaRecorder(stream, {
mimeType: 'audio/webm'
});
var handle_data_event = function (e) {
console.log("downloading " + vid_name + " ...");
if (e.data.size > 0) chunk.push(e.data);
};
media_recorder.ondataavailable = handle_data_event;
media_recorder.onstop = function (e) {
console.log('on a fini');
var blob = new Blob(chunk, {
type: 'audio/webm'
}),
url = URL.createObjectURL(blob),
a = document.createElement('a');
//document.body.appendChild(a);
console.log('on télécharge');
a.href = url;
a.download = vid_name + '.webm';
a.click();
console.log('on nettoie');
handle_data_event = e => {};
media_recorder = stream = vid_name = chunk = null;
}
console.log('on va demarrer');
media_recorder.start(1);
vid.play();
console.log('on a demarré');
window.setTimeout(function () {
console.log('on va finir');
media_recorder.stop();
}, vid.duration * 1000);
}
HTMLAudioElement.prototype.pause = function launch_dl() {
console.log('on met en pause');
exports.my_pause.call(this);
console.log('on remet au début');
this.currentTime = 0;
console.log('on lance le telechargement');
dl(this, document.querySelectorAll("a.player-track-link")[0].innerText, document.querySelectorAll("div.player-track-artist")[0].innerText.slice(4));
};
// var my_play = HTMLVideoElement.prototype.play;
// HTMLVideoElement.prototype.play = function play()
// {
// console.log(this);
// dl(this, document.querySelectorAll("a.player-track-link")[0].innerText, document.querySelectorAll("div.player-track-artist")[0].innerText.slice(4));
// my_play.call(this);
// }
window.exports = exports;
console.log("deezer reaper ok");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment