From 8a392e5e4e274d28175cd78008b757e6709e40ce Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Fri, 27 Jun 2025 00:59:45 +0200 Subject: [PATCH 1/8] Improved openlibrary API + updated readme Fixed missing ratings, page numbers and also added an option to add specific editions using search by ID, this method also enables you to search by isbn ID. --- README.md | 6 ++++-- src/api/apis/OpenLibraryAPI.ts | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dd48ea0..0ffd6aa 100644 --- a/README.md +++ b/README.md @@ -162,9 +162,11 @@ Now you select the result you want and the plugin will cast it's magic and creat - you can find this ID in the URL - e.g. for "Factorio" the URL looks like this `https://store.steampowered.com/app/427520/Factorio/` so the ID is `427520` - [Open Library](https://openlibrary.org) - - The ID you need is the "work" ID and not the "book" ID, it needs to start with `/works/`. You can find this ID in the URL - - e.g. for "Fantastic Mr. Fox" the URL looks like this `https://openlibrary.org/works/OL45804W` so the ID is `/works/OL45804W` + - The ID can either be the "/work/" ID, the "/book/" ID, or the "/isbn/" ID it needs to start with `/works/`. You can find this ID in the URL + - e.g. for "Fantastic Mr. Fox" the "/works/" 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) ` + - For a specific edition of "Fantastic Mr. Fox" the "/books/" URL looks like this `https://openlibrary.org/books/OL3567303M/` so the ID is `/books/OL3567303M` + - This URL is located in the editions section` - [Moby Games](https://www.mobygames.com) - you can find this ID in the URL - e.g. for "Bioshock 2" the URL looks like this `https://www.mobygames.com/game/45089/bioshock-2/` so the ID is `45089` diff --git a/src/api/apis/OpenLibraryAPI.ts b/src/api/apis/OpenLibraryAPI.ts index 78eb301..45383f1 100644 --- a/src/api/apis/OpenLibraryAPI.ts +++ b/src/api/apis/OpenLibraryAPI.ts @@ -52,7 +52,7 @@ export class OpenLibraryAPI extends APIModel { async getById(id: string): Promise { console.log(`MDB | api "${this.apiName}" queried by ID`); - const searchUrl = `https://openlibrary.org/search.json?q=key:${encodeURIComponent(id)}`; + const searchUrl = `https://openlibrary.org/search.json?q=${encodeURIComponent(id)}&fields=key,title,author_name,number_of_pages_median,first_publish_year,isbn,ratings_score,first_sentence,title_suggest,rating*,cover_edition_key`; const fetchData = await fetch(searchUrl); // console.debug(fetchData); @@ -68,8 +68,8 @@ export class OpenLibraryAPI extends APIModel { title: result.title, year: result.first_publish_year, dataSource: this.apiName, - url: `https://openlibrary.org` + result.key, - id: result.key, + url: `https://openlibrary.org` + data.q, + id: data.q, isbn: (result.isbn ?? []).find((el: string | any[]) => el.length <= 10) ?? 'unknown', isbn13: (result.isbn ?? []).find((el: string | any[]) => el.length == 13) ?? 'unknown', englishTitle: result.title_english ?? result.title, From f867f42793e7958b5ed101dafe52eddf1f71c828 Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Fri, 27 Jun 2025 01:03:01 +0200 Subject: [PATCH 2/8] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0ffd6aa..0bf4914 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ ## Obsidian Media DB Plugin -A plugin that can query multiple APIs for movies, series, anime, manga, books, games, music and wiki articles, and import them into your vault. +A plugin that can query multiple APIs for movies, series, anime, manga, books, comics, games, music and wiki articles, and import them into your vault. ### Features #### Search by Title -Search a movie, series, anime, game, music release or wiki article by its name across multiple APIs. +Search a movie, series, anime, manga, book, comic, game, music or wiki articles by its name across multiple APIs. #### Search by ID @@ -164,9 +164,9 @@ Now you select the result you want and the plugin will cast it's magic and creat - [Open Library](https://openlibrary.org) - The ID can either be the "/work/" ID, the "/book/" ID, or the "/isbn/" ID it needs to start with `/works/`. You can find this ID in the URL - e.g. for "Fantastic Mr. Fox" the "/works/" 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) ` + - This URL is located near the top of the page above the title, see `An edition of Fantastic Mr Fox (1970) ` - For a specific edition of "Fantastic Mr. Fox" the "/books/" URL looks like this `https://openlibrary.org/books/OL3567303M/` so the ID is `/books/OL3567303M` - - This URL is located in the editions section` + - This URL is located in the editions section` - [Moby Games](https://www.mobygames.com) - you can find this ID in the URL - e.g. for "Bioshock 2" the URL looks like this `https://www.mobygames.com/game/45089/bioshock-2/` so the ID is `45089` From c3df1f582f3213f22385e654cf4db0f282602201 Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Fri, 27 Jun 2025 01:14:10 +0200 Subject: [PATCH 3/8] Re-added music release --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0bf4914..536c900 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A plugin that can query multiple APIs for movies, series, anime, manga, books, c #### Search by Title -Search a movie, series, anime, manga, book, comic, game, music or wiki articles by its name across multiple APIs. +Search a movie, series, anime, manga, book, comic, game, music release or wiki articles by its name across multiple APIs. #### Search by ID From 74acf7f914ee9db502e46d1ad9cb86f93f47449b Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Fri, 27 Jun 2025 16:04:48 +0200 Subject: [PATCH 4/8] Small fix for musicbrainzapi Added .jpg to the poster url so the posters can be downloaded by the plugin --- src/api/apis/MusicBrainzAPI.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/apis/MusicBrainzAPI.ts b/src/api/apis/MusicBrainzAPI.ts index 022d944..c67e820 100644 --- a/src/api/apis/MusicBrainzAPI.ts +++ b/src/api/apis/MusicBrainzAPI.ts @@ -51,7 +51,7 @@ export class MusicBrainzAPI extends APIModel { dataSource: this.apiName, url: 'https://musicbrainz.org/release-group/' + result.id, id: result.id, - image: 'https://coverartarchive.org/release-group/' + result.id + '/front', + image: 'https://coverartarchive.org/release-group/' + result.id + '/front.jpg', artists: result['artist-credit'].map((a: any) => a.name), subType: result['primary-type'], @@ -87,7 +87,7 @@ export class MusicBrainzAPI extends APIModel { dataSource: this.apiName, url: 'https://musicbrainz.org/release-group/' + result.id, id: result.id, - image: 'https://coverartarchive.org/release-group/' + result.id + '/front', + image: 'https://coverartarchive.org/release-group/' + result.id + '/front.jpg', artists: result['artist-credit'].map((a: any) => a.name), genres: result.genres.map((g: any) => g.name), From 12596573b3e72e187ba69fb19a6b8979c7f83dd4 Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Tue, 1 Jul 2025 01:40:44 +0200 Subject: [PATCH 5/8] Added plot/description to openlibraryAPI when available --- src/api/apis/OpenLibraryAPI.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/api/apis/OpenLibraryAPI.ts b/src/api/apis/OpenLibraryAPI.ts index 45383f1..7279206 100644 --- a/src/api/apis/OpenLibraryAPI.ts +++ b/src/api/apis/OpenLibraryAPI.ts @@ -3,6 +3,7 @@ import type MediaDbPlugin from '../../main'; import type { MediaTypeModel } from '../../models/MediaTypeModel'; import { MediaType } from '../../utils/MediaType'; import { APIModel } from '../APIModel'; +import { requestUrl } from 'obsidian'; export class OpenLibraryAPI extends APIModel { plugin: MediaDbPlugin; @@ -53,14 +54,24 @@ export class OpenLibraryAPI extends APIModel { console.log(`MDB | api "${this.apiName}" queried by ID`); const searchUrl = `https://openlibrary.org/search.json?q=${encodeURIComponent(id)}&fields=key,title,author_name,number_of_pages_median,first_publish_year,isbn,ratings_score,first_sentence,title_suggest,rating*,cover_edition_key`; - const fetchData = await fetch(searchUrl); + const fetchData = await requestUrl({ + url: searchUrl, + }); + const descriptionUrl = `https://openlibrary.org/${encodeURIComponent(id)}.json`; + const fetchDescription = await requestUrl({ + url: descriptionUrl, + }); // console.debug(fetchData); if (fetchData.status !== 200) { throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`); } + if (fetchDescription.status !== 200) { + throw Error(`MDB | Received status code ${fetchDescription.status} from ${this.apiName}.`); + } - const data = await fetchData.json(); + const data = await fetchData.json; + const resultdesc = await fetchDescription.json; // console.debug(data); const result = data.docs[0]; @@ -75,7 +86,7 @@ export class OpenLibraryAPI extends APIModel { englishTitle: result.title_english ?? result.title, author: result.author_name ?? 'unknown', - plot: result.description ?? 'unknown', + plot: resultdesc.description?.value ?? 'unknown', pages: result.number_of_pages_median ?? 'unknown', onlineRating: Number.parseFloat(Number(result.ratings_average ?? 0).toFixed(2)), image: `https://covers.openlibrary.org/b/OLID/` + result.cover_edition_key + `-L.jpg`, From ece665037662ce09b2461ae2cac6dde7a0ae4231 Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Sat, 19 Jul 2025 19:14:11 +0200 Subject: [PATCH 6/8] Add country, boxOffice and ageRating fields for movies and series OMDbAPI has all 3 of these fields and MALAPI only has ageRating. While most anime is japanese there are some korean or chinese anime also on MAL so I thought it best to just set country and boxOffice as empty. boxOffice isn't applicable for series so I removed that field --- src/api/apis/MALAPI.ts | 8 ++++++++ src/api/apis/OMDbAPI.ts | 5 +++++ src/models/MovieModel.ts | 6 ++++++ src/models/SeriesModel.ts | 4 ++++ 4 files changed, 23 insertions(+) diff --git a/src/api/apis/MALAPI.ts b/src/api/apis/MALAPI.ts index d85746c..7aa7ac6 100644 --- a/src/api/apis/MALAPI.ts +++ b/src/api/apis/MALAPI.ts @@ -119,6 +119,9 @@ export class MALAPI extends APIModel { image: result.images?.jpg?.image_url ?? '', released: true, + country: [], + boxOffice: '', + ageRating: result.rating ?? '', premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', streamingServices: result.streaming?.map((x: any) => x.name) ?? [], @@ -151,6 +154,9 @@ export class MALAPI extends APIModel { image: result.images?.jpg?.image_url ?? '', released: true, + country: [], + boxOffice: '', + ageRating: result.rating ?? '', premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', streamingServices: result.streaming?.map((x: any) => x.name) ?? [], @@ -181,6 +187,8 @@ export class MALAPI extends APIModel { image: result.images?.jpg?.image_url ?? '', released: true, + country: [], + ageRating: result.rating ?? '', airedFrom: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', airedTo: this.plugin.dateFormatter.format(result.aired?.to, this.apiDateFormat) ?? 'unknown', airing: result.airing, diff --git a/src/api/apis/OMDbAPI.ts b/src/api/apis/OMDbAPI.ts index 3afe47f..b909677 100644 --- a/src/api/apis/OMDbAPI.ts +++ b/src/api/apis/OMDbAPI.ts @@ -154,6 +154,9 @@ export class OMDbAPI extends APIModel { image: result.Poster ? result.Poster.replace('_SX300', '_SX600') : '', released: true, + country: result.Country?.split(', ') ?? [], + boxOffice: result.BoxOffice, + ageRating: result.Rated, streamingServices: [], premiere: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', @@ -184,6 +187,8 @@ export class OMDbAPI extends APIModel { image: result.Poster ? result.Poster.replace('_SX300', '_SX600') : '', released: true, + country: result.Country?.split(', ') ?? [], + ageRating: result.Rated, streamingServices: [], airing: false, airedFrom: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', diff --git a/src/models/MovieModel.ts b/src/models/MovieModel.ts index bbf7cb5..925f1b3 100644 --- a/src/models/MovieModel.ts +++ b/src/models/MovieModel.ts @@ -17,6 +17,9 @@ export class MovieModel extends MediaTypeModel { image: string; released: boolean; + country: string[]; + boxOffice: string; + ageRating: string; streamingServices: string[]; premiere: string; @@ -40,6 +43,9 @@ export class MovieModel extends MediaTypeModel { this.image = ''; this.released = false; + this.country = []; + this.boxOffice = ''; + this.ageRating = ''; this.streamingServices = []; this.premiere = ''; diff --git a/src/models/SeriesModel.ts b/src/models/SeriesModel.ts index c13d90d..bb5c5c0 100644 --- a/src/models/SeriesModel.ts +++ b/src/models/SeriesModel.ts @@ -17,6 +17,8 @@ export class SeriesModel extends MediaTypeModel { image: string; released: boolean; + country: string[]; + ageRating: string; streamingServices: string[]; airing: boolean; airedFrom: string; @@ -42,6 +44,8 @@ export class SeriesModel extends MediaTypeModel { this.image = ''; this.released = false; + this.country = []; + this.ageRating = ''; this.streamingServices = []; this.airing = false; this.airedFrom = ''; From 1c9de8c3a03ce9a573a22b642087075ce2f8dfee Mon Sep 17 00:00:00 2001 From: Zack Boehm Date: Thu, 24 Jul 2025 20:02:15 -0400 Subject: [PATCH 7/8] MusicBrainz: Limit cover art images to 500px --- src/api/apis/MusicBrainzAPI.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/apis/MusicBrainzAPI.ts b/src/api/apis/MusicBrainzAPI.ts index c67e820..04db9fd 100644 --- a/src/api/apis/MusicBrainzAPI.ts +++ b/src/api/apis/MusicBrainzAPI.ts @@ -51,7 +51,7 @@ export class MusicBrainzAPI extends APIModel { dataSource: this.apiName, url: 'https://musicbrainz.org/release-group/' + result.id, id: result.id, - image: 'https://coverartarchive.org/release-group/' + result.id + '/front.jpg', + image: 'https://coverartarchive.org/release-group/' + result.id + '/front-500.jpg', artists: result['artist-credit'].map((a: any) => a.name), subType: result['primary-type'], @@ -87,7 +87,7 @@ export class MusicBrainzAPI extends APIModel { dataSource: this.apiName, url: 'https://musicbrainz.org/release-group/' + result.id, id: result.id, - image: 'https://coverartarchive.org/release-group/' + result.id + '/front.jpg', + image: 'https://coverartarchive.org/release-group/' + result.id + '/front-500.jpg', artists: result['artist-credit'].map((a: any) => a.name), genres: result.genres.map((g: any) => g.name), From 5089287ee4926d11ae36d4bf427c1743588d7c68 Mon Sep 17 00:00:00 2001 From: Zack Boehm Date: Thu, 24 Jul 2025 20:23:36 -0400 Subject: [PATCH 8/8] MusicBrainz: Add releaseDate to music releases --- src/api/apis/MusicBrainzAPI.ts | 3 +++ src/models/MusicReleaseModel.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/api/apis/MusicBrainzAPI.ts b/src/api/apis/MusicBrainzAPI.ts index c67e820..9d34ee4 100644 --- a/src/api/apis/MusicBrainzAPI.ts +++ b/src/api/apis/MusicBrainzAPI.ts @@ -8,6 +8,7 @@ import { APIModel } from '../APIModel'; export class MusicBrainzAPI extends APIModel { plugin: MediaDbPlugin; + apiDateFormat: string = 'YYYY-MM-DD'; constructor(plugin: MediaDbPlugin) { super(); @@ -48,6 +49,7 @@ export class MusicBrainzAPI extends APIModel { title: result.title, englishTitle: result.title, year: new Date(result['first-release-date']).getFullYear().toString(), + releaseDate: this.plugin.dateFormatter.format(result['first-release-date'], this.apiDateFormat) ?? 'unknown', dataSource: this.apiName, url: 'https://musicbrainz.org/release-group/' + result.id, id: result.id, @@ -84,6 +86,7 @@ export class MusicBrainzAPI extends APIModel { title: result.title, englishTitle: result.title, year: new Date(result['first-release-date']).getFullYear().toString(), + releaseDate: this.plugin.dateFormatter.format(result['first-release-date'], this.apiDateFormat) ?? 'unknown', dataSource: this.apiName, url: 'https://musicbrainz.org/release-group/' + result.id, id: result.id, diff --git a/src/models/MusicReleaseModel.ts b/src/models/MusicReleaseModel.ts index 24f6816..5f20a75 100644 --- a/src/models/MusicReleaseModel.ts +++ b/src/models/MusicReleaseModel.ts @@ -10,6 +10,7 @@ export class MusicReleaseModel extends MediaTypeModel { artists: string[]; image: string; rating: number; + releaseDate: string; userData: { personalRating: number; @@ -22,6 +23,8 @@ export class MusicReleaseModel extends MediaTypeModel { this.artists = []; this.image = ''; this.rating = 0; + this.releaseDate = ''; + this.userData = { personalRating: 0, };