From 1d76bb8981ca8f132daf2715a97c5fac1c0f0d11 Mon Sep 17 00:00:00 2001 From: mProjectsCode Date: Thu, 28 Sep 2023 11:50:39 +0200 Subject: [PATCH] maintenance --- README.md | 18 ++++----- src/api/APIManager.ts | 17 +++++++++ src/api/apis/MALAPIManga.ts | 62 +++++++++++++++---------------- src/api/apis/OpenLibraryAPI.ts | 22 +++++------ src/modals/MediaDbPreviewModal.ts | 3 +- src/utils/MediaTypeManager.ts | 11 +++++- src/utils/ModalHelper.ts | 2 +- 7 files changed, 80 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index f80649e..716fea7 100644 --- a/README.md +++ b/README.md @@ -111,15 +111,14 @@ 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 | -| [OMDb](https://www.omdbapi.com/) | OMDb is an API that offers metadata for movie, series and games. | series, movies, games | Yes, you can get a free key here [here](https://www.omdbapi.com/apikey.aspx) | 1000 per day | No | -| [MusicBrainz](https://musicbrainz.org/) | MusicBrainz is an API that offers information about music releases. | music releases | No | 50 per second | No | -| [Wikipedia](https://en.wikipedia.org/wiki/Main_Page) | The Wikipedia API allows access to all Wikipedia articles. | wiki articles | No | None | No | -| [Steam](https://store.steampowered.com/) | The Steam API offers information on all steam games. | games | No | 10000 per day | No | -| [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 | - +| 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 | +| [OMDb](https://www.omdbapi.com/) | OMDb is an API that offers metadata for movie, series and games. | series, movies, games | Yes, you can get a free key here [here](https://www.omdbapi.com/apikey.aspx) | 1000 per day | No | +| [MusicBrainz](https://musicbrainz.org/) | MusicBrainz is an API that offers information about music releases. | music releases | No | 50 per second | No | +| [Wikipedia](https://en.wikipedia.org/wiki/Main_Page) | The Wikipedia API allows access to all Wikipedia articles. | wiki articles | No | None | No | +| [Steam](https://store.steampowered.com/) | The Steam API offers information on all steam games. | games | No | 10000 per day | No | +| [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 | #### Notes @@ -154,7 +153,6 @@ Now you select the result you want and the plugin will cast it's magic and creat - e.g. for "Fantastic Mr. Fox" the URL looks like this `https://openlibrary.org/works/OL45804W` so the ID is `/works/OL45804W` - This URL is located near the top of the page above the title, see `An edition of Fantastic Mr Fox (1970) ` - ### Problems, unexpected behavior or improvement suggestions? You are more than welcome to open an issue on [GitHub](https://github.com/mProjectsCode/obsidian-media-db-plugin/issues). diff --git a/src/api/APIManager.ts b/src/api/APIManager.ts index d3390d0..17f0f36 100644 --- a/src/api/APIManager.ts +++ b/src/api/APIManager.ts @@ -8,6 +8,12 @@ export class APIManager { this.apis = []; } + /** + * Queries the basic info for one query string and multiple APIs. + * + * @param query + * @param apisToQuery + */ async query(query: string, apisToQuery: string[]): Promise { console.debug(`MDB | api manager queried with "${query}"`); @@ -23,10 +29,21 @@ export class APIManager { return res; } + /** + * Queries detailed information for a MediaTypeModel. + * + * @param item + */ async queryDetailedInfo(item: MediaTypeModel): Promise { return await this.queryDetailedInfoById(item.id, item.dataSource); } + /** + * Queries detailed info for an id from an API. + * + * @param id + * @param apiName + */ async queryDetailedInfoById(id: string, apiName: string): Promise { for (const api of this.apis) { if (api.apiName === apiName) { diff --git a/src/api/apis/MALAPIManga.ts b/src/api/apis/MALAPIManga.ts index 45bc06d..ee34817 100644 --- a/src/api/apis/MALAPIManga.ts +++ b/src/api/apis/MALAPIManga.ts @@ -44,37 +44,37 @@ export class MALAPIManga extends APIModel { for (const result of data.data) { const type = this.typeMappings.get(result.type?.toLowerCase()); - ret.push( - new MangaModel({ - subType: type, - title: result.title, - synopsis: result.synopsis, - englishTitle: result.title_english ?? result.title, - alternateTitles: result.titles?.map((x: any) => x.title) ?? [], - year: result.year ?? result.published?.prop?.from?.year ?? '', - dataSource: this.apiName, - url: result.url, - id: result.mal_id, - - genres: result.genres?.map((x: any) => x.name) ?? [], - authors: result.authors?.map((x: any) => x.name) ?? [], - chapters: result.chapters, - volumes: result.volumes, - onlineRating: result.score ?? 0, - image: result.images?.jpg?.image_url ?? '', - - released: true, - publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown', - publishedTo: new Date(result.published?.to).toLocaleDateString() ?? 'unknown', - status: result.status, - - userData: { - watched: false, - lastWatched: '', - personalRating: 0, - }, - } as MangaModel) - ) + ret.push( + new MangaModel({ + subType: type, + title: result.title, + synopsis: result.synopsis, + englishTitle: result.title_english ?? result.title, + alternateTitles: result.titles?.map((x: any) => x.title) ?? [], + year: result.year ?? result.published?.prop?.from?.year ?? '', + dataSource: this.apiName, + url: result.url, + id: result.mal_id, + + genres: result.genres?.map((x: any) => x.name) ?? [], + authors: result.authors?.map((x: any) => x.name) ?? [], + chapters: result.chapters, + volumes: result.volumes, + onlineRating: result.score ?? 0, + image: result.images?.jpg?.image_url ?? '', + + released: true, + publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown', + publishedTo: new Date(result.published?.to).toLocaleDateString() ?? 'unknown', + status: result.status, + + userData: { + watched: false, + lastWatched: '', + personalRating: 0, + }, + } as MangaModel) + ); } return ret; diff --git a/src/api/apis/OpenLibraryAPI.ts b/src/api/apis/OpenLibraryAPI.ts index 60e6852..a0d0507 100644 --- a/src/api/apis/OpenLibraryAPI.ts +++ b/src/api/apis/OpenLibraryAPI.ts @@ -15,7 +15,7 @@ export class OpenLibraryAPI extends APIModel { this.apiDescription = 'A free API for books'; this.apiUrl = 'https://openlibrary.org/'; this.types = [MediaType.Book]; -} + } async searchByTitle(title: string): Promise { console.log(`MDB | api "${this.apiName}" queried by Title`); @@ -34,15 +34,15 @@ export class OpenLibraryAPI extends APIModel { const ret: MediaTypeModel[] = []; for (const result of data.docs) { - ret.push( - new BookModel({ - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.first_publish_year, - dataSource: this.apiName, - id: result.key, - } as BookModel) - ); + ret.push( + new BookModel({ + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.first_publish_year, + dataSource: this.apiName, + id: result.key, + } as BookModel) + ); } return ret; @@ -87,4 +87,4 @@ export class OpenLibraryAPI extends APIModel { return model; } -} \ No newline at end of file +} diff --git a/src/modals/MediaDbPreviewModal.ts b/src/modals/MediaDbPreviewModal.ts index 729bae1..f7472c2 100644 --- a/src/modals/MediaDbPreviewModal.ts +++ b/src/modals/MediaDbPreviewModal.ts @@ -57,7 +57,8 @@ export class MediaDbPreviewModal extends Modal { fileContent = `\n${fileContent}\n`; try { - await MarkdownRenderer.renderMarkdown(fileContent, fileDiv, '', this.markdownComponent); + // TODO: fix this not rendering the frontmatter any more + await MarkdownRenderer.render(this.app, fileContent, fileDiv, '', this.markdownComponent); } catch (e) { console.warn(`mdb | error during rendering of preview`, e); } diff --git a/src/utils/MediaTypeManager.ts b/src/utils/MediaTypeManager.ts index 6d2c925..d94c1ec 100644 --- a/src/utils/MediaTypeManager.ts +++ b/src/utils/MediaTypeManager.ts @@ -12,7 +12,16 @@ import { MusicReleaseModel } from '../models/MusicReleaseModel'; import { BoardGameModel } from '../models/BoardGameModel'; import { BookModel } from '../models/BookModel'; -export const MEDIA_TYPES: MediaType[] = [MediaType.Movie, MediaType.Series, MediaType.Manga, MediaType.Game, MediaType.Wiki, MediaType.MusicRelease, MediaType.BoardGame, MediaType.Book]; +export const MEDIA_TYPES: MediaType[] = [ + MediaType.Movie, + MediaType.Series, + MediaType.Manga, + MediaType.Game, + MediaType.Wiki, + MediaType.MusicRelease, + MediaType.BoardGame, + MediaType.Book, +]; export class MediaTypeManager { mediaFileNameTemplateMap: Map; diff --git a/src/utils/ModalHelper.ts b/src/utils/ModalHelper.ts index 808aa5e..8299e64 100644 --- a/src/utils/ModalHelper.ts +++ b/src/utils/ModalHelper.ts @@ -440,7 +440,7 @@ export class ModalHelper { * then executes the `submitCallback` returning the callbacks result and closing the modal. * * @param selectModalOptions the options for the modal, see {@link SELECT_MODAL_OPTIONS_DEFAULT} - * @param submitCallback the callback that gets executed after the modal has been submitted, but after it has been closed + * @param submitCallback the callback that gets executed after the modal has been submitted, but before it has been closed * @returns the user input or nothing and a reference to the modal. */ async openSelectModal(selectModalOptions: SelectModalOptions, submitCallback: (selectModalData: SelectModalData) => Promise): Promise {