small fix for type name consistency
This commit is contained in:
parent
b3ff9d1a38
commit
5bdb9bdbaa
3 changed files with 44 additions and 15 deletions
|
|
@ -6,6 +6,7 @@ import {SeriesModel} from '../../models/SeriesModel';
|
||||||
|
|
||||||
export class MALAPI extends APIModel {
|
export class MALAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
|
typeMappings: Map<string, string>;
|
||||||
|
|
||||||
constructor(plugin: MediaDbPlugin) {
|
constructor(plugin: MediaDbPlugin) {
|
||||||
super();
|
super();
|
||||||
|
|
@ -15,6 +16,11 @@ export class MALAPI extends APIModel {
|
||||||
this.apiDescription = 'A free API for Anime. Some results may take a long time to load.';
|
this.apiDescription = 'A free API for Anime. Some results may take a long time to load.';
|
||||||
this.apiUrl = 'https://jikan.moe/';
|
this.apiUrl = 'https://jikan.moe/';
|
||||||
this.types = ['movie', 'series', 'anime'];
|
this.types = ['movie', 'series', 'anime'];
|
||||||
|
this.typeMappings = new Map<string, string>();
|
||||||
|
this.typeMappings.set('movie', 'movie');
|
||||||
|
this.typeMappings.set('special', 'special');
|
||||||
|
this.typeMappings.set('tv', 'series');
|
||||||
|
this.typeMappings.set('ova', 'ova');
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||||
|
|
@ -34,18 +40,22 @@ export class MALAPI extends APIModel {
|
||||||
let ret: MediaTypeModel[] = [];
|
let ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
for (const result of data.data) {
|
for (const result of data.data) {
|
||||||
if (result.type.toLowerCase() === 'movie' || result.type.toLowerCase() === 'special') {
|
const type = this.typeMappings.get(result.type.toLowerCase());
|
||||||
|
if (type === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (type === 'movie' || type === 'special') {
|
||||||
ret.push(new MovieModel({
|
ret.push(new MovieModel({
|
||||||
type: result.type,
|
type: type,
|
||||||
title: result.title,
|
title: result.title,
|
||||||
englishTitle: result.title_english ?? result.title,
|
englishTitle: result.title_english ?? result.title,
|
||||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||||
dataSource: this.apiName,
|
dataSource: this.apiName,
|
||||||
id: result.mal_id,
|
id: result.mal_id,
|
||||||
} as MovieModel));
|
} as MovieModel));
|
||||||
} else if (result.type.toLowerCase() === 'tv' || result.type.toLowerCase() === 'ova') {
|
} else if (type === 'series' || type === 'ova') {
|
||||||
ret.push(new SeriesModel({
|
ret.push(new SeriesModel({
|
||||||
type: result.type,
|
type: type,
|
||||||
title: result.title,
|
title: result.title,
|
||||||
englishTitle: result.title_english ?? result.title,
|
englishTitle: result.title_english ?? result.title,
|
||||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||||
|
|
@ -71,9 +81,14 @@ export class MALAPI extends APIModel {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
const result = data.data;
|
const result = data.data;
|
||||||
|
|
||||||
if (result.type.toLowerCase() === 'movie' || result.type.toLowerCase() === 'special') {
|
const type = this.typeMappings.get(result.type.toLowerCase());
|
||||||
|
if (type === undefined) {
|
||||||
|
throw Error(`${result.type.toLowerCase()} is an unsupported type.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'movie' || type === 'special') {
|
||||||
const model = new MovieModel({
|
const model = new MovieModel({
|
||||||
type: result.type,
|
type: type,
|
||||||
title: result.title,
|
title: result.title,
|
||||||
englishTitle: result.title_english ?? result.title,
|
englishTitle: result.title_english ?? result.title,
|
||||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||||
|
|
@ -96,9 +111,9 @@ export class MALAPI extends APIModel {
|
||||||
} as MovieModel);
|
} as MovieModel);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
} else if (result.type.toLowerCase() === 'tv' || result.type.toLowerCase() === 'ova') {
|
} else if (type === 'series' || type === 'ova') {
|
||||||
const model = new SeriesModel({
|
const model = new SeriesModel({
|
||||||
type: result.type,
|
type: type,
|
||||||
title: result.title,
|
title: result.title,
|
||||||
englishTitle: result.title_english ?? result.title,
|
englishTitle: result.title_english ?? result.title,
|
||||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {GameModel} from '../../models/GameModel';
|
||||||
|
|
||||||
export class OMDbAPI extends APIModel {
|
export class OMDbAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
|
typeMappings: Map<string, string>;
|
||||||
|
|
||||||
constructor(plugin: MediaDbPlugin) {
|
constructor(plugin: MediaDbPlugin) {
|
||||||
super();
|
super();
|
||||||
|
|
@ -16,6 +17,10 @@ export class OMDbAPI extends APIModel {
|
||||||
this.apiDescription = 'A free API for Movies, Series and Games.';
|
this.apiDescription = 'A free API for Movies, Series and Games.';
|
||||||
this.apiUrl = 'http://www.omdbapi.com/';
|
this.apiUrl = 'http://www.omdbapi.com/';
|
||||||
this.types = ['movie', 'series'];
|
this.types = ['movie', 'series'];
|
||||||
|
this.typeMappings = new Map<string, string>();
|
||||||
|
this.typeMappings.set('movie', 'movie');
|
||||||
|
this.typeMappings.set('series', 'series');
|
||||||
|
this.typeMappings.set('game', 'game');
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||||
|
|
@ -46,6 +51,10 @@ export class OMDbAPI extends APIModel {
|
||||||
let ret: MediaTypeModel[] = [];
|
let ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
for (const result of data.Search) {
|
for (const result of data.Search) {
|
||||||
|
const type = this.typeMappings.get(result.type.toLowerCase());
|
||||||
|
if (type === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (result.Type === 'movie') {
|
if (result.Type === 'movie') {
|
||||||
ret.push(new MovieModel({
|
ret.push(new MovieModel({
|
||||||
type: 'movie',
|
type: 'movie',
|
||||||
|
|
@ -99,9 +108,14 @@ export class OMDbAPI extends APIModel {
|
||||||
throw Error(`Received error from ${this.apiName}: ${result.Error}`);
|
throw Error(`Received error from ${this.apiName}: ${result.Error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.Type === 'movie') {
|
const type = this.typeMappings.get(result.type.toLowerCase());
|
||||||
|
if (type === undefined) {
|
||||||
|
throw Error(`${result.type.toLowerCase()} is an unsupported type.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'movie') {
|
||||||
const model = new MovieModel({
|
const model = new MovieModel({
|
||||||
type: 'movie',
|
type: type,
|
||||||
title: result.Title,
|
title: result.Title,
|
||||||
englishTitle: result.Title,
|
englishTitle: result.Title,
|
||||||
year: result.Year,
|
year: result.Year,
|
||||||
|
|
@ -124,9 +138,9 @@ export class OMDbAPI extends APIModel {
|
||||||
} as MovieModel);
|
} as MovieModel);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
} else if (result.Type === 'series') {
|
} else if (type === 'series') {
|
||||||
const model = new SeriesModel({
|
const model = new SeriesModel({
|
||||||
type: 'series',
|
type: type,
|
||||||
title: result.Title,
|
title: result.Title,
|
||||||
englishTitle: result.Title,
|
englishTitle: result.Title,
|
||||||
year: result.Year,
|
year: result.Year,
|
||||||
|
|
@ -152,9 +166,9 @@ export class OMDbAPI extends APIModel {
|
||||||
} as SeriesModel);
|
} as SeriesModel);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
} else if (result.Type === 'game') {
|
} else if (type === 'game') {
|
||||||
const model = new GameModel({
|
const model = new GameModel({
|
||||||
type: 'game',
|
type: type,
|
||||||
title: result.Title,
|
title: result.Title,
|
||||||
englishTitle: result.Title,
|
englishTitle: result.Title,
|
||||||
year: result.Year,
|
year: result.Year,
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ export function getFileName(item: MediaTypeModel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function replaceIllegalFileNameCharactersInString(string: string) {
|
export function replaceIllegalFileNameCharactersInString(string: string) {
|
||||||
return string.replace(/[\\,#%&{}/*<>$"@.]*/g, '').replace(/:+/g, ' -');
|
return string.replace(/[\\,#%&{}/*<>$"@.?]*/g, '').replace(/:+/g, ' -');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function replaceTags(template: string, mediaTypeModel: MediaTypeModel): string {
|
export function replaceTags(template: string, mediaTypeModel: MediaTypeModel): string {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue