Skip to content

Restored and updated the api toggle + added a download option for poster images #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ Now you select the result you want and the plugin will cast it's magic and creat

### Currently supported APIs:


| Name | Description | Supported formats | Authentification | Rate limiting | SFW filter support |
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
| [Jikan](https://jikan.moe/) | Jikan is an API that uses [My Anime List](https://myanimelist.net) and offers metadata for anime. | series, movies, specials, OVAs, manga, manwha, novels | No | 60 per minute and 3 per second | Yes |
Expand All @@ -124,7 +123,7 @@ Now you select the result you want and the plugin will cast it's magic and creat
| [Open Library](https://openlibrary.org) | The OpenLibrary API offers metadata for books | books | No | Cover access is rate-limited when not using CoverID or OLID by max 100 requests/IP every 5 minutes. This plugin uses OLID so there shouldn't be a rate limit. | No |
| [Moby Games](https://www.mobygames.com) | The Moby Games API offers metadata for games for all platforms | games | Yes, by making an account [here](https://www.mobygames.com/user/register/). NOTE: As of September 2024 the API key is no longer free so consider using Giant Bomb or steam instead | API requests are limited to 360 per hour (one every ten seconds). In addition, requests should be made no more frequently than one per second. | No |
| [Giant Bomb](https://www.giantbomb.com) | The Giant Bomb API offers metadata for games for all platforms | games | Yes, by making an account [here](https://www.giantbomb.com/login-signup/) | API requests are limited to 200 requests per resource, per hour. In addition, they implement velocity detection to prevent malicious use. If too many requests are made per second, you may receive temporary blocks to resources. | No |
| Comic Vine | The Comic Vine API offers metadata for comic books | comicbooks | Yes, by making an account [here](https://comicvine.gamespot.com/login-signup/) and going to the [api section](https://comicvine.gamespot.com/api/) of the site | 200 requests per resource, per hour. There is also a velocity detection to prevent malicious use. If too many requests are made per second, you may receive temporary blocks to resources. | No
| Comic Vine | The Comic Vine API offers metadata for comic books | comicbooks | Yes, by making an account [here](https://comicvine.gamespot.com/login-signup/) and going to the [api section](https://comicvine.gamespot.com/api/) of the site | 200 requests per resource, per hour. There is also a velocity detection to prevent malicious use. If too many requests are made per second, you may receive temporary blocks to resources. | No |

#### Notes

Expand Down
11 changes: 3 additions & 8 deletions src/api/APIModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export abstract class APIModel {
plugin!: MediaDbPlugin;

/**
* This function should query the api and return a list of matches. The matches should be caped at 20.
* This function should query the api and return a list of matches. The matches should be capped at 20.
*
* @param title the title to query for
*/
Expand All @@ -19,13 +19,8 @@ export abstract class APIModel {
abstract getById(id: string): Promise<MediaTypeModel>;

hasType(type: MediaType): boolean {
// if (
// this.types.contains(type) &&
// (Boolean((this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type]) === true || (this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type] === undefined)
// ) {
// return true;
// }
return this.types.contains(type);
const disabledMediaTypes = this.plugin.settings[`${this.apiName}_disabledMediaTypes` as keyof typeof this.plugin.settings] as MediaType[];
return this.types.includes(type) && !disabledMediaTypes.includes(type);
}

hasTypeOverlap(types: MediaType[]): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/api/apis/MALAPIManga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class MALAPIManga extends APIModel {
super();

this.plugin = plugin;
this.apiName = 'MALAPI Manga';
this.apiName = 'MALAPIManga';
this.apiDescription = 'A free API for Manga. Some results may take a long time to load.';
this.apiUrl = 'https://jikan.moe/';
this.types = [MediaType.ComicManga];
Expand Down
4 changes: 4 additions & 0 deletions src/settings/PropertyMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export class PropertyMapper {
obj.type = 'comicManga';
console.debug(`MDB | updated metadata type`, obj.type);
}
if (obj.dataSource === 'MALAPI Manga') {
obj.dataSource = 'MALAPIManga';
console.debug(`MDB | updated metadata dataSource`, obj.type);
}
if (MEDIA_TYPES.contains(obj.type as any)) {
return obj;
}
Expand Down
176 changes: 64 additions & 112 deletions src/settings/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mount } from 'svelte';
import type MediaDbPlugin from '../main';
import type { MediaTypeModel } from '../models/MediaTypeModel';
import { MEDIA_TYPES } from '../utils/MediaTypeManager';
import { fragWithHTML } from '../utils/Utils';
import { fragWithHTML, unCamelCase } from '../utils/Utils';
import { PropertyMapping, PropertyMappingModel, PropertyMappingOption } from './PropertyMapping';
import PropertyMappingModelsComponent from './PropertyMappingModelsComponent.svelte';
import { FileSuggest } from './suggesters/FileSuggest';
Expand All @@ -21,24 +21,13 @@ export interface MediaDbPluginSettings {
openNoteInNewTab: boolean;
useDefaultFrontMatter: boolean;
enableTemplaterIntegration: boolean;
// TODO: disabled for now, as i currently don't have the time to fix this from the original PR that introduced it (#133)
// apiToggle: {
// OMDbAPI: {
// movie: boolean;
// series: boolean;
// game: boolean;
// };
// MALAPI: {
// movie: boolean;
// series: boolean;
// };
// SteamAPI: {
// game: boolean;
// };
// MobyGamesAPI: {
// game: boolean;
// };
// };
OMDbAPI_disabledMediaTypes: string[];
MALAPI_disabledMediaTypes: string[];
MALAPIManga_disabledMediaTypes: string[];
ComicVineAPI_disabledMediaTypes: string[];
SteamAPI_disabledMediaTypes: string[];
MobyGamesAPI_disabledMediaTypes: string[];
GiantBombAPI_disabledMediaTypes: string[];
movieTemplate: string;
seriesTemplate: string;
mangaTemplate: string;
Expand Down Expand Up @@ -89,23 +78,13 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
openNoteInNewTab: true,
useDefaultFrontMatter: true,
enableTemplaterIntegration: false,
// apiToggle: {
// OMDbAPI: {
// movie: true,
// series: true,
// game: true,
// },
// MALAPI: {
// movie: true,
// series: true,
// },
// SteamAPI: {
// game: true,
// },
// MobyGamesAPI: {
// game: true,
// },
// },
OMDbAPI_disabledMediaTypes: [],
MALAPI_disabledMediaTypes: [],
MALAPIManga_disabledMediaTypes: [],
ComicVineAPI_disabledMediaTypes: [],
SteamAPI_disabledMediaTypes: [],
MobyGamesAPI_disabledMediaTypes: [],
GiantBombAPI_disabledMediaTypes: [],
movieTemplate: '',
seriesTemplate: '',
mangaTemplate: '',
Expand Down Expand Up @@ -310,82 +289,55 @@ export class MediaDbSettingTab extends PluginSettingTab {
});
});

// containerEl.createEl('h3', { text: 'APIs per media type' });
// containerEl.createEl('h5', { text: 'Movies' });
// new Setting(containerEl)
// .setName('OMDb API')
// .setDesc('Use OMDb API for movies.')
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.OMDbAPI.movie).onChange(data => {
// this.plugin.settings.apiToggle.OMDbAPI.movie = data;
// void this.plugin.saveSettings();
// });
// });
// new Setting(containerEl)
// .setName('MAL API')
// .setDesc('Use MAL API for movies.')
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.MALAPI.movie).onChange(data => {
// this.plugin.settings.apiToggle.MALAPI.movie = data;
// void this.plugin.saveSettings();
// });
// });
// containerEl.createEl('h5', { text: 'Series' });
// new Setting(containerEl)
// .setName('OMDb API')
// .setDesc('Use OMDb API for series.')
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.OMDbAPI.series).onChange(data => {
// this.plugin.settings.apiToggle.OMDbAPI.series = data;
// void this.plugin.saveSettings();
// });
// });
// new Setting(containerEl)
// .setName('MAL API')
// .setDesc('Use MAL API for series.')
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.MALAPI.series).onChange(data => {
// this.plugin.settings.apiToggle.MALAPI.series = data;
// void this.plugin.saveSettings();
// });
// });
// containerEl.createEl('h5', { text: 'Games' });
// new Setting(containerEl)
// .setName('OMDb API')
// .setDesc('Use OMDb API for games.')
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.OMDbAPI.game).onChange(data => {
// this.plugin.settings.apiToggle.OMDbAPI.game = data;
// void this.plugin.saveSettings();
// });
// });
// new Setting(containerEl)
// .setName('Steam API')
// .setDesc('Use OMDb API for games.')
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.SteamAPI.game).onChange(data => {
// this.plugin.settings.apiToggle.SteamAPI.game = data;
// void this.plugin.saveSettings();
// });
// });
// new Setting(containerEl)
// .setName('MobyGames API')
// .setDesc('Use MobyGames API for games.')
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.MobyGamesAPI.game).onChange(data => {
// this.plugin.settings.apiToggle.MobyGamesAPI.game = data;
// void this.plugin.saveSettings();
// });
// });
// new Setting(containerEl)
// .setName('Giantbomb API')
// .setDesc('Use Giantbomb API for games.')
// .addToggle(cb => {
// cb.setValue(this.plugin.settings.apiToggle.GiantBombAPI.game).onChange(data => {
// this.plugin.settings.apiToggle.GiantBombAPI.game = data;
// void this.plugin.saveSettings();
// });
// });
// Create a map to store APIs for each media type
const mediaTypeApiMap = new Map<string, string[]>();
const apiMediaTypes = {
OMDbAPI: ['movie', 'series', 'game'],
MALAPI: ['movie', 'series'],
MALAPIManga: ['comicManga'],
ComicVineAPI: ['comicManga'],
SteamAPI: ['game'],
MobyGamesAPI: ['game'],
GiantBombAPI: ['game'],
};

// Populate the map with APIs for each media type
for (const [api, mediaTypes] of Object.entries(apiMediaTypes)) {
for (const mediaType of mediaTypes) {
if (!mediaTypeApiMap.has(mediaType)) {
mediaTypeApiMap.set(mediaType, []);
}
mediaTypeApiMap.get(mediaType)!.push(api);
}
}

// Filter out media types with only one API
const filteredMediaTypes = Array.from(mediaTypeApiMap.entries()).filter(([_, apis]) => apis.length > 1);

// Dynamically create settings based on the filtered media types and their APIs
for (const [mediaType, apis] of filteredMediaTypes) {
new Setting(containerEl).setName(`Select APIs for ${unCamelCase(mediaType)}`).setHeading();
for (const apiName of apis) {
const disabledMediaTypes = this.plugin.settings[`${apiName}_disabledMediaTypes` as keyof typeof this.plugin.settings] as string[];
new Setting(containerEl)
.setName(apiName)
.setDesc(`Use ${apiName} API for ${unCamelCase(mediaType)}.`)
.addToggle(cb => {
cb.setValue(!disabledMediaTypes.includes(mediaType)).onChange(data => {
if (data) {
const index = disabledMediaTypes.indexOf(mediaType);
if (index > -1) {
disabledMediaTypes.splice(index, 1);
}
} else {
disabledMediaTypes.push(mediaType);
}
void this.plugin.saveSettings();
});
});
}
}

new Setting(containerEl).setName('New file location').setHeading();
// region new file location
new Setting(containerEl)
Expand Down