Open craft-lover opened 4 years ago
Found another story (Curse of the Wherepony; 4ch, 26k), though the error is different for this one. Seems to be a issue with the image source...?
Error: Got HTTP response code 404 for URL https://camo.fimfiction.net/aNnPdf-x6vyaljqoXAlimm2hg79s2fZDiW5RbB_pB14?url=http%3A%2F%2Ffc07.deviantart.net%2Ffs70%2Fi%2F2012%2F295%2F1%2Fd%2Ffake__by_publiclibraryx-d5ioj0t.png
Error: Got HTTP response code 404 for URL https://camo.fimfiction.net/aNnPdf-x6vyaljqoXAlimm2hg79s2fZDiW5RbB_pB14?url=http%3A%2F%2Ffc07.deviantart.net%2Ffs70%2Fi%2F2012%2F295%2F1%2Fd%2Ffake__by_publiclibraryx-d5ioj0t.png
at Function.onload (chrome-extension://dhdgffkkebhmkfjojejmpbldmpobfkfo/userscript.html?name=Fimfiction%2520to%2520EPUB.user.js&id=a83012d0-b2a4-453a-a486-0457a7f3cf59:132:18)
at F_a.n (<anonymous>:3:98)
at b.setTimeout (eval at exec_fn (:1:147), <anonymous>:28:123)
Found another story (Curse of the Wherepony; 4ch, 26k), though the error is different for this one. Seems to be a issue with the image source...?
Error: Got HTTP response code 404 for URL https://camo.fimfiction.net/aNnPdf-x6vyaljqoXAlimm2hg79s2fZDiW5RbB_pB14?url=http%3A%2F%2Ffc07.deviantart.net%2Ffs70%2Fi%2F2012%2F295%2F1%2Fd%2Ffake__by_publiclibraryx-d5ioj0t.png Error: Got HTTP response code 404 for URL https://camo.fimfiction.net/aNnPdf-x6vyaljqoXAlimm2hg79s2fZDiW5RbB_pB14?url=http%3A%2F%2Ffc07.deviantart.net%2Ffs70%2Fi%2F2012%2F295%2F1%2Fd%2Ffake__by_publiclibraryx-d5ioj0t.png at Function.onload (chrome-extension://dhdgffkkebhmkfjojejmpbldmpobfkfo/userscript.html?name=Fimfiction%2520to%2520EPUB.user.js&id=a83012d0-b2a4-453a-a486-0457a7f3cf59:132:18) at F_a.n (<anonymous>:3:98) at b.setTimeout (eval at exec_fn (:1:147), <anonymous>:28:123)
I fixed this error by making the script skip images and links that are now dead. In tampermonkey, or whatever userscript extension, edit the script like follows:
Use this new get function
function get(url, responseType) {
if (!url) {
throw Error("Tried to get an empty URI!");
}
let isDocument = false;
if (responseType === 'document') {
isDocument = true;
responseType = 'text';
}
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: "GET",
url,
responseType,
onload({ status, response }) {
if (status === 200) {
if (!isDocument) {
resolve(response);
} else {
resolve(new DOMParser().parseFromString(response + `<base href="${escapeForHTML(location.href)}" />`, 'text/html'));
}
} else if (status === 404) {
console.warn(`Got HTTP response code 404 for URL ${url}. Skipping this image.`);
resolve(null);
} else {
reject(Error(`Got HTTP response code ${status} for URL ${url}`));
}
},
onerror() {
reject(Error(`Request for ${url} errored`));
},
onabort() {
reject(Error(`Request for ${url} was aborted`));
},
});
});
}
Use this new getImage function
function getImage(src) {
return get(src, 'arraybuffer').then(buf => {
const imageType = detectImageType(buf);
if (imageType) {
return { data: buf, imageType, img: undefined };
} else {
return createImageElement(new Blob([buf])).then(img => {
if (!img) {
console.warn(`Skipping image processing for src: ${src}`);
return null;
}
return new Promise((resolve, reject) => {
const canvas = document.createElement('canvas');
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, img.naturalWidth, img.naturalHeight);
const imageType = {
ext: 'png',
mime: 'image/png',
};
canvas.toBlob(blob => {
resolve({ data: blob, imageType, img });
}, imageType.mime);
});
});
}
});
}
then replace lines 5272-5289
if (!images.has(src)) {
const imageNumber = ++imageCounter;
const p = getImage(src).then(result => {
if (result === null) {
console.warn(`Skipping image with src: ${src}`);
return;
}
const { data, imageType: { ext, mime } } = result;
const id = `img${(imagesLeadingZeroes + imageNumber).slice(-imagesLeadingZeroes.length)}`;
const name = `${id}.${ext}`;
ocfWriter.addFile(name, data);
images.set(src, { id, name, mime });
}).catch(error => {
console.error(`Error processing image with src: ${src}`, error);
});
images.set(src, p);
allNecessaryPromises.push(p);
}
Since this is editing the compiled js and not the source found on this repo, i cant really make a commit. Hope this helps for anyone who comes across that error. I think if you add the exception '403' as well as '404' it'll solve that too.
I am currently running Fimfiction to EPUB v2.2.2 on Tampermonkey v4.10 in Google Chrome x64 v67.0.3396.99.
I tryed three separate times today (04 May 2020) to download Techorse Short Stories [https://www.fimfiction.net/story/251131/techorse-short-stories]. The book is 51 Chapters and contains ~534k words. I have had no other problems downloading other large storys--including Fallout: Equestria which has two fewer chapters but nearly 100k more words.
EDIT: Just out of curiosity, I went and downloaded the absolutely massive Fallout: Equestria: Project Horizons (78 chapters/1.8m words), so it definitely has nothing to do with the size of the book. As requested, the stack trace is below: