Automatic Jango Downloader

Automatically download all songs played in jango.com while listening.

  1. // ==UserScript==
  2. // @name Automatic Jango Downloader
  3. // @author Finomosec
  4. // @namespace http://meinebasis.de/
  5. // @description Automatically download all songs played in jango.com while listening.
  6. // @version 1.3
  7. // @grant GM.xmlHttpRequest
  8. // @match https://www.jango.com/*
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. const storagePrefix = "D:";
  13.  
  14. var originalAudio = window.Audio;
  15. unsafeWindow.Audio = exportFunction(function() {
  16. var audioElement = new originalAudio();
  17. audioElement.addEventListener('loadeddata', function() {
  18. var url = audioElement.src;
  19. if (url.indexOf(".jango.com/") == -1) {
  20. return;
  21. }
  22.  
  23. var fileName = url.substring(url.lastIndexOf("/") + 1);
  24. var fileSuffix = url.substring(url.lastIndexOf("."));
  25. var niceFileName = unsafeWindow.document.title.replace(": ", " - ").replace(" - Jango", "").replace("&", "&") + fileSuffix;
  26.  
  27. if (localStorage.getItem(storagePrefix + fileName)) {
  28. // console.info('Already downloaded:', niceFileName);
  29. return;
  30. }
  31.  
  32. // console.info('Downloading:', niceFileName);
  33. GM.xmlHttpRequest({
  34. method: "GET",
  35. url: url,
  36. responseType: 'arraybuffer',
  37. onload: function(response) {
  38. var blob = new Blob([response.response], {type: "audio/" + fileSuffix.substring(1)});
  39. var url = URL.createObjectURL(blob);
  40. var link = document.createElement('a');
  41. link.href = url;
  42. link.download = niceFileName;
  43. link.click();
  44. localStorage.setItem(storagePrefix + fileName, "1");
  45. }
  46. });
  47. });
  48. return audioElement;
  49. }, unsafeWindow);