mirror of
https://github.com/danbulant/Mangades
synced 2026-07-07 12:00:36 +00:00
Merge pull request #1 from LHK1337/download-separate
Allow downloading multiple chapters in separate files
This commit is contained in:
commit
8c32bdb7a0
2 changed files with 42 additions and 12 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -2,6 +2,6 @@
|
||||||
/public/build/
|
/public/build/
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/.routify
|
|
||||||
package-lock.json
|
package-lock.json
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
|
/.routify/
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,9 @@
|
||||||
async function getMangaChapters(id) {
|
async function getMangaChapters(id) {
|
||||||
const data = await request("manga/" + id + "/feed?limit=500&translatedLanguage[]=en");
|
const data = await request("manga/" + id + "/feed?limit=500&translatedLanguage[]=en");
|
||||||
console.log(data);
|
console.log(data);
|
||||||
data.data.sort((a, b) => a.attributes.chapter - b.attributes.chapter);
|
data.data = data.data
|
||||||
|
.filter(datum => !datum.attributes?.externalUrl)
|
||||||
|
.sort((a, b) => a.attributes.chapter - b.attributes.chapter);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,15 +85,10 @@
|
||||||
cbz: CBZGenerator
|
cbz: CBZGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadSingle(chapter) {
|
function createGenerator(chapter, file) {
|
||||||
const file = streamSaver.createWriteStream(`${manga.title.en} ${chapter.attributes.chapter}.${format}`, {
|
return new generators[format]({
|
||||||
writableStrategy: undefined, // (optional)
|
|
||||||
readableStrategy: undefined, // (optional)
|
|
||||||
});
|
|
||||||
|
|
||||||
const generator = new generators[format]({
|
|
||||||
file,
|
file,
|
||||||
id: chapter.id,
|
id: window.location.toString() + "-" + chapter.id,
|
||||||
language: chapter.attributes.translatedLanguage,
|
language: chapter.attributes.translatedLanguage,
|
||||||
updatedAt: chapter.attributes.updatedAt,
|
updatedAt: chapter.attributes.updatedAt,
|
||||||
title: manga.title.en,
|
title: manga.title.en,
|
||||||
|
|
@ -102,6 +99,14 @@
|
||||||
volume: chapter.attributes.volume
|
volume: chapter.attributes.volume
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
async function downloadSingle(chapter) {
|
||||||
|
const file = streamSaver.createWriteStream(`${manga.title.en} ${chapter.attributes.chapter}.${format}`, {
|
||||||
|
writableStrategy: undefined, // (optional)
|
||||||
|
readableStrategy: undefined, // (optional)
|
||||||
|
});
|
||||||
|
|
||||||
|
const generator = createGenerator(chapter, file)
|
||||||
|
|
||||||
console.log(generator);
|
console.log(generator);
|
||||||
queue.push(generator);
|
queue.push(generator);
|
||||||
|
|
@ -154,6 +159,30 @@
|
||||||
selected = [];
|
selected = [];
|
||||||
processQueue();
|
processQueue();
|
||||||
}
|
}
|
||||||
|
function downloadSeparate() {
|
||||||
|
selected.sort((a, b) => a.attributes.chapter - b.attributes.chapter);
|
||||||
|
if(!selected.length) return;
|
||||||
|
if(selected.length === 1) {
|
||||||
|
downloadSingle(selected.shift());
|
||||||
|
selected = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const chapter of selected) {
|
||||||
|
const file = streamSaver.createWriteStream(`${manga.title.en} ${chapter.attributes.chapter}.${format}`, {
|
||||||
|
writableStrategy: undefined, // (optional)
|
||||||
|
readableStrategy: undefined, // (optional)
|
||||||
|
});
|
||||||
|
|
||||||
|
const generator = createGenerator(chapter, file)
|
||||||
|
|
||||||
|
console.log(generator);
|
||||||
|
queue.push(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
selected = [];
|
||||||
|
processQueue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {BeforeUnloadEvent} e
|
* @param {BeforeUnloadEvent} e
|
||||||
|
|
@ -169,7 +198,7 @@
|
||||||
|
|
||||||
function selectAll() {
|
function selectAll() {
|
||||||
chapters.then(res => {
|
chapters.then(res => {
|
||||||
var chapters = res.results;
|
var chapters = res.data;
|
||||||
if(arraysEqual(selected, chapters)) {
|
if(arraysEqual(selected, chapters)) {
|
||||||
selected = [];
|
selected = [];
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -230,6 +259,7 @@
|
||||||
<option value="epub"><b>.epub</b> Electronic publication</option>
|
<option value="epub"><b>.epub</b> Electronic publication</option>
|
||||||
</select>
|
</select>
|
||||||
<button disabled={!selected.length} on:click={downloadMulti}>Download</button>
|
<button disabled={!selected.length} on:click={downloadMulti}>Download</button>
|
||||||
|
<button disabled={!selected.length} on:click={downloadSeparate}>Download Separate</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue