Skip to content

Commit a07e549

Browse files
committed
Merged comic book models with manga models into comicmanga model
Updated both MALAPI Manga and ComicVine API to be more consistent with eachother.
1 parent 01b56c9 commit a07e549

File tree

8 files changed

+128
-93
lines changed

8 files changed

+128
-93
lines changed

src/api/apis/ComicVineAPI.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { requestUrl } from 'obsidian';
2-
import { ComicBookModel } from 'src/models/ComicBookModel';
2+
import { ComicMangaModel } from 'src/models/ComicMangaModel';
33
import type MediaDbPlugin from '../../main';
44
import type { MediaTypeModel } from '../../models/MediaTypeModel';
55
import { MediaType } from '../../utils/MediaType';
@@ -15,7 +15,7 @@ export class ComicVineAPI extends APIModel {
1515
this.apiName = 'ComicVineAPI';
1616
this.apiDescription = 'A free API for comic books.';
1717
this.apiUrl = 'https://comicvine.gamespot.com/api';
18-
this.types = [MediaType.ComicBook];
18+
this.types = [MediaType.ComicManga];
1919
}
2020

2121
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
@@ -35,7 +35,7 @@ export class ComicVineAPI extends APIModel {
3535
const ret: MediaTypeModel[] = [];
3636
for (const result of data.results) {
3737
ret.push(
38-
new ComicBookModel({
38+
new ComicMangaModel({
3939
title: result.name,
4040
englishTitle: result.name,
4141
year: result.start_year,
@@ -67,18 +67,20 @@ export class ComicVineAPI extends APIModel {
6767
// console.debug(data);
6868
const result = data.results;
6969

70-
return new ComicBookModel({
71-
type: MediaType.ComicBook,
70+
return new ComicMangaModel({
71+
type: MediaType.ComicManga,
7272
title: result.name,
73+
englishTitle: result.name,
74+
alternateTitles: result.aliases,
7375
plot: result.deck,
7476
year: result.start_year ?? '',
7577
dataSource: this.apiName,
7678
url: result.site_detail_url,
7779
id: result.id,
7880

79-
creators: result.people?.map((x: any) => x.name) ?? [],
80-
issues: result.count_of_issues,
81-
onlineRating: result.score ?? 0,
81+
82+
authors: result.people?.map((x: any) => x.name) ?? [],
83+
chapters: result.count_of_issues,
8284
image: result.image?.original_url ?? '',
8385

8486
released: true,

src/api/apis/MALAPIManga.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type MediaDbPlugin from '../../main';
2-
import { MangaModel } from '../../models/MangaModel';
2+
import { ComicMangaModel } from '../../models/ComicMangaModel';
33
import type { MediaTypeModel } from '../../models/MediaTypeModel';
44
import { MediaType } from '../../utils/MediaType';
55
import { APIModel } from '../APIModel';
@@ -15,7 +15,7 @@ export class MALAPIManga extends APIModel {
1515
this.apiName = 'MALAPI Manga';
1616
this.apiDescription = 'A free API for Manga. Some results may take a long time to load.';
1717
this.apiUrl = 'https://jikan.moe/';
18-
this.types = [MediaType.Manga];
18+
this.types = [MediaType.ComicManga];
1919
this.typeMappings = new Map<string, string>();
2020
this.typeMappings.set('manga', 'manga');
2121
this.typeMappings.set('manhwa', 'manhwa');
@@ -45,7 +45,7 @@ export class MALAPIManga extends APIModel {
4545
for (const result of data.data) {
4646
const type = this.typeMappings.get(result.type?.toLowerCase());
4747
ret.push(
48-
new MangaModel({
48+
new ComicMangaModel({
4949
subType: type,
5050
title: result.title,
5151
plot: result.synopsis,
@@ -69,8 +69,8 @@ export class MALAPIManga extends APIModel {
6969
status: result.status,
7070

7171
userData: {
72-
watched: false,
73-
lastWatched: '',
72+
read: false,
73+
lastRead: '',
7474
personalRating: 0,
7575
},
7676
}),
@@ -95,7 +95,7 @@ export class MALAPIManga extends APIModel {
9595
const result = data.data;
9696

9797
const type = this.typeMappings.get(result.type?.toLowerCase());
98-
return new MangaModel({
98+
return new ComicMangaModel({
9999
subType: type,
100100
title: result.title,
101101
englishTitle: result.title_english ?? result.title,
@@ -120,8 +120,8 @@ export class MALAPIManga extends APIModel {
120120
status: result.status,
121121

122122
userData: {
123-
watched: false,
124-
lastWatched: '',
123+
read: false,
124+
lastRead: '',
125125
personalRating: 0,
126126
},
127127
});

src/main.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { OpenLibraryAPI } from './api/apis/OpenLibraryAPI';
1212
import { SteamAPI } from './api/apis/SteamAPI';
1313
import { WikipediaAPI } from './api/apis/WikipediaAPI';
1414
import { ComicVineAPI } from './api/apis/ComicVineAPI';
15+
import { VNDBAPI } from './api/apis/VNDBAPI';
1516
import { MediaDbFolderImportModal } from './modals/MediaDbFolderImportModal';
1617
import type { MediaTypeModel } from './models/MediaTypeModel';
1718
import { PropertyMapper } from './settings/PropertyMapper';
@@ -57,6 +58,7 @@ export default class MediaDbPlugin extends Plugin {
5758
this.apiManager.registerAPI(new ComicVineAPI(this));
5859
this.apiManager.registerAPI(new MobyGamesAPI(this));
5960
this.apiManager.registerAPI(new GiantBombAPI(this));
61+
this.apiManager.registerAPI(new VNDBAPI(this));
6062
// this.apiManager.registerAPI(new LocGovAPI(this)); // TODO: parse data
6163

6264
this.mediaTypeManager = new MediaTypeManager();
@@ -540,35 +542,37 @@ export default class MediaDbPlugin extends Plugin {
540542
if (!activeFile) {
541543
throw new Error('MDB | there is no active note');
542544
}
543-
545+
544546
let metadata = this.getMetadataFromFileCache(activeFile);
545547
metadata = this.modelPropertyMapper.convertObjectBack(metadata);
546-
548+
547549
console.debug(`MDB | read metadata`, metadata);
548-
550+
549551
if (!metadata?.type || !metadata?.dataSource || !metadata?.id) {
550552
throw new Error('MDB | active note is not a Media DB entry or is missing metadata');
551553
}
552-
554+
553555
const validOldMetadata: MediaTypeModelObj = metadata as unknown as MediaTypeModelObj;
554-
556+
console.debug(`MDB | validOldMetadata`, validOldMetadata);
557+
555558
const oldMediaTypeModel = this.mediaTypeManager.createMediaTypeModelFromMediaType(validOldMetadata, validOldMetadata.type);
556-
// console.debug(oldMediaTypeModel);
557-
559+
console.debug(`MDB | oldMediaTypeModel created`, oldMediaTypeModel);
560+
558561
let newMediaTypeModel = await this.apiManager.queryDetailedInfoById(validOldMetadata.id, validOldMetadata.dataSource);
559562
if (!newMediaTypeModel) {
560563
return;
561564
}
562-
565+
563566
newMediaTypeModel = Object.assign(oldMediaTypeModel, newMediaTypeModel.getWithOutUserData());
564-
// console.debug(newMediaTypeModel);
565-
567+
console.debug(`MDB | newMediaTypeModel after merge`, newMediaTypeModel);
568+
566569
if (onlyMetadata) {
567570
await this.createMediaDbNoteFromModel(newMediaTypeModel, { attachFile: activeFile, folder: activeFile.parent ?? undefined, openNote: true });
568571
} else {
569572
await this.createMediaDbNoteFromModel(newMediaTypeModel, { attachTemplate: true, folder: activeFile.parent ?? undefined, openNote: true });
570573
}
571574
}
575+
572576

573577
async createEntriesFromFolder(folder: TFolder): Promise<void> {
574578
const erroredFiles: { filePath: string; error: string }[] = [];

src/models/ComicMangaModel.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { MediaType } from '../utils/MediaType';
2+
import type { ModelToData } from '../utils/Utils';
3+
import { mediaDbTag, migrateObject } from '../utils/Utils';
4+
import { MediaTypeModel } from './MediaTypeModel';
5+
6+
export type ComicMangaData = ModelToData<ComicMangaModel>;
7+
8+
export class ComicMangaModel extends MediaTypeModel {
9+
plot: string;
10+
alternateTitles: string[];
11+
genres: string[];
12+
authors: string[];
13+
chapters: number;
14+
volumes: number;
15+
onlineRating: number;
16+
image: string;
17+
18+
released: boolean;
19+
status: string;
20+
publishers: string[];
21+
publishedFrom: string;
22+
publishedTo: string;
23+
24+
userData: {
25+
read: boolean;
26+
lastRead: string;
27+
personalRating: number;
28+
};
29+
30+
constructor(obj: ComicMangaData) {
31+
super();
32+
33+
this.plot = '';
34+
this.alternateTitles = [];
35+
this.genres = [];
36+
this.authors = [];
37+
this.chapters = 0;
38+
this.volumes = 0;
39+
this.onlineRating = 0;
40+
this.image = '';
41+
42+
this.released = false;
43+
this.status = '';
44+
this.publishers = [];
45+
this.publishedFrom = '';
46+
this.publishedTo = '';
47+
48+
this.userData = {
49+
read: false,
50+
lastRead: '',
51+
personalRating: 0,
52+
};
53+
54+
migrateObject(this, obj, this);
55+
56+
if (!obj.hasOwnProperty('userData')) {
57+
migrateObject(this.userData, obj, this.userData);
58+
}
59+
60+
this.type = this.getMediaType();
61+
}
62+
63+
getTags(): string[] {
64+
return [mediaDbTag, 'manga', 'light-novel', 'comicbook'];
65+
}
66+
67+
getMediaType(): MediaType {
68+
return MediaType.ComicManga;
69+
}
70+
71+
getSummary(): string {
72+
return this.title + ' (' + this.year + ')';
73+
}
74+
}

src/settings/PropertyMapper.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ export class PropertyMapper {
6262
return obj;
6363
}
6464

65-
if (MEDIA_TYPES.contains(obj.type as any)) {
65+
66+
if (obj.type === "manga") {
67+
obj.type = "comicManga";
68+
console.debug(`MDB | updated metadata type`, obj.type);
69+
}
70+
if (MEDIA_TYPES.contains(obj.type as any)) {
6671
return obj;
6772
}
6873

0 commit comments

Comments
 (0)