games, english anime titles, specials and OVAs
This commit is contained in:
parent
c400b7abf5
commit
d2afe3bcc2
10 changed files with 141 additions and 42 deletions
|
|
@ -1,30 +1,30 @@
|
|||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
|
||||
export abstract class APIModel {
|
||||
apiName: string;
|
||||
apiUrl: string;
|
||||
apiDescription: string;
|
||||
types: string[];
|
||||
apiName: string;
|
||||
apiUrl: string;
|
||||
apiDescription: string;
|
||||
types: string[];
|
||||
|
||||
/**
|
||||
* This function should query the api and return a list of matches. The matches should be caped at 20.
|
||||
*
|
||||
* @param title the title to query for
|
||||
*/
|
||||
abstract searchByTitle(title: string): Promise<MediaTypeModel[]>;
|
||||
/**
|
||||
* This function should query the api and return a list of matches. The matches should be caped at 20.
|
||||
*
|
||||
* @param title the title to query for
|
||||
*/
|
||||
abstract searchByTitle(title: string): Promise<MediaTypeModel[]>;
|
||||
|
||||
abstract getById(item: MediaTypeModel): Promise<MediaTypeModel>;
|
||||
abstract getById(item: MediaTypeModel): Promise<MediaTypeModel>;
|
||||
|
||||
hasType(type: string): boolean {
|
||||
return this.types.contains(type);
|
||||
}
|
||||
hasType(type: string): boolean {
|
||||
return this.types.contains(type);
|
||||
}
|
||||
|
||||
hasTypeOverlap(types: string[]): boolean {
|
||||
for (const type of types) {
|
||||
if (this.hasType(type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
hasTypeOverlap(types: string[]): boolean {
|
||||
for (const type of types) {
|
||||
if (this.hasType(type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ import {APIModel} from '../APIModel';
|
|||
import {MediaTypeModel} from '../../models/MediaTypeModel';
|
||||
import {MovieModel} from '../../models/MovieModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
// @ts-ignore
|
||||
import Jikanjs from '@mateoaranda/jikanjs';
|
||||
import {SeriesModel} from '../../models/SeriesModel';
|
||||
|
||||
export class MALAPI extends APIModel {
|
||||
|
|
@ -36,18 +34,20 @@ export class MALAPI extends APIModel {
|
|||
let ret: MediaTypeModel[] = [];
|
||||
|
||||
for (const result of data.data) {
|
||||
if (result.type.toLowerCase() === 'movie') {
|
||||
if (result.type.toLowerCase() === 'movie' || result.type.toLowerCase() === 'special') {
|
||||
ret.push(new MovieModel({
|
||||
type: result.type,
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||
dataSource: this.apiName,
|
||||
id: result.mal_id,
|
||||
} as MovieModel));
|
||||
} else if (result.type.toLowerCase() === 'tv') {
|
||||
} else if (result.type.toLowerCase() === 'tv' || result.type.toLowerCase() === 'ova') {
|
||||
ret.push(new SeriesModel({
|
||||
type: result.type,
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||
dataSource: this.apiName,
|
||||
id: result.mal_id,
|
||||
|
|
@ -71,10 +71,11 @@ export class MALAPI extends APIModel {
|
|||
console.log(data);
|
||||
const result = data.data;
|
||||
|
||||
if (result.type.toLowerCase() === 'movie') {
|
||||
if (result.type.toLowerCase() === 'movie' || result.type.toLowerCase() === 'special') {
|
||||
const model = new MovieModel({
|
||||
type: result.type,
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||
dataSource: this.apiName,
|
||||
url: result.url,
|
||||
|
|
@ -95,10 +96,11 @@ export class MALAPI extends APIModel {
|
|||
} as MovieModel);
|
||||
|
||||
return model;
|
||||
} else if (result.type.toLowerCase() === 'tv') {
|
||||
} else if (result.type.toLowerCase() === 'tv' || result.type.toLowerCase() === 'ova') {
|
||||
const model = new SeriesModel({
|
||||
type: result.type,
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||
dataSource: this.apiName,
|
||||
url: result.url,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {MediaTypeModel} from '../../models/MediaTypeModel';
|
|||
import {MovieModel} from '../../models/MovieModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
import {SeriesModel} from '../../models/SeriesModel';
|
||||
import {GameModel} from '../../models/GameModel';
|
||||
|
||||
export class OMDbAPI extends APIModel {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -12,7 +13,7 @@ export class OMDbAPI extends APIModel {
|
|||
|
||||
this.plugin = plugin;
|
||||
this.apiName = 'OMDbAPI';
|
||||
this.apiDescription = 'A free API for Movies and Series.';
|
||||
this.apiDescription = 'A free API for Movies, Series and Games.';
|
||||
this.apiUrl = 'http://www.omdbapi.com/';
|
||||
this.types = ['movie', 'series'];
|
||||
}
|
||||
|
|
@ -44,23 +45,34 @@ export class OMDbAPI extends APIModel {
|
|||
|
||||
let ret: MediaTypeModel[] = [];
|
||||
|
||||
for (const value of data.Search) {
|
||||
if (value.Type === 'movie') {
|
||||
for (const result of data.Search) {
|
||||
if (result.Type === 'movie') {
|
||||
ret.push(new MovieModel({
|
||||
type: 'movie',
|
||||
title: value.Title,
|
||||
year: value.Year,
|
||||
title: result.Title,
|
||||
englishTitle: result.Title,
|
||||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
id: value.imdbID,
|
||||
id: result.imdbID,
|
||||
} as MovieModel));
|
||||
} else if (value.Type === 'series') {
|
||||
} else if (result.Type === 'series') {
|
||||
ret.push(new SeriesModel({
|
||||
type: 'series',
|
||||
title: value.Title,
|
||||
year: value.Year,
|
||||
title: result.Title,
|
||||
englishTitle: result.Title,
|
||||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
id: value.imdbID,
|
||||
id: result.imdbID,
|
||||
} as SeriesModel));
|
||||
} else if (result.Type === 'game') {
|
||||
ret.push(new GameModel({
|
||||
type: 'game',
|
||||
title: result.Title,
|
||||
englishTitle: result.Title,
|
||||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
id: result.imdbID,
|
||||
} as GameModel));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -91,6 +103,7 @@ export class OMDbAPI extends APIModel {
|
|||
const model = new MovieModel({
|
||||
type: 'movie',
|
||||
title: result.Title,
|
||||
englishTitle: result.Title,
|
||||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
url: `https://www.imdb.com/title/${result.imdbID}/`,
|
||||
|
|
@ -115,6 +128,7 @@ export class OMDbAPI extends APIModel {
|
|||
const model = new SeriesModel({
|
||||
type: 'series',
|
||||
title: result.Title,
|
||||
englishTitle: result.Title,
|
||||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
url: `https://www.imdb.com/title/${result.imdbID}/`,
|
||||
|
|
@ -137,6 +151,28 @@ export class OMDbAPI extends APIModel {
|
|||
personalRating: 0,
|
||||
} as SeriesModel);
|
||||
|
||||
return model;
|
||||
} else if (result.Type === 'game') {
|
||||
const model = new GameModel({
|
||||
type: 'game',
|
||||
title: result.Title,
|
||||
englishTitle: result.Title,
|
||||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
url: `https://www.imdb.com/title/${result.imdbID}/`,
|
||||
id: result.imdbID,
|
||||
|
||||
genres: result.Genre?.split(', ') ?? [],
|
||||
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
|
||||
image: result.Poster ?? '',
|
||||
|
||||
released: true,
|
||||
releaseDate: (new Date(result.Released)).toLocaleDateString() ?? 'unknown',
|
||||
|
||||
played: false,
|
||||
personalRating: 0,
|
||||
} as GameModel);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue