more stuff
This commit is contained in:
parent
42610459d5
commit
c7a75ff93c
5 changed files with 55 additions and 9 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {App, ButtonComponent, Component, Modal, Setting, TextComponent, ToggleComponent} from 'obsidian';
|
||||
import {App, ButtonComponent, Component, Modal, Notice, Setting, TextComponent, ToggleComponent} from 'obsidian';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import {APIManager} from '../api/APIManager';
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ export class MediaDbAdvancedSearchModal extends Modal {
|
|||
this.onSubmit = onSubmit;
|
||||
this.selectedApis = [];
|
||||
for (const api of this.apiManager.apis) {
|
||||
this.selectedApis[api.apiName] = true;
|
||||
this.selectedApis[api.apiName] = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +30,20 @@ export class MediaDbAdvancedSearchModal extends Modal {
|
|||
|
||||
console.log(this.selectedApis);
|
||||
|
||||
if (!this.query) {
|
||||
if (!this.query || this.query.length < 5) {
|
||||
new Notice("MDB: Query to short");
|
||||
return;
|
||||
}
|
||||
|
||||
let selectedAPICount = 0;
|
||||
for (const api in this.selectedApis) {
|
||||
if (this.selectedApis[api]) {
|
||||
selectedAPICount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedAPICount === 0) {
|
||||
new Notice("MDB: No API selected");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,13 @@ import {FolderSuggest} from './suggesters/FolderSuggester';
|
|||
|
||||
export interface MediaDbPluginSettings {
|
||||
folder: string,
|
||||
sfwFilter: boolean,
|
||||
OMDbKey: string,
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||
folder: '',
|
||||
sfwFilter: true,
|
||||
OMDbKey: '',
|
||||
};
|
||||
|
||||
|
|
@ -53,6 +55,17 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('SFW filter')
|
||||
.setDesc('Only shows SFW results for APIs that offer filtering.')
|
||||
.addToggle(cb => {
|
||||
cb.setValue(this.plugin.settings.sfwFilter)
|
||||
.onChange(data => {
|
||||
this.plugin.settings.sfwFilter = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,5 +13,5 @@ export function getFileName(item: MediaTypeModel) {
|
|||
}
|
||||
|
||||
export function replaceIllegalFileNameCharactersInString(string: string) {
|
||||
return string.replace(/[\\,#%&{}/*<>$":@.]*/g, '');
|
||||
return string.replace(/[\\,#%&{}/*<>$"@.]*/g, '').replace(/:+/g, ' -');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue