lemmabit / ffn2epub

an alternative EPUB generator for Fimfiction.net stories
Other
2 stars 0 forks source link

Fimfiction to EPUB Cannot Download (Large) Story #1

Open craft-lover opened 4 years ago

craft-lover commented 4 years ago

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:

Error: Got HTTP response code 403 for URL https://camo.fimfiction.net/KOUaMzgwtgGVtDsOverfEaxRJ2F6cYXBPcw7bxvSYEw?url=https%3A%2F%2Flh3.googleusercontent.com%2FlPWihgZ7vBdRjTY4ZoTNAm47JcGks41NRQ3IY1CnDb2fTrVB3hUwrKCy4weUGOSu8J5egt7PPCcUCpUsOmTyKr-s7ZwtPAwalJBdKXlXB72oq3tKhBFOyDGYzlIn5xUjKqNSaUHqEyOOaSG4fqqN8TIDlR5-JAsfA4toospm4A1PDEuH7cCQmybHsnN2c6H12NBNnTjvk1nbXK6C6eAWC8ho7dNk0OAnK3yAqeNtSmBurKVeRpc_iMIR7Wx2DNjkvKZLsDL0fmH3XEee2Fh4D7vKzDwmTlYZXuiZx1ZrykEGiB3TC6fUECqwjGgIhIpu5KXurTxrxPxaAe8o3H5hoQVz2-s4yUSol8Wp99j76tBO_EpTCMmDdoOMH2RyxIYLWz0ApGbmd29XgKI0I-KoTC-0hYAYMGe-e9DpaB3qLoqyjEJDTQw6TTW72gWMoZZnCS-xM1DmR-h-ZjJYthOdQgSmyaaYzZj0tDb8Zuxz5XntxkQXBVQZkiph4YDQkykDB7Dw8n2vg2rcKeNmJm05V7dX8Sbwo4JKZfcYcjO7mu1yKFo_6nTtSQZfZU6OqpMH_X4PHgV7E84p2K5ipd7qABvexDilSL1FGSBt6A6N7-gEHIbA%3Dw34-h39-no

Error: Got HTTP response code 403 for URL https://camo.fimfiction.net/KOUaMzgwtgGVtDsOverfEaxRJ2F6cYXBPcw7bxvSYEw?url=https%3A%2F%2Flh3.googleusercontent.com%2FlPWihgZ7vBdRjTY4ZoTNAm47JcGks41NRQ3IY1CnDb2fTrVB3hUwrKCy4weUGOSu8J5egt7PPCcUCpUsOmTyKr-s7ZwtPAwalJBdKXlXB72oq3tKhBFOyDGYzlIn5xUjKqNSaUHqEyOOaSG4fqqN8TIDlR5-JAsfA4toospm4A1PDEuH7cCQmybHsnN2c6H12NBNnTjvk1nbXK6C6eAWC8ho7dNk0OAnK3yAqeNtSmBurKVeRpc_iMIR7Wx2DNjkvKZLsDL0fmH3XEee2Fh4D7vKzDwmTlYZXuiZx1ZrykEGiB3TC6fUECqwjGgIhIpu5KXurTxrxPxaAe8o3H5hoQVz2-s4yUSol8Wp99j76tBO_EpTCMmDdoOMH2RyxIYLWz0ApGbmd29XgKI0I-KoTC-0hYAYMGe-e9DpaB3qLoqyjEJDTQw6TTW72gWMoZZnCS-xM1DmR-h-ZjJYthOdQgSmyaaYzZj0tDb8Zuxz5XntxkQXBVQZkiph4YDQkykDB7Dw8n2vg2rcKeNmJm05V7dX8Sbwo4JKZfcYcjO7mu1yKFo_6nTtSQZfZU6OqpMH_X4PHgV7E84p2K5ipd7qABvexDilSL1FGSBt6A6N7-gEHIbA%3Dw34-h39-no
    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)
craft-lover commented 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)
ShinkoNet commented 2 months 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)

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.