Add sampled_name

This commit is contained in:
2023-06-25 13:42:24 +08:00
parent 214c419593
commit 494a0f66e3
3 changed files with 23 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import { DOMParser, Element } from "deno_dom/deno-dom-wasm-noinit.ts";
import { extname } from "std/path/mod.ts";
import { Client } from "../client.ts";
import { EhFile, PMeta } from "../db.ts";
import { initDOMParser, map, parse_bool } from "../utils.ts";
@@ -75,6 +76,15 @@ class Image {
get page_token() {
return this.base.token;
}
get sampled_name() {
const name = this.data?.name;
if (name) return name;
const n = this.base.name;
const e = extname(n);
const b = n.slice(0, n.length - e.length);
if (n === ".gif") return `${b}.gif`;
return `${b}.jpg`;
}
get src() {
return this.data?.img_url;
}

View File

@@ -1,4 +1,5 @@
import { DOMParser } from "deno_dom/deno-dom-wasm-noinit.ts";
import { extname } from "std/path/mod.ts";
import { Client } from "../client.ts";
import { initDOMParser } from "../utils.ts";
import { EhFile, PMeta } from "../db.ts";
@@ -122,6 +123,13 @@ class MPVImage {
get page_token() {
return this.base.k;
}
get sampled_name() {
const n = this.base.n;
const e = extname(n);
const b = n.slice(0, n.length - e.length);
if (n === ".gif") return `${b}.gif`;
return `${b}.jpg`;
}
get src() {
return this.data?.i;
}

View File

@@ -106,6 +106,7 @@ interface Image {
is_original: boolean | undefined;
name: string;
page_token: string;
sampled_name: string;
get_file(path: string): EhFile | undefined;
get_original_file(path: string): EhFile | undefined;
load(): Promise<void>;
@@ -222,7 +223,10 @@ export async function download_task(
if (pmeta) db.add_pmeta(pmeta);
const download_original = download_original_img &&
!i.is_original;
let path = resolve(join(base_path, i.name));
const is_sampled = !download_original_img && !i.is_original;
let path = resolve(
join(base_path, is_sampled ? i.sampled_name : i.name),
);
if (names[i.name] > 1) {
path = add_suffix_to_path(path, i.page_token);
console.log("Changed path to", path);