Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // To use with Greasemonkey browser addon. Userscripts: http://userscripts.org/scripts/show/210177
- /*
- 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.
- 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.
- 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.
- */
- // ==UserScript==
- // @name amazon_mp3_multiple_download
- // @namespace amazon
- // @description Download all songs in current playlist
- // @include https://www.amazon.*/gp/dmusic/mp3/player*
- // @version 1
- // @grant none
- // ==/UserScript==
- setTimeout(function() {
- var downloadButton = document.getElementsByClassName("downloadButton")[0];
- downloadButton.setAttribute("href", "#multipleDownload");
- downloadButton.onclick = function() {
- var target = document.getElementsByClassName("bodyHeightContainer")[0];
- var list = document.getElementsByClassName("bodyContainer")[0];
- var listMax = 50; // Amazon Cloud Player displays max 50 MP3 by dataGroup
- var scroll = document.getElementsByClassName("selectable")[0].scrollHeight * listMax / 8;
- // scroll by 1/8 of max dataGroup for good speed and scroll detection by Amazon script
- var scrollMax = list.scrollTopMax;
- var idxMax = document.getElementsByClassName("countNumber")[0].firstChild.nodeValue;
- var dataGroup = 0;
- var idxOffset = 0;
- var timer, scrollTimer;
- function scrollUid()
- {
- var observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- if (mutation.addedNodes.length > 0)
- {
- clearInterval(scrollTimer);
- timer = setInterval(function() {
- mutation.addedNodes[0].getElementsByClassName("optionSprite")[idxOffset].click();
- document.getElementsByClassName("optionPanelLink")[2].click();
- ++idxOffset;
- if (dataGroup + idxOffset == idxMax)
- {
- clearInterval(timer);
- observer.disconnect();
- }
- else if (idxOffset == listMax)
- {
- dataGroup += listMax;
- idxOffset = 0;
- clearInterval(timer);
- scrollTimer = setInterval(function() {
- list.scrollTop += scroll;
- }, 500); // scroll every 1/2 second to let enough time for scroll detection by Amazon script
- }
- }, 5000); // let enough time (5 seconds) for server response
- }
- });
- });
- var config = {attributes: true, childList: true, characterData: true};
- observer.observe(target, config);
- scrollTimer = setInterval(function() {
- list.scrollTop += scroll;
- if (list.scrollTop == scrollMax)
- {
- clearInterval(scrollTimer);
- observer.disconnect();
- }
- }, 500); // scroll every 1/2 second to let enough time for scroll detection by Amazon script
- }
- timer = setInterval(function() {
- document.getElementsByClassName("dataGroup" + dataGroup)[0].getElementsByClassName("optionSprite")[idxOffset].click();
- document.getElementsByClassName("optionPanelLink")[2].click();
- ++idxOffset;
- if (dataGroup + idxOffset == idxMax)
- clearInterval(timer);
- else if (idxOffset == listMax)
- {
- dataGroup += listMax;
- idxOffset = 0;
- if (dataGroup == listMax * 2)
- {
- clearInterval(timer);
- scrollUid();
- }
- }
- }, 5000); // let enough time (5 seconds) for server response
- };
- }, 5000); // wait some time (5 seconds) until download button is available
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement