Video Game Music batch downloader

batch download for downloads.khinsider.com originalsoundtracks

当前为 2018-01-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Video Game Music batch downloader
  3. // @name:zh-TW Video Game Music 批量下載器
  4. // @namespace https://blog.maple3142.net/
  5. // @version 0.1.2
  6. // @description batch download for downloads.khinsider.com originalsoundtracks
  7. // @description:zh-TW 批量下載 downloads.khinsider.com 的原聲帶
  8. // @author maple3142
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js
  10. // @match https://downloads.khinsider.com/game-soundtracks/album/*
  11. // @grant GM_xmlhttpRequest
  12. // @connect 66.90.93.122
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict'
  17. function downloadblob(url){
  18. return new Promise((resolve,reject)=>{
  19. GM_xmlhttpRequest({
  20. method: 'GET',
  21. url,
  22. responseType: 'blob',
  23. onload: res=>resolve(res.response)
  24. })
  25. })
  26. }
  27. $('a:contains("click to download")').on('click',e=>{
  28. e.preventDefault()
  29. $('.albumMassDownload').append(`
  30. <div>
  31. <span>Download progress:</span>
  32. <progress min="0" max="100" id="dp" value="0"></progress>
  33. </div>
  34. `)
  35.  
  36. const title=$('h2')[0].textContent
  37. const urls=$('tr>td.clickable-row:not([align])').toArray().map(el=>$(el).find('a').attr('href'))
  38. const requests=urls.map(e=>fetch(e).then(r=>r.text()))
  39. Promise.all(requests).then(ar=>ar.map(ht=>{
  40. const url=$(ht).find('a:contains("Click here to download as MP3")').attr('href')
  41. return {
  42. blob: downloadblob(url),
  43. name: decodeURIComponent(url.split('/').pop())
  44. }
  45. }).reduce((zip,file)=>{
  46. zip.file(file.name,file.blob)
  47. return zip
  48. },new JSZip()).generateAsync({type: 'blob'},meta=>{
  49. $('#dp').attr('value',parseInt(meta.percent))
  50. }).then(blob=>{
  51. const url=URL.createObjectURL(blob)
  52. const a=document.createElement('a')
  53. a.download=title+'.zip'
  54. a.href=url
  55. document.body.appendChild(a)
  56. a.click()
  57. a.remove()
  58. URL.revokeObjectURL(url)
  59. }))
  60. })
  61. })()