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 12 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
13 changes: 5 additions & 8 deletions src/api/APIModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@ 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
*/
abstract searchByTitle(title: string): Promise<MediaTypeModel[]>;

abstract getById(id: string): Promise<MediaTypeModel>;

abstract getDisabledMediaTypes(): MediaType[];

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.getDisabledMediaTypes();
return this.types.includes(type) && !disabledMediaTypes.includes(type);
}

hasTypeOverlap(types: MediaType[]): boolean {
Expand Down
3 changes: 3 additions & 0 deletions src/api/apis/BoardGameGeekAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@ export class BoardGameGeekAPI extends APIModel {
},
});
}
getDisabledMediaTypes(): MediaType[] {
return this.plugin.settings.BoardgameGeekAPI_disabledMediaTypes as MediaType[];
}
}
3 changes: 3 additions & 0 deletions src/api/apis/ComicVineAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,7 @@ export class ComicVineAPI extends APIModel {
},
});
}
getDisabledMediaTypes(): MediaType[] {
return this.plugin.settings.ComicVineAPI_disabledMediaTypes as MediaType[];
}
}
3 changes: 3 additions & 0 deletions src/api/apis/GiantBombAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,7 @@ export class GiantBombAPI extends APIModel {
},
});
}
getDisabledMediaTypes(): MediaType[] {
return this.plugin.settings.GiantBombAPI_disabledMediaTypes as MediaType[];
}
}
3 changes: 3 additions & 0 deletions src/api/apis/MALAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,7 @@ export class MALAPI extends APIModel {

throw new Error(`MDB | Unknown media type for id ${id}`);
}
getDisabledMediaTypes(): MediaType[] {
return this.plugin.settings.MALAPI_disabledMediaTypes as MediaType[];
}
}
3 changes: 3 additions & 0 deletions src/api/apis/MALAPIManga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@ export class MALAPIManga extends APIModel {
},
});
}
getDisabledMediaTypes(): MediaType[] {
return this.plugin.settings.MALAPIManga_disabledMediaTypes as MediaType[];
}
}
3 changes: 3 additions & 0 deletions src/api/apis/MobyGamesAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,7 @@ export class MobyGamesAPI extends APIModel {
},
});
}
getDisabledMediaTypes(): MediaType[] {
return this.plugin.settings.MobyGamesAPI_disabledMediaTypes as MediaType[];
}
}
3 changes: 3 additions & 0 deletions src/api/apis/MusicBrainzAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,7 @@ export class MusicBrainzAPI extends APIModel {
},
});
}
getDisabledMediaTypes(): MediaType[] {
return this.plugin.settings.MusicBrainzAPI_disabledMediaTypes as MediaType[];
}
}
4 changes: 4 additions & 0 deletions src/api/apis/OMDbAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,8 @@ export class OMDbAPI extends APIModel {

throw new Error(`MDB | Unknown media type for id ${id}`);
}

getDisabledMediaTypes(): MediaType[] {
return this.plugin.settings.OMDbAPI_disabledMediaTypes as MediaType[];
}
}
3 changes: 3 additions & 0 deletions src/api/apis/OpenLibraryAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,7 @@ export class OpenLibraryAPI extends APIModel {
},
});
}
getDisabledMediaTypes(): MediaType[] {
return this.plugin.settings.OpenLibraryAPI_disabledMediaTypes as MediaType[];
}
}
3 changes: 3 additions & 0 deletions src/api/apis/SteamAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,7 @@ export class SteamAPI extends APIModel {
},
});
}
getDisabledMediaTypes(): MediaType[] {
return this.plugin.settings.SteamAPI_disabledMediaTypes as MediaType[];
}
}
3 changes: 3 additions & 0 deletions src/api/apis/WikipediaAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,7 @@ export class WikipediaAPI extends APIModel {
userData: {},
});
}
getDisabledMediaTypes(): MediaType[] {
return this.plugin.settings.WikipediaAPI_disabledMediaTypes as MediaType[];
}
}
179 changes: 67 additions & 112 deletions src/settings/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ 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';
import { FolderSuggest } from './suggesters/FolderSuggest';
import type { MediaType } from 'src/utils/MediaType';

export interface MediaDbPluginSettings {
OMDbKey: string;
Expand All @@ -21,24 +22,17 @@ 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[];
WikipediaAPI_disabledMediaTypes: string[];
BoardgameGeekAPI_disabledMediaTypes: string[];
MusicBrainzAPI_disabledMediaTypes: string[];
OpenLibraryAPI_disabledMediaTypes: string[];
movieTemplate: string;
seriesTemplate: string;
mangaTemplate: string;
Expand Down Expand Up @@ -89,23 +83,17 @@ 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: [],
WikipediaAPI_disabledMediaTypes: [],
BoardgameGeekAPI_disabledMediaTypes: [],
MusicBrainzAPI_disabledMediaTypes: [],
OpenLibraryAPI_disabledMediaTypes: [],
movieTemplate: '',
seriesTemplate: '',
mangaTemplate: '',
Expand Down Expand Up @@ -310,82 +298,49 @@ 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[]>();

// Populate the map with APIs for each media type dynamically
for (const api of this.plugin.apiManager.apis) {
for (const MediaType of api.types) {
if (!mediaTypeApiMap.has(MediaType)) {
mediaTypeApiMap.set(MediaType, []);
}
mediaTypeApiMap.get(MediaType)!.push(api.apiName);
}
}

// 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 api = this.plugin.apiManager.apis.find(api => api.apiName === apiName);
if (api) {
const disabledMediaTypes = api.getDisabledMediaTypes();
new Setting(containerEl)
.setName(apiName)
.setDesc(`Use ${apiName} API for ${unCamelCase(MediaType)}.`)
.addToggle(cb => {
cb.setValue(!disabledMediaTypes.includes(MediaType as MediaType)).onChange(data => {
if (data) {
const index = disabledMediaTypes.indexOf(MediaType as MediaType);
if (index > -1) {
disabledMediaTypes.splice(index, 1);
}
} else {
disabledMediaTypes.push(MediaType as MediaType);
}
void this.plugin.saveSettings();
});
});
}
}
}

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