more stuff

This commit is contained in:
mProjectsCode 2022-05-06 23:45:22 +02:00
parent 42610459d5
commit c7a75ff93c
5 changed files with 55 additions and 9 deletions

View file

@ -13,7 +13,7 @@ export class MALAPI extends APIModel {
this.plugin = plugin;
this.apiName = 'MALAPI';
this.apiDescription = 'A free API for Anime.';
this.apiDescription = 'A free API for Anime. Some results may take a long time to load.';
this.apiUrl = 'https://jikan.moe/';
this.types = ['movie', 'series', 'anime'];
}
@ -62,18 +62,31 @@ export class MALAPI extends APIModel {
console.log(data);
const result = data.data;
// if (data.Type === 'movie') {
if (result.type === 'Movie') {
const model = new MovieModel({
type: result.type,
title: result.title,
year: result.year,
year: result.year ?? result.aired?.prop?.from?.year ?? '',
dataSource: this.apiName,
id: result.mal_id,
genres: result.genres?.map((x: any) => x.name) ?? [],
producer: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown',
duration: result.duration ?? 'unknown',
onlineRating: result.score ?? 0,
image: result.images?.jpg?.image_url ?? '',
released: true,
premiere: result.aired?.string ?? 'unknown',
watched: false,
lastWatched: '',
personalRating: 0,
} as MovieModel);
return model;
// }
}
// return;
return;
}
}

View file

@ -22,6 +22,10 @@ export class OMDbAPI extends APIModel {
const searchUrl = `http://www.omdbapi.com/?s=${title}&apikey=${this.plugin.settings.OMDbKey}`;
const fetchData = await fetch(searchUrl);
if (fetchData.status === 401) {
throw Error(`Authentication for ${this.apiName} failed. Check the API key.`);
}
if (fetchData.status !== 200) {
throw Error(`Received status code ${fetchData.status} from an API.`);
}
@ -55,6 +59,9 @@ export class OMDbAPI extends APIModel {
const searchUrl = `http://www.omdbapi.com/?i=${item.id}&apikey=${this.plugin.settings.OMDbKey}`;
const fetchData = await fetch(searchUrl);
if (fetchData.status === 401) {
throw Error(`Authentication for ${this.apiName} failed. Check the API key.`);
}
if (fetchData.status !== 200) {
throw Error(`Received status code ${fetchData.status} from an API.`);
}