Song365Easy

Download files from Song365

  1. // ==UserScript==
  2. // @name Song365Easy
  3. // @namespace http://www.tampermonkey.com/
  4. // @version 0.1
  5. // @description Download files from Song365
  6. // @author LesserEvil
  7. // @match https://www.song365.biz/album/*
  8. // @match https://www.song365.me/album/*
  9. // @match https://www.song365.co/album/*
  10. // @match https://www.song365.mobi/album/*
  11. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
  12. // @grant GM_xmlhttpRequest
  13. // ==/UserScript==
  14.  
  15.  
  16. function SubmitTrackInfo(trackUrl, trackFilename, elementId)
  17. {
  18. console.log('TrackUrl submitted: '+trackUrl);
  19. GM_xmlhttpRequest ( {
  20. method: "GET",
  21. url: trackUrl,
  22. onload: function (response) {
  23. console.log('TrackUrl Loaded: '+trackUrl);
  24. var parser = new DOMParser ();
  25. /* IMPORTANT!
  26. 1) For Chrome, see
  27. https://developer.mozilla.org/en-US/docs/Web/API/DOMParser#DOMParser_HTML_extension_for_other_browsers
  28. for a work-around.
  29.  
  30. 2) jQuery.parseHTML() and similar are bad because it causes images, etc., to be loaded.
  31. */
  32. console.log("loaded html for song: "+trackFilename);
  33. var lines = response.responseText.split("\n");
  34. //console.log("Found lines: "+lines.length);
  35. var theLine = "";
  36. var realLink = "";
  37. for( lineIndex in lines )
  38. {
  39. var theLine = lines[lineIndex];
  40. var lqIndex = theLine.indexOf("var url = 'http://");
  41. // var streamIndex = theLine.indexOf("http://stream.song365.co");
  42. var hqIndex = theLine.indexOf("var hqurl = 'http://");
  43. var strLength = theLine.length;
  44. //if ( elementId == 1 )
  45. // {
  46. // console.log(theLine);
  47. // }
  48. if ( lqIndex >= 0 )
  49. {
  50. if ( realLink == "" )
  51. {
  52. realLink = theLine.substr(lqIndex+11, strLength-(lqIndex+14));
  53. }
  54. }
  55. else if ( hqIndex >= 0 ) // subVal == "var hqurl = 'http://stre" )
  56. {
  57. realLink = theLine.substr(hqIndex+13, strLength-(hqIndex+16));
  58. break;
  59. }
  60. // var testLinkIndex=theLine.indexOf("download-link-hq");
  61. //if ( testLinkIndex >= 0 )
  62. //{
  63. // if ( realLink == "" )
  64. // {
  65. // console.log("Found this: "+theLine);
  66. // }
  67. // }
  68. // else if ( streamIndex >= 0 )
  69. //{
  70. // realLink = theLine.substr(streamIndex);
  71. // break;
  72. // }
  73. }
  74. if ( realLink != "" )
  75. {
  76. console.log("Found link: "+realLink);
  77. var linkElement = document.querySelector("a.song-dl-"+elementId);
  78. if ( linkElement != null )
  79. {
  80. linkElement.href = realLink;
  81. linkElement.download = trackFilename;
  82. }
  83. }
  84. else
  85. {
  86. console.log("Unable to find real link!");
  87. }
  88. // var doc = parser.parseFromString (response.responseText, "text/html");
  89. // var criticTxt = doc.getElementsByClassName ("critic_consensus")[0].textContent;
  90.  
  91. // $("body").prepend ('<h1>' + criticTxt + '</h1>');
  92. },
  93. onerror: function (e) {
  94. console.error ('**** error ', e);
  95. },
  96. onabort: function (e) {
  97. console.error ('**** abort ', e);
  98. },
  99. ontimeout: function (e) {
  100. console.error ('**** timeout ', e);
  101. }
  102. } );
  103. }
  104.  
  105. function insertAfter(newNode, referenceNode) {
  106. referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  107. }
  108.  
  109. function hasClass(docElement, matchClass)
  110. {
  111. return ((' ' + docElement.className + ' ').indexOf(' ' + matchClass + ' ') > -1)
  112. }
  113.  
  114. function getElementByTagAndClass(docElement, tagName, matchClass)
  115. {
  116. var elements = docElement.getElementsByTagName(tagName), i;
  117. for( i in elements )
  118. {
  119. if ( hasClass(elements[i], matchClass ))
  120. {
  121. return elements[i];
  122. }
  123. }
  124. return null;
  125. }
  126.  
  127. function getProfileItemValue(title)
  128. {
  129. console.log('Getting profile item value for: '+title);
  130. var returnVal = "";
  131. profileItemList = document.querySelectorAll('div.profile-item');
  132. console.log('Found profile items: '+profileItemList.length);
  133. for( var index=0; index<profileItemList.length; index++ )
  134. {
  135. profileItemTitle = profileItemList[0].querySelector('em.profile-item-title').innerHTML;
  136. if ( profileItemTitle == title )
  137. {
  138. var valElement = profileItemList[0].querySelector('em.profile-item-value');
  139. if ( valElement.firstElementChild != null )
  140. {
  141. returnVal = valElement.firstElementChild.innerHTML;
  142. }
  143. else
  144. {
  145. returnVal = valElement.innerHTML; // profileItemList[0].querySelector('em.profile-item-value').innerHTML;
  146. }
  147. break;
  148. }
  149. }
  150. console.log(profileItemTitle+' - '+returnVal);
  151. return returnVal;
  152. }
  153.  
  154. function songItem(element,artistName)
  155. {
  156. var numberVal = element.querySelector('div.number').innerHTML;
  157. var titleElement = element.querySelector('div.song-name');
  158. var songTitle = "";
  159. var fullSongFilename = "";
  160. var buttonsDiv = element.querySelector('div.buttons');
  161. var downloadLink = buttonsDiv.querySelector('a.download').href;
  162. if ( titleElement.firstElementChild != null )
  163. {
  164. songTitle = titleElement.firstElementChild.innerHTML.trim();
  165. }
  166. else
  167. {
  168. songTitle = titleElement.innerHTML.trim(); // profileItemList[0].querySelector('em.profile-item-value').innerHTML;
  169. }
  170. fullSongFilename = ("00" + numberVal).slice(-2) +" - "+artistName+" - "+songTitle+".mp3";
  171. songUrlId = "song-dl-"+numberVal;
  172. fullSongLink = "<a href='"+downloadLink+"' class='"+songUrlId+"' >"+fullSongFilename+"</a>";
  173. SubmitTrackInfo(downloadLink,fullSongFilename,numberVal);
  174. return fullSongLink; // element.innerHTML;
  175. }
  176.  
  177. var insertPoint = null;
  178.  
  179. var elements = document.getElementsByTagName('a'), i;
  180.  
  181. for( i in elements )
  182. {
  183. if ( i.href = '//www.liveinternet.ru/click' )
  184. {
  185. console.log('Found insert point!');
  186. insertPoint = i;
  187. break;
  188. }
  189. }
  190.  
  191. if ( insertPoint != null )
  192. {
  193. var newDiv = document.createElement("div");
  194. newDiv.id = "courseDownload";
  195. newDiv.innerHTML = "Download Songs<br /><ul id='songDownloadList' class='songList'></ul>";
  196. // console.log(insertPoint);
  197. // console.log(insertPoint.parentNode);
  198. document.body.appendChild(newDiv); // ,insertPoint);
  199.  
  200. var newDiv2 = document.createElement("div");
  201. newDiv2.id = "courseInfo";
  202. newDiv2.innerHTML = "----------<br />";
  203. insertAfter(newDiv2,newDiv);
  204. }
  205.  
  206. artistSongs = document.querySelector('div.artist-songs');
  207. artistName = getProfileItemValue('Artist Name:');
  208. songList = document.querySelector('ul.songList');
  209. elements = artistSongs.querySelectorAll('div.item');
  210.  
  211. songList.innerHTML = songList.innerHTML+"<li>"+artistName+"</li>\n"
  212.  
  213. for( var index=0; index<elements.length; index++ )
  214. {
  215. songList.innerHTML = songList.innerHTML+"<li>"+songItem(elements[index],artistName)+"</li>\n"
  216. }
  217.  
  218.  
  219.