mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-06-06 05:38:44 +08:00
Update
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { GMeta } from "../db.ts";
|
||||
|
||||
export type GalleryMetadataTorrentInfo = {
|
||||
hash: string;
|
||||
added: string;
|
||||
@@ -31,8 +33,32 @@ export type GalleryMetadataSingle = {
|
||||
|
||||
class GalleryMetadata {
|
||||
obj;
|
||||
map: Map<number, GalleryMetadataSingle | string>;
|
||||
constructor(text: string) {
|
||||
this.obj = JSON.parse(text);
|
||||
this.map = new Map();
|
||||
for (const m of this.obj["gmetadata"]) {
|
||||
this.map.set(m.gid, m.error ? m.error : m);
|
||||
}
|
||||
}
|
||||
convert(g: GalleryMetadataSingle): GMeta {
|
||||
return {
|
||||
gid: g.gid,
|
||||
token: g.token,
|
||||
title: g.title,
|
||||
title_jpn: g.title_jpn,
|
||||
category: g.category,
|
||||
uploader: g.uploader,
|
||||
posted: parseInt(g.posted),
|
||||
filecount: parseInt(g.filecount),
|
||||
filesize: g.filesize,
|
||||
expunged: g.expunged,
|
||||
rating: parseFloat(g.rating),
|
||||
parent_gid: g.parent_gid ? parseInt(g.parent_gid) : null,
|
||||
parent_key: g.parent_key ? g.parent_key : null,
|
||||
first_gid: g.first_gid ? parseInt(g.first_gid) : null,
|
||||
first_key: g.first_key ? g.first_key : null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@ class GalleryPage {
|
||||
client;
|
||||
#tags: Set<string> | undefined = undefined;
|
||||
#gdd_data: Map<string, Element> | undefined = undefined;
|
||||
#meta_script: string | undefined = undefined;
|
||||
#gid: number | undefined = undefined;
|
||||
#token: string | undefined = undefined;
|
||||
constructor(html: string, client: Client) {
|
||||
const dom = (new DOMParser()).parseFromString(html, "text/html");
|
||||
if (!dom) {
|
||||
@@ -47,6 +50,14 @@ class GalleryPage {
|
||||
return g;
|
||||
} else return this.#gdd_data;
|
||||
}
|
||||
get gid() {
|
||||
if (this.#gid === undefined) {
|
||||
const gid: number = eval(`${this.meta_script};gid`);
|
||||
this.#gid = gid;
|
||||
return gid;
|
||||
}
|
||||
return this.#gid;
|
||||
}
|
||||
get language() {
|
||||
const o = this.gdd_data.get("Language")?.innerText;
|
||||
if (!o) return undefined;
|
||||
@@ -60,6 +71,19 @@ class GalleryPage {
|
||||
const p = o.slice(0, o.length - 6);
|
||||
return parseInt(p);
|
||||
}
|
||||
get meta_script() {
|
||||
if (this.#meta_script === undefined) {
|
||||
const c = this.doc.getElementsByTagName("script");
|
||||
for (const e of c) {
|
||||
const t = e.innerHTML.trim();
|
||||
if (t.startsWith("var ")) {
|
||||
this.#meta_script = t;
|
||||
return t;
|
||||
}
|
||||
}
|
||||
throw Error("Failed to locate meta script.");
|
||||
} else return this.#meta_script;
|
||||
}
|
||||
get name() {
|
||||
const ele = this.doc.getElementById("gn");
|
||||
if (!ele) throw Error("Failed to find gallery's name.");
|
||||
@@ -78,6 +102,14 @@ class GalleryPage {
|
||||
return tags;
|
||||
} else return this.#tags;
|
||||
}
|
||||
get token() {
|
||||
if (this.#token === undefined) {
|
||||
const token: string = eval(`${this.meta_script};token`);
|
||||
this.#token = token;
|
||||
return token;
|
||||
}
|
||||
return this.#token;
|
||||
}
|
||||
get visible() {
|
||||
const s = this.gdd_data.get("Visible")?.innerText;
|
||||
if (s === undefined) return undefined;
|
||||
|
||||
@@ -37,4 +37,6 @@ Deno.test({
|
||||
console.log(re.favorited);
|
||||
assert(typeof re.favorited === "number");
|
||||
assertEquals(re.language, "Chinese");
|
||||
assertEquals(re.gid, 2552611);
|
||||
assertEquals(re.token, "3132307627");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user