Skip to content

Commit 601fe19

Browse files
committed
Updated image URL parsing to latest iteratoin the site uses
1 parent eab9244 commit 601fe19

File tree

7 files changed

+57
-16
lines changed

7 files changed

+57
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
It'll archive stories for you.
44

5-
If you have no idea what you're doing then just download [this zip](https://github.com/Fiddlekins/akun-story-scraper/releases/download/1.7.0/akun-story-scraper.1.7.0.zip) and extract it in a nice friendly location like your desktop.
5+
If you have no idea what you're doing then just download [this zip](https://github.com/Fiddlekins/akun-story-scraper/releases/download/1.8.0/akun-story-scraper.1.8.0.zip) and extract it in a nice friendly location like your desktop.
66

77
Otherwise clone the project, do an npm install, it's pretty standard.
88

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "akun-story-scraper",
3-
"version": "1.7.0",
3+
"version": "1.8.0",
44
"description": "A tool to archive all quests on Akun",
55
"type": "module",
66
"main": "src/index.js",

src/Scraper.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs-extra';
22
import jsdom from 'jsdom';
33
import path from 'path';
44
import downloadImage from './downloadImage.js';
5+
import {imageURLParser} from "./imageURLParser.js";
56
import Striver from './Striver.js';
67
import Throttler from './Throttler.js';
78

@@ -299,13 +300,14 @@ export default class Scraper {
299300
const throttler = new Throttler();
300301
const promises = [];
301302
Array.from(imageUrls).forEach(imageUrl => {
303+
const parsedImageUrl = imageURLParser(imageUrl);
302304
const promiseGenerator = () => {
303-
return downloadImage(imageUrl, imagesPath).then(imagePath => {
305+
return downloadImage(parsedImageUrl, imagesPath).then(imagePath => {
304306
imageMap[imageUrl] = imagePath;
305307
});
306308
};
307309
const promise = throttler.queue(promiseGenerator).catch(err => {
308-
this._logger.error(`Unable to download image ${imageUrl} due to:\n${err}`);
310+
this._logger.error(`Unable to download image ${imageUrl} (parsed: ${parsedImageUrl}) due to:\n${err}`);
309311
});
310312
promises.push(promise);
311313
});

src/imageURLParser.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Code copied from akun site code, parameter meanings deduced
3+
* @param e Input URL
4+
* @param t Optional. Target location width
5+
* @param n Optional. Target location height
6+
* @param i Optional. Value can be "nocfill"
7+
* @param r Optional. Value can be "storyCover"
8+
* @returns {*}
9+
*/
10+
export function imageURLParser(e, t, n, i, r) {
11+
function a() {
12+
return 400 == t || 16 == t || 24 == t || 60 == t || 80 == t || 100 == t ? !0 : !1
13+
}
14+
15+
function o(e) {
16+
return e.split("?")[0]
17+
}
18+
19+
if (e && "string" == typeof e) {
20+
"object" == typeof e && (e = e[0]);
21+
var s;
22+
return r && (s = !0),
23+
t && n ? (i && (s && (-1 != e.indexOf("filepicker.io") && (e = e.replace(/www\.filepicker\.io\/api\/file\/(\w+)/g, "cdn4.fiction.live/fp/$1?height=" + n + "&width=" + t + "&quality=95")),
24+
e = e.replace(/(\w+)\.cloudfront.net\/(.+)/g, "cdn4.fiction.live/$2?height=" + n + "&width=" + t + "&quality=95").replace(/cdn3.fiction.live\/(.+)/g, "cdn4.fiction.live/$1?height=" + n + "&width=" + t + "&quality=95")),
25+
-1 != e.indexOf("filepicker.io") && (e = e.replace(/www\.filepicker\.io\/api\/file\/(\w+)/g, "cdn4.fiction.live/fp/$1?height=" + n + "&width=" + t + "&quality=95")),
26+
e = e.replace(/cdn3.fiction.live\/(.+)/g, "cdn4.fiction.live/$1?height=" + n + "&width=" + t + "&quality=95")),
27+
-1 != e.indexOf("filepicker.io") && (e = e.replace(/www\.filepicker\.io\/api\/file\/(\w+)/g, "cdn4.fiction.live/fp/$1?height=" + n + "&width=" + t + "&quality=95&aspect_ratio=" + t + ":" + n)),
28+
e = e.replace(/(\w+)\.cloudfront.net\/(.+)/g, "cdn4.fiction.live/$2?height=" + n + "&width=" + t + "&quality=95&aspect_ratio=" + t + ":" + n).replace(/cdn3.fiction.live\/(.+)/g, "cdn4.fiction.live/$1?height=" + n + "&width=" + t + "&quality=95&aspect_ratio=" + t + ":" + n),
29+
e = o(e),
30+
a() && (e = e.replace(/cdn6.fiction.live\/file\/fictionlive\/(.+)/g, "cdn6.fiction.live/file/fictionlive/thumb/$1").replace(/cdn4.fiction.live\/(.+)/g, "cdn6.fiction.live/file/fictionlive/thumb/$1").replace(/cdn3.fiction.live\/(.+)/g, "cdn6.fiction.live/file/fictionlive/thumb/$1")),
31+
e = e.replace(/cdn4.fiction.live\/(.+)/g, "cdn6.fiction.live/file/fictionlive/$1")) : (e = e.replace(/(\w+)\.cloudfront.net/g, "cdn6.fiction.live/file/fictionlive").replace(/www\.filepicker\.io\/api\/file\/(\w+)/g, "cdn4.fiction.live/fp/$1"),
32+
e = e.replace(/cdn4.fiction.live\/(.+)/g, "cdn6.fiction.live/file/fictionlive/$1").replace(/cdn3.fiction.live\/(.+)/g, "cdn6.fiction.live/file/fictionlive/$1")),
33+
e
34+
}
35+
}

src/view/buildChapter.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import {imageURLParser} from "../imageURLParser.js";
2+
13
export default function buildChapter($content, update) {
2-
$content.innerHTML = update['b'];
4+
$content.innerHTML = update['b'];
5+
6+
try {
7+
$content.querySelectorAll('img').forEach(el => {
8+
el.src = imageURLParser(el.src);
9+
});
10+
} catch (err) {
11+
console.error(err);
12+
}
313
}

src/view/formatAvatarSrc.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1+
import {imageURLParser} from "../imageURLParser.js";
2+
13
export default function formatAvatarSrc(src, size = 64) {
2-
const cloudfrontMatch = src.match(/https?:\/\/[A-z0-9]+.cloudfront.net\/images\/(.+)/i);
3-
if (cloudfrontMatch) {
4-
return `https://cdn.fiction.live/h${size}-w${size}-cfill/images/${cloudfrontMatch[1]}`;
5-
}
6-
const filepickerMatch = src.match(/https?:\/\/www.filepicker.io\/api\/file\/(.+)/i);
7-
if (filepickerMatch) {
8-
return `https://www.filepicker.io/api/file/${filepickerMatch[1]}/convert?w=${size}&h=${size}&fit=crop&cache=true`;
9-
}
10-
return src;
4+
return imageURLParser(src, size, size);
115
}

0 commit comments

Comments
 (0)