-
Notifications
You must be signed in to change notification settings - Fork 0
/
comic-info.ts
61 lines (52 loc) · 2.76 KB
/
comic-info.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { join } from "https://deno.land/[email protected]/path/mod.ts";
import { BasicMangaMetadata, Chapter } from "./metadata.ts";
export interface PageInfo {
index: number;
size: number;
filename: string;
}
export function writeComicInfo(folder_path: string, metadata: BasicMangaMetadata, chapter_info: Chapter, pages: PageInfo[]): boolean {
const FILE_PATH = join(folder_path, "ComicInfo.xml");
const Encoder = new TextEncoder();
Deno.writeFileSync(FILE_PATH, Encoder.encode(`<?xml version="1.0"?>\n`), { create: true, append: false });
Deno.writeFileSync(
FILE_PATH,
Encoder.encode(`<ComicInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">\n`),
{ create: false, append: true }
);
Deno.writeFileSync(
FILE_PATH,
Encoder.encode(
`\t<Title>${metadata.title} - Chapter ${chapter_info.pretype} ${chapter_info.main}${chapter_info.sub ? `.${chapter_info.sub}` : ""}</Title>\n`
),
{
create: false,
append: true,
}
);
Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t<Series>${metadata.title}</Series>\n`), { create: false, append: true });
Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t<Number>${chapter_info.main}${chapter_info.sub != 0 ? `.${chapter_info.sub}` : ""}</Number>\n`), {
create: false,
append: true,
});
Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t<Volume>${chapter_info.pretype}</Volume>\n`), { create: false, append: true });
Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t<Notes>Downloaded/Scrapped with Mangasee123 Downloader from MrMysterius</Notes>\n`), {
create: false,
append: true,
});
Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t<Year>${metadata.release_year}</Year>\n`), { create: false, append: true });
Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t<Writer>${metadata.authors.join(",")}</Writer>\n`), { create: false, append: true });
Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t<Genre>${metadata.genres.join(",")}</Genre>\n`), { create: false, append: true });
Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t<PageCount>${pages.length}</PageCount>\n`), { create: false, append: true });
Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t<AgeRating>Unknown</AgeRating>\n`), { create: false, append: true });
Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t<Pages>\n`), { create: false, append: true });
for (const page of pages) {
Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t\t<Page Image="${page.index}" ImageSize="${page.size}" />\n`), {
create: false,
append: true,
});
}
Deno.writeFileSync(FILE_PATH, Encoder.encode(`\t</Pages>\n`), { create: false, append: true });
Deno.writeFileSync(FILE_PATH, Encoder.encode(`</ComicInfo>\n`), { create: false, append: true });
return true;
}