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
|
|
@ -2,8 +2,6 @@ import {APIModel} from '../APIModel';
|
||||||
import {MediaTypeModel} from '../../models/MediaTypeModel';
|
import {MediaTypeModel} from '../../models/MediaTypeModel';
|
||||||
import {MovieModel} from '../../models/MovieModel';
|
import {MovieModel} from '../../models/MovieModel';
|
||||||
import MediaDbPlugin from '../../main';
|
import MediaDbPlugin from '../../main';
|
||||||
// @ts-ignore
|
|
||||||
import Jikanjs from '@mateoaranda/jikanjs';
|
|
||||||
import {SeriesModel} from '../../models/SeriesModel';
|
import {SeriesModel} from '../../models/SeriesModel';
|
||||||
|
|
||||||
export class MALAPI extends APIModel {
|
export class MALAPI extends APIModel {
|
||||||
|
|
@ -36,18 +34,20 @@ 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') {
|
if (result.type.toLowerCase() === 'movie' || result.type.toLowerCase() === 'special') {
|
||||||
ret.push(new MovieModel({
|
ret.push(new MovieModel({
|
||||||
type: result.type,
|
type: result.type,
|
||||||
title: result.title,
|
title: 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') {
|
} else if (result.type.toLowerCase() === 'tv' || result.type.toLowerCase() === 'ova') {
|
||||||
ret.push(new SeriesModel({
|
ret.push(new SeriesModel({
|
||||||
type: result.type,
|
type: result.type,
|
||||||
title: result.title,
|
title: 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,
|
||||||
|
|
@ -71,10 +71,11 @@ export class MALAPI extends APIModel {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
const result = data.data;
|
const result = data.data;
|
||||||
|
|
||||||
if (result.type.toLowerCase() === 'movie') {
|
if (result.type.toLowerCase() === 'movie' || result.type.toLowerCase() === 'special') {
|
||||||
const model = new MovieModel({
|
const model = new MovieModel({
|
||||||
type: result.type,
|
type: result.type,
|
||||||
title: result.title,
|
title: 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,
|
||||||
url: result.url,
|
url: result.url,
|
||||||
|
|
@ -95,10 +96,11 @@ export class MALAPI extends APIModel {
|
||||||
} as MovieModel);
|
} as MovieModel);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
} else if (result.type.toLowerCase() === 'tv') {
|
} else if (result.type.toLowerCase() === 'tv' || result.type.toLowerCase() === 'ova') {
|
||||||
const model = new SeriesModel({
|
const model = new SeriesModel({
|
||||||
type: result.type,
|
type: result.type,
|
||||||
title: result.title,
|
title: 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,
|
||||||
url: result.url,
|
url: result.url,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {MediaTypeModel} from '../../models/MediaTypeModel';
|
||||||
import {MovieModel} from '../../models/MovieModel';
|
import {MovieModel} from '../../models/MovieModel';
|
||||||
import MediaDbPlugin from '../../main';
|
import MediaDbPlugin from '../../main';
|
||||||
import {SeriesModel} from '../../models/SeriesModel';
|
import {SeriesModel} from '../../models/SeriesModel';
|
||||||
|
import {GameModel} from '../../models/GameModel';
|
||||||
|
|
||||||
export class OMDbAPI extends APIModel {
|
export class OMDbAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
|
|
@ -12,7 +13,7 @@ export class OMDbAPI extends APIModel {
|
||||||
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.apiName = 'OMDbAPI';
|
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.apiUrl = 'http://www.omdbapi.com/';
|
||||||
this.types = ['movie', 'series'];
|
this.types = ['movie', 'series'];
|
||||||
}
|
}
|
||||||
|
|
@ -44,23 +45,34 @@ export class OMDbAPI extends APIModel {
|
||||||
|
|
||||||
let ret: MediaTypeModel[] = [];
|
let ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
for (const value of data.Search) {
|
for (const result of data.Search) {
|
||||||
if (value.Type === 'movie') {
|
if (result.Type === 'movie') {
|
||||||
ret.push(new MovieModel({
|
ret.push(new MovieModel({
|
||||||
type: 'movie',
|
type: 'movie',
|
||||||
title: value.Title,
|
title: result.Title,
|
||||||
year: value.Year,
|
englishTitle: result.Title,
|
||||||
|
year: result.Year,
|
||||||
dataSource: this.apiName,
|
dataSource: this.apiName,
|
||||||
id: value.imdbID,
|
id: result.imdbID,
|
||||||
} as MovieModel));
|
} as MovieModel));
|
||||||
} else if (value.Type === 'series') {
|
} else if (result.Type === 'series') {
|
||||||
ret.push(new SeriesModel({
|
ret.push(new SeriesModel({
|
||||||
type: 'series',
|
type: 'series',
|
||||||
title: value.Title,
|
title: result.Title,
|
||||||
year: value.Year,
|
englishTitle: result.Title,
|
||||||
|
year: result.Year,
|
||||||
dataSource: this.apiName,
|
dataSource: this.apiName,
|
||||||
id: value.imdbID,
|
id: result.imdbID,
|
||||||
} as SeriesModel));
|
} 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({
|
const model = new MovieModel({
|
||||||
type: 'movie',
|
type: 'movie',
|
||||||
title: result.Title,
|
title: result.Title,
|
||||||
|
englishTitle: result.Title,
|
||||||
year: result.Year,
|
year: result.Year,
|
||||||
dataSource: this.apiName,
|
dataSource: this.apiName,
|
||||||
url: `https://www.imdb.com/title/${result.imdbID}/`,
|
url: `https://www.imdb.com/title/${result.imdbID}/`,
|
||||||
|
|
@ -115,6 +128,7 @@ export class OMDbAPI extends APIModel {
|
||||||
const model = new SeriesModel({
|
const model = new SeriesModel({
|
||||||
type: 'series',
|
type: 'series',
|
||||||
title: result.Title,
|
title: result.Title,
|
||||||
|
englishTitle: result.Title,
|
||||||
year: result.Year,
|
year: result.Year,
|
||||||
dataSource: this.apiName,
|
dataSource: this.apiName,
|
||||||
url: `https://www.imdb.com/title/${result.imdbID}/`,
|
url: `https://www.imdb.com/title/${result.imdbID}/`,
|
||||||
|
|
@ -137,6 +151,28 @@ export class OMDbAPI extends APIModel {
|
||||||
personalRating: 0,
|
personalRating: 0,
|
||||||
} as SeriesModel);
|
} 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;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,13 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
// console.log(template);
|
// console.log(template);
|
||||||
fileContent += template;
|
fileContent += template;
|
||||||
}
|
}
|
||||||
|
} else if (data.type === 'game' && this.settings.seriesTemplate) {
|
||||||
|
const templateFile = this.app.vault.getFiles().filter((f: TFile) => f.name === this.settings.gameTemplate).first();
|
||||||
|
if (templateFile) {
|
||||||
|
let template = await this.app.vault.read(templateFile);
|
||||||
|
// console.log(template);
|
||||||
|
fileContent += template;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileName = replaceIllegalFileNameCharactersInString(data.getFileName());
|
const fileName = replaceIllegalFileNameCharactersInString(data.getFileName());
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ export class MediaDbSearchResultModal extends SuggestModal<MediaTypeModel> {
|
||||||
// Renders each suggestion item.
|
// Renders each suggestion item.
|
||||||
renderSuggestion(item: MediaTypeModel, el: HTMLElement) {
|
renderSuggestion(item: MediaTypeModel, el: HTMLElement) {
|
||||||
el.createEl('div', {text: item.getFileName()});
|
el.createEl('div', {text: item.getFileName()});
|
||||||
|
el.createEl('small', {text: `${item.englishTitle}\n`});
|
||||||
el.createEl('small', {text: `${item.type.toUpperCase()} from ${item.dataSource}`});
|
el.createEl('small', {text: `${item.type.toUpperCase()} from ${item.dataSource}`});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
39
src/models/GameModel.ts
Normal file
39
src/models/GameModel.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import {MediaTypeModel} from './MediaTypeModel';
|
||||||
|
import {stringifyYaml} from 'obsidian';
|
||||||
|
|
||||||
|
|
||||||
|
export class GameModel extends MediaTypeModel {
|
||||||
|
type: string;
|
||||||
|
title: string;
|
||||||
|
englishTitle: string;
|
||||||
|
year: string;
|
||||||
|
dataSource: string;
|
||||||
|
url: string;
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
genres: string[];
|
||||||
|
onlineRating: number;
|
||||||
|
image: string;
|
||||||
|
|
||||||
|
released: boolean;
|
||||||
|
releaseDate: string;
|
||||||
|
|
||||||
|
played: boolean;
|
||||||
|
personalRating: number;
|
||||||
|
|
||||||
|
|
||||||
|
constructor(obj: any = {}) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
Object.assign(this, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
toMetaData(): string {
|
||||||
|
return stringifyYaml(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
getFileName(): string {
|
||||||
|
return this.title + (this.year ? ` (${this.year})` : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
export abstract class MediaTypeModel {
|
export abstract class MediaTypeModel {
|
||||||
type: string;
|
type: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
englishTitle: string;
|
||||||
year: string;
|
year: string;
|
||||||
dataSource: string;
|
dataSource: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import {stringifyYaml} from 'obsidian';
|
||||||
export class MovieModel extends MediaTypeModel {
|
export class MovieModel extends MediaTypeModel {
|
||||||
type: string;
|
type: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
englishTitle: string;
|
||||||
year: string;
|
year: string;
|
||||||
dataSource: string;
|
dataSource: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
|
@ -28,8 +29,6 @@ export class MovieModel extends MediaTypeModel {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
Object.assign(this, obj);
|
Object.assign(this, obj);
|
||||||
|
|
||||||
this.type = 'movie';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toMetaData(): string {
|
toMetaData(): string {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import {stringifyYaml} from 'obsidian';
|
||||||
export class SeriesModel extends MediaTypeModel {
|
export class SeriesModel extends MediaTypeModel {
|
||||||
type: string;
|
type: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
englishTitle: string;
|
||||||
year: string;
|
year: string;
|
||||||
dataSource: string;
|
dataSource: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
|
@ -31,8 +32,6 @@ export class SeriesModel extends MediaTypeModel {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
Object.assign(this, obj);
|
Object.assign(this, obj);
|
||||||
|
|
||||||
this.type = 'series';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toMetaData(): string {
|
toMetaData(): string {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ export interface MediaDbPluginSettings {
|
||||||
OMDbKey: string,
|
OMDbKey: string,
|
||||||
movieTemplate: string,
|
movieTemplate: string,
|
||||||
seriesTemplate: string,
|
seriesTemplate: string,
|
||||||
|
gameTemplate: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
export const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
|
|
@ -19,6 +20,7 @@ export const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
OMDbKey: '',
|
OMDbKey: '',
|
||||||
movieTemplate: '',
|
movieTemplate: '',
|
||||||
seriesTemplate: '',
|
seriesTemplate: '',
|
||||||
|
gameTemplate: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export class MediaDbSettingTab extends PluginSettingTab {
|
export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
|
|
@ -75,6 +77,19 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Game template')
|
||||||
|
.setDesc('Template file to be used when creating a new note for a game.')
|
||||||
|
.addSearch(cb => {
|
||||||
|
new FileSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder('Example: gameTemplate.md')
|
||||||
|
.setValue(this.plugin.settings.gameTemplate)
|
||||||
|
.onChange(data => {
|
||||||
|
this.plugin.settings.gameTemplate = data;
|
||||||
|
this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('OMDb API key')
|
.setName('OMDb API key')
|
||||||
.setDesc('API key for "www.omdbapi.com".')
|
.setDesc('API key for "www.omdbapi.com".')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue