SoundCloud Downloader using local copy of youtube-dl

Download songs from SoundCloud using youtube-dl

  1. // ==UserScript==
  2. // @name SoundCloud Downloader using local copy of youtube-dl
  3. // @namespace fke9fgjew89gjwe89
  4. // @version 1.1
  5. // @description Download songs from SoundCloud using youtube-dl
  6. // @author https://greasyfork.org/en/users/432346-fke9fgjew89gjwe89
  7. // @icon https://a-v2.sndcdn.com/assets/images/sc-icons/ios.png
  8. // @include /^https:\/\/soundcloud\.com/.*$/
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14. var head = document.getElementsByTagName('head')[0];
  15. var style = document.createElement('style');
  16. var css = '.sc-button-directdl{text-indent:19px}.sc-button-directdl::before{background-size:16px 16px;background-image:url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48dGl0bGU+UmVjdGFuZ2xlIDMxPC90aXRsZT48cGF0aCBkPSJNMyAxMXYyaDEwdi0ySDN6bTAtN2gxMGwtNSA2LTUtNnptMy0ydjJoNFYySDZ6IiBmaWxsPSIjMjIyIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48L3N2Zz4=);content:"";display:block;position:absolute;background-repeat:no-repeat;background-position:center center;width:20px;height:20px;top:0;bottom:0;margin:auto 0;left:4px}';
  17. style.setAttribute('type', 'text/css');
  18. if (style.styleSheet) {
  19. style.styleSheet.cssText = css;
  20. } else {
  21. style.appendChild(document.createTextNode(css));
  22. }
  23. head.appendChild(style);
  24. String.prototype.mapReplace = function (map) {
  25. var regex = [];
  26. for (var key in map)
  27. regex.push(key.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'));
  28. return this.replace(new RegExp(regex.join('|'), 'g'), function (word) {
  29. return map[word];
  30. });
  31. };
  32. var last_sound_title = '1';
  33. setInterval(function () {
  34. var sound_title = document.getElementsByClassName('soundTitle__title')[0].children[0].innerText.mapReplace({
  35. '&': '&',
  36. '<': '&lt;',
  37. '>': '&gt;',
  38. "'": '&#39;',
  39. '/': '&#x2F;',
  40. '`': '&#x60;',
  41. '=': '&#x3D;',
  42. '"': '&quot;'
  43. });
  44. if (last_sound_title !== sound_title) {
  45. last_sound_title = sound_title;
  46. var button_list = document.getElementsByClassName('sc-button-group sc-button-group-medium')[0];
  47. var directdl = '<a href="ytdl://' + window.location + '" class="sc-button-directdl sc-button sc-button-medium sc-button-responsive" tabindex="0" aria-haspopup="true" role="button" title="Download" aria-label="Download">Download</a>';
  48. button_list.insertAdjacentHTML('beforeend', directdl);
  49. }
  50. if (document.getElementsByClassName('sound streamContext playing')[0] && !document.getElementsByClassName('sound streamContext playing')[0].querySelector('.sc-button-directdl')) {
  51. var stuff = document.getElementsByClassName('sound streamContext playing')[0];
  52. var linksr = stuff.querySelector('.soundTitle__title.sc-link-dark').href;
  53. console.log(linksr);
  54. var button_list = stuff.querySelector('.sc-button-group.sc-button-group-small');
  55. var directdl = '<a href="ytdl://' + linksr + '" class="sc-button-directdl sc-button sc-button-small sc-button-responsive" tabindex="0" aria-haspopup="true" role="button" title="Download" aria-label="Download">Download</a>';
  56. button_list.insertAdjacentHTML('beforeend', directdl);
  57. var divs = document.getElementsByClassName('sc-button-directdl');
  58. var lastChild = divs[divs.length - 1];
  59. }
  60. }, 3 * 1000);
  61. }());