SHARE
TWEET

amazon_mp3_multiple_download.user.js (Cloud Player for Web)

baptx Jan 5th, 2014 (edited) 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // To use with Greasemonkey browser addon. Userscripts: http://userscripts.org/scripts/show/210177
  2.  
  3. /*
  4. As of today (January 2014), when you want to download multiple songs on Amazon Cloud Player for Web, it's not supported. If you use Linux (user agent), you get an error message "On Linux systems, Cloud Player only supports downloading songs one at a time". For Windows or Mac, you get a download link to install an Amazon Cloud Player program on your computer.
  5. With this Greasemonkey script, just press the download button and every song in your current playlist will be added to queue of downloads so you don't have to manually download a song one by one.
  6. I recommend using a download manager like DownThemAll for Firefox and limit downloads to one at a time because Amazon Cloud Player for Web does not correctly support multiple downloads (one day I got corrupted files, they were truncated before the end of file). To not be prompted if you want to download a new file every time, you should allow automatic download in your browser settings (On Firefox, use FlashGot addon). The script starts a new download every 5 seconds to let enough time for server response. Note also that the script waits 5 seconds until the download button is available after page load. If you wish to download some specific songs from a playlist, don't try to check the boxes and press download, instead check the boxes and add songs to a temporary playlist, then go to this playlist and press the download button. If you loaded another playlist, you need to reload the page to reenable the script (Amazon AJAX request resets the download button). While the script hasn't finished starting downloads, don't use the browser tab the script is running on. If your playlist has more then 100 songs, the script needs to scroll the playlist to get the 50 next songs. To download one song only, click the little arrow next to song name and then click "Download". This script is a hack, it is not my job to add a "multiple download" functionality so the best solution would be Amazon to fix this on their servers.
  7. */
  8.  
  9. // ==UserScript==
  10. // @name        amazon_mp3_multiple_download
  11. // @namespace   amazon
  12. // @description Download all songs in current playlist
  13. // @include     https://www.amazon.*/gp/dmusic/mp3/player*
  14. // @version     1
  15. // @grant       none
  16. // ==/UserScript==
  17.  
  18. setTimeout(function() {
  19.  
  20. var downloadButton = document.getElementsByClassName("downloadButton")[0];
  21. downloadButton.setAttribute("href", "#multipleDownload");
  22. downloadButton.onclick = function() {
  23.  
  24. var target = document.getElementsByClassName("bodyHeightContainer")[0];
  25. var list = document.getElementsByClassName("bodyContainer")[0];
  26. var listMax = 50; // Amazon Cloud Player displays max 50 MP3 by dataGroup
  27. var scroll = document.getElementsByClassName("selectable")[0].scrollHeight * listMax / 8;
  28. // scroll by 1/8 of max dataGroup for good speed and scroll detection by Amazon script
  29. var scrollMax = list.scrollTopMax;
  30. var idxMax = document.getElementsByClassName("countNumber")[0].firstChild.nodeValue;
  31. var dataGroup = 0;
  32. var idxOffset = 0;
  33. var timer, scrollTimer;
  34.  
  35. function scrollUid()
  36. {
  37.     var observer = new MutationObserver(function(mutations) {
  38.         mutations.forEach(function(mutation) {
  39.             if (mutation.addedNodes.length > 0)
  40.             {
  41.                 clearInterval(scrollTimer);
  42.                 timer = setInterval(function() {
  43.                     mutation.addedNodes[0].getElementsByClassName("optionSprite")[idxOffset].click();
  44.                     document.getElementsByClassName("optionPanelLink")[2].click();
  45.                     ++idxOffset;
  46.                     if (dataGroup + idxOffset == idxMax)
  47.                     {
  48.                         clearInterval(timer);
  49.                         observer.disconnect();
  50.                     }
  51.                     else if (idxOffset == listMax)
  52.                     {
  53.                         dataGroup += listMax;
  54.                         idxOffset = 0;
  55.                         clearInterval(timer);
  56.                         scrollTimer = setInterval(function() {
  57.                             list.scrollTop += scroll;
  58.                         }, 500); // scroll every 1/2 second to let enough time for scroll detection by Amazon script
  59.                     }
  60.                 }, 5000); // let enough time (5 seconds) for server response
  61.             }
  62.         });
  63.     });
  64.     var config = {attributes: true, childList: true, characterData: true};
  65.     observer.observe(target, config);
  66.  
  67.     scrollTimer = setInterval(function() {
  68.         list.scrollTop += scroll;
  69.         if (list.scrollTop == scrollMax)
  70.         {
  71.             clearInterval(scrollTimer);
  72.             observer.disconnect();
  73.         }
  74.     }, 500); // scroll every 1/2 second to let enough time for scroll detection by Amazon script
  75. }
  76.  
  77. timer = setInterval(function() {
  78.     document.getElementsByClassName("dataGroup" + dataGroup)[0].getElementsByClassName("optionSprite")[idxOffset].click();
  79.     document.getElementsByClassName("optionPanelLink")[2].click();
  80.     ++idxOffset;
  81.     if (dataGroup + idxOffset == idxMax)
  82.         clearInterval(timer);
  83.     else if (idxOffset == listMax)
  84.     {
  85.         dataGroup += listMax;
  86.         idxOffset = 0;
  87.         if (dataGroup == listMax * 2)
  88.         {
  89.             clearInterval(timer);
  90.             scrollUid();
  91.         }
  92.     }
  93. }, 5000); // let enough time (5 seconds) for server response
  94.  
  95. };
  96.  
  97. }, 5000); // wait some time (5 seconds) until download button is available
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top