Merge branch 'master' into feat/vndb
This commit is contained in:
commit
86f003b916
9 changed files with 175 additions and 35 deletions
98
src/api/apis/ComicVineAPI.ts
Normal file
98
src/api/apis/ComicVineAPI.ts
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
import { requestUrl } from 'obsidian';
|
||||
import { ComicMangaModel } from 'src/models/ComicMangaModel';
|
||||
import type MediaDbPlugin from '../../main';
|
||||
import type { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import { MediaType } from '../../utils/MediaType';
|
||||
import { APIModel } from '../APIModel';
|
||||
|
||||
export class ComicVineAPI extends APIModel {
|
||||
plugin: MediaDbPlugin;
|
||||
|
||||
constructor(plugin: MediaDbPlugin) {
|
||||
super();
|
||||
|
||||
this.plugin = plugin;
|
||||
this.apiName = 'ComicVineAPI';
|
||||
this.apiDescription = 'A free API for comic books.';
|
||||
this.apiUrl = 'https://comicvine.gamespot.com/api';
|
||||
this.types = [MediaType.ComicManga];
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
const searchUrl = `${this.apiUrl}/search/?api_key=${this.plugin.settings.ComicVineKey}&format=json&resources=volume&query=${encodeURIComponent(title)}`;
|
||||
const fetchData = await requestUrl({
|
||||
url: searchUrl,
|
||||
});
|
||||
// console.debug(fetchData);
|
||||
if (fetchData.status !== 200) {
|
||||
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
|
||||
}
|
||||
|
||||
const data = await fetchData.json;
|
||||
// console.debug(data);
|
||||
const ret: MediaTypeModel[] = [];
|
||||
for (const result of data.results) {
|
||||
ret.push(
|
||||
new ComicMangaModel({
|
||||
title: result.name,
|
||||
englishTitle: result.name,
|
||||
year: result.start_year,
|
||||
dataSource: this.apiName,
|
||||
id: `4050-${result.id}`,
|
||||
publishers: result.publisher?.name ?? [],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<MediaTypeModel> {
|
||||
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
const searchUrl = `${this.apiUrl}/volume/${encodeURIComponent(id)}/?api_key=${this.plugin.settings.ComicVineKey}&format=json`;
|
||||
const fetchData = await requestUrl({
|
||||
url: searchUrl,
|
||||
});
|
||||
|
||||
console.debug(fetchData);
|
||||
|
||||
if (fetchData.status !== 200) {
|
||||
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
|
||||
}
|
||||
|
||||
const data = await fetchData.json;
|
||||
// console.debug(data);
|
||||
const result = data.results;
|
||||
|
||||
return new ComicMangaModel({
|
||||
type: MediaType.ComicManga,
|
||||
title: result.name,
|
||||
englishTitle: result.name,
|
||||
alternateTitles: result.aliases,
|
||||
plot: result.deck,
|
||||
year: result.start_year ?? '',
|
||||
dataSource: this.apiName,
|
||||
url: result.site_detail_url,
|
||||
id: `4050-${result.id}`,
|
||||
|
||||
authors: result.people?.map((x: any) => x.name) ?? [],
|
||||
chapters: result.count_of_issues,
|
||||
image: result.image?.original_url ?? '',
|
||||
|
||||
released: true,
|
||||
publishers: result.publisher?.name ?? [],
|
||||
publishedFrom: result.start_year ?? 'unknown',
|
||||
publishedTo: 'unknown',
|
||||
status: result.status,
|
||||
|
||||
userData: {
|
||||
read: false,
|
||||
lastRead: '',
|
||||
personalRating: 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import type MediaDbPlugin from '../../main';
|
||||
import { MangaModel } from '../../models/MangaModel';
|
||||
import { ComicMangaModel } from '../../models/ComicMangaModel';
|
||||
import type { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import { MediaType } from '../../utils/MediaType';
|
||||
import { APIModel } from '../APIModel';
|
||||
|
|
@ -15,7 +15,7 @@ export class MALAPIManga extends APIModel {
|
|||
this.apiName = 'MALAPI Manga';
|
||||
this.apiDescription = 'A free API for Manga. Some results may take a long time to load.';
|
||||
this.apiUrl = 'https://jikan.moe/';
|
||||
this.types = [MediaType.Manga];
|
||||
this.types = [MediaType.ComicManga];
|
||||
this.typeMappings = new Map<string, string>();
|
||||
this.typeMappings.set('manga', 'manga');
|
||||
this.typeMappings.set('manhwa', 'manhwa');
|
||||
|
|
@ -45,7 +45,7 @@ export class MALAPIManga extends APIModel {
|
|||
for (const result of data.data) {
|
||||
const type = this.typeMappings.get(result.type?.toLowerCase());
|
||||
ret.push(
|
||||
new MangaModel({
|
||||
new ComicMangaModel({
|
||||
subType: type,
|
||||
title: result.title,
|
||||
plot: result.synopsis,
|
||||
|
|
@ -69,8 +69,8 @@ export class MALAPIManga extends APIModel {
|
|||
status: result.status,
|
||||
|
||||
userData: {
|
||||
watched: false,
|
||||
lastWatched: '',
|
||||
read: false,
|
||||
lastRead: '',
|
||||
personalRating: 0,
|
||||
},
|
||||
}),
|
||||
|
|
@ -95,7 +95,7 @@ export class MALAPIManga extends APIModel {
|
|||
const result = data.data;
|
||||
|
||||
const type = this.typeMappings.get(result.type?.toLowerCase());
|
||||
return new MangaModel({
|
||||
return new ComicMangaModel({
|
||||
subType: type,
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
|
|
@ -114,13 +114,14 @@ export class MALAPIManga extends APIModel {
|
|||
image: result.images?.jpg?.image_url ?? '',
|
||||
|
||||
released: true,
|
||||
publishers: result.serializations?.map((x: any) => x.name) ?? [],
|
||||
publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown',
|
||||
publishedTo: new Date(result.published?.to).toLocaleDateString() ?? 'unknown',
|
||||
status: result.status,
|
||||
|
||||
userData: {
|
||||
watched: false,
|
||||
lastWatched: '',
|
||||
read: false,
|
||||
lastRead: '',
|
||||
personalRating: 0,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue