khinsider batch downloader

batch download for downloads.khinsider.com originalsoundtracks

Nainštalovať tento skript?
Autor skriptu navrhuje

Tiež sa vám môže páčiť anime1-downloader.

Nainštalovať tento skript
  1. // ==UserScript==
  2. // @name khinsider batch downloader
  3. // @name:zh-TW khinsider 批量下載器
  4. // @namespace https://blog.maple3142.net/
  5. // @description batch download for downloads.khinsider.com originalsoundtracks
  6. // @description:zh-TW 批量下載 downloads.khinsider.com 的原聲帶
  7. // @version 0.2.0
  8. // @author maple3142
  9. // @match https://downloads.khinsider.com/game-soundtracks/album/*
  10. // @require https://cdn.jsdelivr.net/npm/web-streams-polyfill@2.0.2/dist/ponyfill.min.js
  11. // @require https://cdn.jsdelivr.net/npm/streamsaver@2.0.3/StreamSaver.min.js
  12. // @require https://cdn.jsdelivr.net/gh/maple3142/StreamSaver.js/examples/zip-stream.min.js
  13. // @license MIT
  14. // @connect 23.237.126.42
  15. // @grant GM_xmlhttpRequest
  16. // ==/UserScript==
  17.  
  18. function download(url) {
  19. return new Promise((resolve, reject) => {
  20. GM_xmlhttpRequest({
  21. method: 'GET',
  22. url,
  23. responseType: 'blob',
  24. onload: res => resolve(res.response)
  25. })
  26. })
  27. }
  28.  
  29. let started = false
  30. $('a:contains("click to download")').on('click', async e => {
  31. e.preventDefault()
  32. $(e.target).text("Don't close this tab until download complete.")
  33. if (started) return
  34. started = true
  35. const title = $('h2')[0].textContent
  36. const files = $('tr>td.clickable-row:not([align])')
  37. .toArray()
  38. .map(el =>
  39. $(el)
  40. .find('a')
  41. .attr('href')
  42. )
  43. .map(url => {
  44. const obj = {}
  45. obj.pageUrl = url
  46. obj.blobPromise = fetch(url)
  47. .then(r => r.text())
  48. .then(html => {
  49. obj.url = $(html)
  50. .find('a:contains("Click here to download as MP3")')
  51. .attr('href')
  52. obj.name = decodeURIComponent(obj.url.split('/').pop())
  53. return download(obj.url)
  54. })
  55. return obj
  56. })
  57. const ws = streamSaver.createWriteStream(title + '.zip')
  58. new ZIP({
  59. async pull(ctrl) {
  60. const f = files.shift()
  61. const stream = new Response(await f.blobPromise).body
  62. ctrl.enqueue({ name: f.name, stream: () => stream })
  63. if (files.length === 0) ctrl.close()
  64. }
  65. })
  66. .pipeTo(ws)
  67. .then(console.log, console.error)
  68. })