From 4ec25de6c48b7eb28b441ce3f1e8cb6d5950b8f6 Mon Sep 17 00:00:00 2001 From: ReconVirus <43733760+ReconVirus@users.noreply.github.com> Date: Thu, 2 May 2024 15:33:38 -0700 Subject: [PATCH 1/5] Add files via upload Changed the way the image link are outputted so that they are embed ready instead of it just being a web link to the image --- src/api/apis/MALAPI.ts | 406 ++++++++++++++++++------------------ src/api/apis/OMDbAPI.ts | 446 ++++++++++++++++++++-------------------- 2 files changed, 426 insertions(+), 426 deletions(-) diff --git a/src/api/apis/MALAPI.ts b/src/api/apis/MALAPI.ts index e3a91fa..d262388 100644 --- a/src/api/apis/MALAPI.ts +++ b/src/api/apis/MALAPI.ts @@ -1,203 +1,203 @@ -import { APIModel } from '../APIModel'; -import { MediaTypeModel } from '../../models/MediaTypeModel'; -import { MovieModel } from '../../models/MovieModel'; -import MediaDbPlugin from '../../main'; -import { SeriesModel } from '../../models/SeriesModel'; -import { MediaType } from '../../utils/MediaType'; - -export class MALAPI extends APIModel { - plugin: MediaDbPlugin; - typeMappings: Map; - apiDateFormat: string = 'YYYY-MM-DDTHH:mm:ssZ'; // ISO - - constructor(plugin: MediaDbPlugin) { - super(); - - this.plugin = plugin; - this.apiName = 'MALAPI'; - this.apiDescription = 'A free API for Anime. Some results may take a long time to load.'; - this.apiUrl = 'https://jikan.moe/'; - this.types = [MediaType.Movie, MediaType.Series]; - this.typeMappings = new Map(); - this.typeMappings.set('movie', 'movie'); - this.typeMappings.set('special', 'special'); - this.typeMappings.set('tv', 'series'); - this.typeMappings.set('ova', 'ova'); - } - - async searchByTitle(title: string): Promise { - console.log(`MDB | api "${this.apiName}" queried by Title`); - - const searchUrl = `https://api.jikan.moe/v4/anime?q=${encodeURIComponent(title)}&limit=20${this.plugin.settings.sfwFilter ? '&sfw' : ''}`; - - const fetchData = await fetch(searchUrl); - console.debug(fetchData); - if (fetchData.status !== 200) { - throw Error(`MDB | Received status code ${fetchData.status} from an API.`); - } - const data = await fetchData.json(); - - console.debug(data); - - const ret: MediaTypeModel[] = []; - - for (const result of data.data) { - const type = this.typeMappings.get(result.type?.toLowerCase()); - if (type === undefined) { - ret.push( - new MovieModel({ - subType: '', - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.year ?? result.aired?.prop?.from?.year ?? '', - dataSource: this.apiName, - id: result.mal_id, - } as MovieModel), - ); - } - if (type === 'movie' || type === 'special') { - ret.push( - new MovieModel({ - subType: type, - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.year ?? result.aired?.prop?.from?.year ?? '', - dataSource: this.apiName, - id: result.mal_id, - } as MovieModel), - ); - } else if (type === 'series' || type === 'ova') { - ret.push( - new SeriesModel({ - subType: type, - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.year ?? result.aired?.prop?.from?.year ?? '', - dataSource: this.apiName, - id: result.mal_id, - } as SeriesModel), - ); - } - } - - return ret; - } - - async getById(id: string): Promise { - console.log(`MDB | api "${this.apiName}" queried by ID`); - - const searchUrl = `https://api.jikan.moe/v4/anime/${encodeURIComponent(id)}/full`; - const fetchData = await fetch(searchUrl); - - if (fetchData.status !== 200) { - throw Error(`MDB | Received status code ${fetchData.status} from an API.`); - } - - const data = await fetchData.json(); - console.debug(data); - const result = data.data; - - const type = this.typeMappings.get(result.type?.toLowerCase()); - if (type === undefined) { - const model = new MovieModel({ - subType: '', - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.year ?? result.aired?.prop?.from?.year ?? '', - dataSource: this.apiName, - url: result.url, - id: result.mal_id, - - plot: result.synopsis, - genres: result.genres?.map((x: any) => x.name) ?? [], - director: [], - writer: [], - studio: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown', - duration: result.duration ?? 'unknown', - onlineRating: result.score ?? 0, - actors: [], - image: result.images?.jpg?.image_url ?? '', - - released: true, - premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', - streamingServices: result.streaming?.map((x: any) => x.name) ?? [], - - userData: { - watched: false, - lastWatched: '', - personalRating: 0, - }, - } as MovieModel); - - return model; - } - - if (type === 'movie' || type === 'special') { - const model = new MovieModel({ - subType: type, - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.year ?? result.aired?.prop?.from?.year ?? '', - dataSource: this.apiName, - url: result.url, - id: result.mal_id, - - plot: result.synopsis, - genres: result.genres?.map((x: any) => x.name) ?? [], - director: [], - writer: [], - studio: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown', - duration: result.duration ?? 'unknown', - onlineRating: result.score ?? 0, - actors: [], - image: result.images?.jpg?.image_url ?? '', - - released: true, - premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', - streamingServices: result.streaming?.map((x: any) => x.name) ?? [], - - userData: { - watched: false, - lastWatched: '', - personalRating: 0, - }, - } as MovieModel); - - return model; - } else if (type === 'series' || type === 'ova') { - const model = new SeriesModel({ - subType: type, - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.year ?? result.aired?.prop?.from?.year ?? '', - dataSource: this.apiName, - url: result.url, - id: result.mal_id, - - genres: result.genres?.map((x: any) => x.name) ?? [], - writer: [], - studio: result.studios?.map((x: any) => x.name) ?? [], - episodes: result.episodes, - duration: result.duration ?? 'unknown', - onlineRating: result.score ?? 0, - streamingServices: result.streaming?.map((x: any) => x.name) ?? [], - image: result.images?.jpg?.image_url ?? '', - - released: true, - 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, - - userData: { - watched: false, - lastWatched: '', - personalRating: 0, - }, - } as SeriesModel); - - return model; - } - - return; - } -} +import { APIModel } from '../APIModel'; +import { MediaTypeModel } from '../../models/MediaTypeModel'; +import { MovieModel } from '../../models/MovieModel'; +import MediaDbPlugin from '../../main'; +import { SeriesModel } from '../../models/SeriesModel'; +import { MediaType } from '../../utils/MediaType'; + +export class MALAPI extends APIModel { + plugin: MediaDbPlugin; + typeMappings: Map; + apiDateFormat: string = 'YYYY-MM-DDTHH:mm:ssZ'; // ISO + + constructor(plugin: MediaDbPlugin) { + super(); + + this.plugin = plugin; + this.apiName = 'MALAPI'; + this.apiDescription = 'A free API for Anime. Some results may take a long time to load.'; + this.apiUrl = 'https://jikan.moe/'; + this.types = [MediaType.Movie, MediaType.Series]; + this.typeMappings = new Map(); + this.typeMappings.set('movie', 'movie'); + this.typeMappings.set('special', 'special'); + this.typeMappings.set('tv', 'series'); + this.typeMappings.set('ova', 'ova'); + } + + async searchByTitle(title: string): Promise { + console.log(`MDB | api "${this.apiName}" queried by Title`); + + const searchUrl = `https://api.jikan.moe/v4/anime?q=${encodeURIComponent(title)}&limit=20${this.plugin.settings.sfwFilter ? '&sfw' : ''}`; + + const fetchData = await fetch(searchUrl); + console.debug(fetchData); + if (fetchData.status !== 200) { + throw Error(`MDB | Received status code ${fetchData.status} from an API.`); + } + const data = await fetchData.json(); + + console.debug(data); + + const ret: MediaTypeModel[] = []; + + for (const result of data.data) { + const type = this.typeMappings.get(result.type?.toLowerCase()); + if (type === undefined) { + ret.push( + new MovieModel({ + subType: '', + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.year ?? result.aired?.prop?.from?.year ?? '', + dataSource: this.apiName, + id: result.mal_id, + } as MovieModel), + ); + } + if (type === 'movie' || type === 'special') { + ret.push( + new MovieModel({ + subType: type, + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.year ?? result.aired?.prop?.from?.year ?? '', + dataSource: this.apiName, + id: result.mal_id, + } as MovieModel), + ); + } else if (type === 'series' || type === 'ova') { + ret.push( + new SeriesModel({ + subType: type, + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.year ?? result.aired?.prop?.from?.year ?? '', + dataSource: this.apiName, + id: result.mal_id, + } as SeriesModel), + ); + } + } + + return ret; + } + + async getById(id: string): Promise { + console.log(`MDB | api "${this.apiName}" queried by ID`); + + const searchUrl = `https://api.jikan.moe/v4/anime/${encodeURIComponent(id)}/full`; + const fetchData = await fetch(searchUrl); + + if (fetchData.status !== 200) { + throw Error(`MDB | Received status code ${fetchData.status} from an API.`); + } + + const data = await fetchData.json(); + console.debug(data); + const result = data.data; + + const type = this.typeMappings.get(result.type?.toLowerCase()); + if (type === undefined) { + const model = new MovieModel({ + subType: '', + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.year ?? result.aired?.prop?.from?.year ?? '', + dataSource: this.apiName, + url: result.url, + id: result.mal_id, + + plot: result.synopsis, + genres: result.genres?.map((x: any) => x.name) ?? [], + director: [], + writer: [], + studio: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown', + duration: result.duration ?? 'unknown', + onlineRating: result.score ?? 0, + actors: [], + image: result.images?.jpg?.image_url ? `![](${result.images?.jpg?.image_url})` : '', + + released: true, + premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', + streamingServices: result.streaming?.map((x: any) => x.name) ?? [], + + userData: { + watched: false, + lastWatched: '', + personalRating: 0, + }, + } as MovieModel); + + return model; + } + + if (type === 'movie' || type === 'special') { + const model = new MovieModel({ + subType: type, + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.year ?? result.aired?.prop?.from?.year ?? '', + dataSource: this.apiName, + url: result.url, + id: result.mal_id, + + plot: result.synopsis, + genres: result.genres?.map((x: any) => x.name) ?? [], + director: [], + writer: [], + studio: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown', + duration: result.duration ?? 'unknown', + onlineRating: result.score ?? 0, + actors: [], + image: result.images?.jpg?.image_url ? `![](${result.images?.jpg?.image_url})` : '', + + released: true, + premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', + streamingServices: result.streaming?.map((x: any) => x.name) ?? [], + + userData: { + watched: false, + lastWatched: '', + personalRating: 0, + }, + } as MovieModel); + + return model; + } else if (type === 'series' || type === 'ova') { + const model = new SeriesModel({ + subType: type, + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.year ?? result.aired?.prop?.from?.year ?? '', + dataSource: this.apiName, + url: result.url, + id: result.mal_id, + + genres: result.genres?.map((x: any) => x.name) ?? [], + writer: [], + studio: result.studios?.map((x: any) => x.name) ?? [], + episodes: result.episodes, + duration: result.duration ?? 'unknown', + onlineRating: result.score ?? 0, + streamingServices: result.streaming?.map((x: any) => x.name) ?? [], + image: result.images?.jpg?.image_url ? `![](${result.images?.jpg?.image_url})` : '', + + released: true, + 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, + + userData: { + watched: false, + lastWatched: '', + personalRating: 0, + }, + } as SeriesModel); + + return model; + } + + return; + } +} diff --git a/src/api/apis/OMDbAPI.ts b/src/api/apis/OMDbAPI.ts index 13308f6..8e4e594 100644 --- a/src/api/apis/OMDbAPI.ts +++ b/src/api/apis/OMDbAPI.ts @@ -1,223 +1,223 @@ -import { APIModel } from '../APIModel'; -import { MediaTypeModel } from '../../models/MediaTypeModel'; -import { MovieModel } from '../../models/MovieModel'; -import MediaDbPlugin from '../../main'; -import { SeriesModel } from '../../models/SeriesModel'; -import { GameModel } from '../../models/GameModel'; -import { MediaType } from '../../utils/MediaType'; - -export class OMDbAPI extends APIModel { - plugin: MediaDbPlugin; - typeMappings: Map; - apiDateFormat: string = 'DD MMM YYYY'; - - constructor(plugin: MediaDbPlugin) { - super(); - - this.plugin = plugin; - this.apiName = 'OMDbAPI'; - this.apiDescription = 'A free API for Movies, Series and Games.'; - this.apiUrl = 'http://www.omdbapi.com/'; - this.types = [MediaType.Movie, MediaType.Series, MediaType.Game]; - this.typeMappings = new Map(); - this.typeMappings.set('movie', 'movie'); - this.typeMappings.set('series', 'series'); - this.typeMappings.set('game', 'game'); - } - - async searchByTitle(title: string): Promise { - console.log(`MDB | api "${this.apiName}" queried by Title`); - - const searchUrl = `http://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`; - const fetchData = await fetch(searchUrl); - - if (fetchData.status === 401) { - throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); - } - if (fetchData.status !== 200) { - throw Error(`MDB | Received status code ${fetchData.status} from an API.`); - } - - const data = await fetchData.json(); - - if (data.Response === 'False') { - if (data.Error === 'Movie not found!') { - return []; - } - - throw Error(`MDB | Received error from ${this.apiName}: \n${JSON.stringify(data, undefined, 4)}`); - } - if (!data.Search) { - return []; - } - - console.debug(data.Search); - - const ret: MediaTypeModel[] = []; - - for (const result of data.Search) { - const type = this.typeMappings.get(result.Type.toLowerCase()); - if (type === undefined) { - continue; - } - if (type === 'movie') { - ret.push( - new MovieModel({ - type: type, - title: result.Title, - englishTitle: result.Title, - year: result.Year, - dataSource: this.apiName, - id: result.imdbID, - } as MovieModel), - ); - } else if (type === 'series') { - ret.push( - new SeriesModel({ - type: type, - title: result.Title, - englishTitle: result.Title, - year: result.Year, - dataSource: this.apiName, - id: result.imdbID, - } as SeriesModel), - ); - } else if (type === 'game') { - ret.push( - new GameModel({ - type: type, - title: result.Title, - englishTitle: result.Title, - year: result.Year, - dataSource: this.apiName, - id: result.imdbID, - } as GameModel), - ); - } - } - - return ret; - } - - async getById(id: string): Promise { - console.log(`MDB | api "${this.apiName}" queried by ID`); - - const searchUrl = `http://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`; - const fetchData = await fetch(searchUrl); - - if (fetchData.status === 401) { - throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); - } - if (fetchData.status !== 200) { - throw Error(`MDB | Received status code ${fetchData.status} from an API.`); - } - - const result = await fetchData.json(); - // console.debug(result); - - if (result.Response === 'False') { - throw Error(`MDB | Received error from ${this.apiName}: ${result.Error}`); - } - - const type = this.typeMappings.get(result.Type.toLowerCase()); - if (type === undefined) { - throw Error(`${result.type.toLowerCase()} is an unsupported type.`); - } - - if (type === 'movie') { - const model = new MovieModel({ - type: type, - title: result.Title, - englishTitle: result.Title, - year: result.Year, - dataSource: this.apiName, - url: `https://www.imdb.com/title/${result.imdbID}/`, - id: result.imdbID, - - plot: result.Plot ?? '', - genres: result.Genre?.split(', ') ?? [], - director: result.Director?.split(', ') ?? [], - writer: result.Writer?.split(', ') ?? [], - studio: ['N/A'], - duration: result.Runtime ?? 'unknown', - onlineRating: Number.parseFloat(result.imdbRating ?? 0), - actors: result.Actors?.split(', ') ?? [], - image: result.Poster ?? '', - - released: true, - streamingServices: [], - premiere: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', - - userData: { - watched: false, - lastWatched: '', - personalRating: 0, - }, - } as MovieModel); - - return model; - } else if (type === 'series') { - const model = new SeriesModel({ - type: type, - title: result.Title, - englishTitle: result.Title, - year: result.Year, - dataSource: this.apiName, - url: `https://www.imdb.com/title/${result.imdbID}/`, - id: result.imdbID, - - plot: result.Plot ?? '', - genres: result.Genre?.split(', ') ?? [], - writer: result.Writer?.split(', ') ?? [], - studio: [], - episodes: 0, - duration: result.Runtime ?? 'unknown', - onlineRating: Number.parseFloat(result.imdbRating ?? 0), - actors: result.Actors?.split(', ') ?? [], - image: result.Poster ?? '', - - released: true, - streamingServices: [], - airing: false, - airedFrom: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', - airedTo: 'unknown', - - userData: { - watched: false, - lastWatched: '', - personalRating: 0, - }, - } as SeriesModel); - - return model; - } else if (type === 'game') { - const model = new GameModel({ - type: type, - title: result.Title, - englishTitle: result.Title, - year: result.Year, - dataSource: this.apiName, - url: `https://www.imdb.com/title/${result.imdbID}/`, - id: result.imdbID, - - developers: [], - publishers: [], - genres: result.Genre?.split(', ') ?? [], - onlineRating: Number.parseFloat(result.imdbRating ?? 0), - image: result.Poster ?? '', - - released: true, - releaseDate: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', - - userData: { - played: false, - personalRating: 0, - }, - } as GameModel); - - return model; - } - - return; - } -} +import { APIModel } from '../APIModel'; +import { MediaTypeModel } from '../../models/MediaTypeModel'; +import { MovieModel } from '../../models/MovieModel'; +import MediaDbPlugin from '../../main'; +import { SeriesModel } from '../../models/SeriesModel'; +import { GameModel } from '../../models/GameModel'; +import { MediaType } from '../../utils/MediaType'; + +export class OMDbAPI extends APIModel { + plugin: MediaDbPlugin; + typeMappings: Map; + apiDateFormat: string = 'DD MMM YYYY'; + + constructor(plugin: MediaDbPlugin) { + super(); + + this.plugin = plugin; + this.apiName = 'OMDbAPI'; + this.apiDescription = 'A free API for Movies, Series and Games.'; + this.apiUrl = 'http://www.omdbapi.com/'; + this.types = [MediaType.Movie, MediaType.Series, MediaType.Game]; + this.typeMappings = new Map(); + this.typeMappings.set('movie', 'movie'); + this.typeMappings.set('series', 'series'); + this.typeMappings.set('game', 'game'); + } + + async searchByTitle(title: string): Promise { + console.log(`MDB | api "${this.apiName}" queried by Title`); + + const searchUrl = `http://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`; + const fetchData = await fetch(searchUrl); + + if (fetchData.status === 401) { + throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); + } + if (fetchData.status !== 200) { + throw Error(`MDB | Received status code ${fetchData.status} from an API.`); + } + + const data = await fetchData.json(); + + if (data.Response === 'False') { + if (data.Error === 'Movie not found!') { + return []; + } + + throw Error(`MDB | Received error from ${this.apiName}: \n${JSON.stringify(data, undefined, 4)}`); + } + if (!data.Search) { + return []; + } + + console.debug(data.Search); + + const ret: MediaTypeModel[] = []; + + for (const result of data.Search) { + const type = this.typeMappings.get(result.Type.toLowerCase()); + if (type === undefined) { + continue; + } + if (type === 'movie') { + ret.push( + new MovieModel({ + type: type, + title: result.Title, + englishTitle: result.Title, + year: result.Year, + dataSource: this.apiName, + id: result.imdbID, + } as MovieModel), + ); + } else if (type === 'series') { + ret.push( + new SeriesModel({ + type: type, + title: result.Title, + englishTitle: result.Title, + year: result.Year, + dataSource: this.apiName, + id: result.imdbID, + } as SeriesModel), + ); + } else if (type === 'game') { + ret.push( + new GameModel({ + type: type, + title: result.Title, + englishTitle: result.Title, + year: result.Year, + dataSource: this.apiName, + id: result.imdbID, + } as GameModel), + ); + } + } + + return ret; + } + + async getById(id: string): Promise { + console.log(`MDB | api "${this.apiName}" queried by ID`); + + const searchUrl = `http://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`; + const fetchData = await fetch(searchUrl); + + if (fetchData.status === 401) { + throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); + } + if (fetchData.status !== 200) { + throw Error(`MDB | Received status code ${fetchData.status} from an API.`); + } + + const result = await fetchData.json(); + // console.debug(result); + + if (result.Response === 'False') { + throw Error(`MDB | Received error from ${this.apiName}: ${result.Error}`); + } + + const type = this.typeMappings.get(result.Type.toLowerCase()); + if (type === undefined) { + throw Error(`${result.type.toLowerCase()} is an unsupported type.`); + } + + if (type === 'movie') { + const model = new MovieModel({ + type: type, + title: result.Title, + englishTitle: result.Title, + year: result.Year, + dataSource: this.apiName, + url: `https://www.imdb.com/title/${result.imdbID}/`, + id: result.imdbID, + + plot: result.Plot ?? '', + genres: result.Genre?.split(', ') ?? [], + director: result.Director?.split(', ') ?? [], + writer: result.Writer?.split(', ') ?? [], + studio: ['N/A'], + duration: result.Runtime ?? 'unknown', + onlineRating: Number.parseFloat(result.imdbRating ?? 0), + actors: result.Actors?.split(', ') ?? [], + image: result.Poster ? `"![](${result.Poster})"` : '', + + released: true, + streamingServices: [], + premiere: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', + + userData: { + watched: false, + lastWatched: '', + personalRating: 0, + }, + } as MovieModel); + + return model; + } else if (type === 'series') { + const model = new SeriesModel({ + type: type, + title: result.Title, + englishTitle: result.Title, + year: result.Year, + dataSource: this.apiName, + url: `https://www.imdb.com/title/${result.imdbID}/`, + id: result.imdbID, + + plot: result.Plot ?? '', + genres: result.Genre?.split(', ') ?? [], + writer: result.Writer?.split(', ') ?? [], + studio: [], + episodes: 0, + duration: result.Runtime ?? 'unknown', + onlineRating: Number.parseFloat(result.imdbRating ?? 0), + actors: result.Actors?.split(', ') ?? [], + image: result.Poster ? `![](${result.Poster})` : '', + + released: true, + streamingServices: [], + airing: false, + airedFrom: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', + airedTo: 'unknown', + + userData: { + watched: false, + lastWatched: '', + personalRating: 0, + }, + } as SeriesModel); + + return model; + } else if (type === 'game') { + const model = new GameModel({ + type: type, + title: result.Title, + englishTitle: result.Title, + year: result.Year, + dataSource: this.apiName, + url: `https://www.imdb.com/title/${result.imdbID}/`, + id: result.imdbID, + + developers: [], + publishers: [], + genres: result.Genre?.split(', ') ?? [], + onlineRating: Number.parseFloat(result.imdbRating ?? 0), + image: result.Poster ? `![](${result.Poster})` : '', + + released: true, + releaseDate: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', + + userData: { + played: false, + personalRating: 0, + }, + } as GameModel); + + return model; + } + + return; + } +} From ae5e0e442c933d2a196d4027e68041b09a6b9b09 Mon Sep 17 00:00:00 2001 From: ReconVirus Date: Thu, 2 May 2024 17:39:33 -0700 Subject: [PATCH 2/5] ran `bun run format` --- src/api/apis/MALAPI.ts | 406 ++++++++++++++++++------------------ src/api/apis/OMDbAPI.ts | 446 ++++++++++++++++++++-------------------- 2 files changed, 426 insertions(+), 426 deletions(-) diff --git a/src/api/apis/MALAPI.ts b/src/api/apis/MALAPI.ts index d262388..b55a2a2 100644 --- a/src/api/apis/MALAPI.ts +++ b/src/api/apis/MALAPI.ts @@ -1,203 +1,203 @@ -import { APIModel } from '../APIModel'; -import { MediaTypeModel } from '../../models/MediaTypeModel'; -import { MovieModel } from '../../models/MovieModel'; -import MediaDbPlugin from '../../main'; -import { SeriesModel } from '../../models/SeriesModel'; -import { MediaType } from '../../utils/MediaType'; - -export class MALAPI extends APIModel { - plugin: MediaDbPlugin; - typeMappings: Map; - apiDateFormat: string = 'YYYY-MM-DDTHH:mm:ssZ'; // ISO - - constructor(plugin: MediaDbPlugin) { - super(); - - this.plugin = plugin; - this.apiName = 'MALAPI'; - this.apiDescription = 'A free API for Anime. Some results may take a long time to load.'; - this.apiUrl = 'https://jikan.moe/'; - this.types = [MediaType.Movie, MediaType.Series]; - this.typeMappings = new Map(); - this.typeMappings.set('movie', 'movie'); - this.typeMappings.set('special', 'special'); - this.typeMappings.set('tv', 'series'); - this.typeMappings.set('ova', 'ova'); - } - - async searchByTitle(title: string): Promise { - console.log(`MDB | api "${this.apiName}" queried by Title`); - - const searchUrl = `https://api.jikan.moe/v4/anime?q=${encodeURIComponent(title)}&limit=20${this.plugin.settings.sfwFilter ? '&sfw' : ''}`; - - const fetchData = await fetch(searchUrl); - console.debug(fetchData); - if (fetchData.status !== 200) { - throw Error(`MDB | Received status code ${fetchData.status} from an API.`); - } - const data = await fetchData.json(); - - console.debug(data); - - const ret: MediaTypeModel[] = []; - - for (const result of data.data) { - const type = this.typeMappings.get(result.type?.toLowerCase()); - if (type === undefined) { - ret.push( - new MovieModel({ - subType: '', - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.year ?? result.aired?.prop?.from?.year ?? '', - dataSource: this.apiName, - id: result.mal_id, - } as MovieModel), - ); - } - if (type === 'movie' || type === 'special') { - ret.push( - new MovieModel({ - subType: type, - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.year ?? result.aired?.prop?.from?.year ?? '', - dataSource: this.apiName, - id: result.mal_id, - } as MovieModel), - ); - } else if (type === 'series' || type === 'ova') { - ret.push( - new SeriesModel({ - subType: type, - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.year ?? result.aired?.prop?.from?.year ?? '', - dataSource: this.apiName, - id: result.mal_id, - } as SeriesModel), - ); - } - } - - return ret; - } - - async getById(id: string): Promise { - console.log(`MDB | api "${this.apiName}" queried by ID`); - - const searchUrl = `https://api.jikan.moe/v4/anime/${encodeURIComponent(id)}/full`; - const fetchData = await fetch(searchUrl); - - if (fetchData.status !== 200) { - throw Error(`MDB | Received status code ${fetchData.status} from an API.`); - } - - const data = await fetchData.json(); - console.debug(data); - const result = data.data; - - const type = this.typeMappings.get(result.type?.toLowerCase()); - if (type === undefined) { - const model = new MovieModel({ - subType: '', - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.year ?? result.aired?.prop?.from?.year ?? '', - dataSource: this.apiName, - url: result.url, - id: result.mal_id, - - plot: result.synopsis, - genres: result.genres?.map((x: any) => x.name) ?? [], - director: [], - writer: [], - studio: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown', - duration: result.duration ?? 'unknown', - onlineRating: result.score ?? 0, - actors: [], - image: result.images?.jpg?.image_url ? `![](${result.images?.jpg?.image_url})` : '', - - released: true, - premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', - streamingServices: result.streaming?.map((x: any) => x.name) ?? [], - - userData: { - watched: false, - lastWatched: '', - personalRating: 0, - }, - } as MovieModel); - - return model; - } - - if (type === 'movie' || type === 'special') { - const model = new MovieModel({ - subType: type, - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.year ?? result.aired?.prop?.from?.year ?? '', - dataSource: this.apiName, - url: result.url, - id: result.mal_id, - - plot: result.synopsis, - genres: result.genres?.map((x: any) => x.name) ?? [], - director: [], - writer: [], - studio: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown', - duration: result.duration ?? 'unknown', - onlineRating: result.score ?? 0, - actors: [], - image: result.images?.jpg?.image_url ? `![](${result.images?.jpg?.image_url})` : '', - - released: true, - premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', - streamingServices: result.streaming?.map((x: any) => x.name) ?? [], - - userData: { - watched: false, - lastWatched: '', - personalRating: 0, - }, - } as MovieModel); - - return model; - } else if (type === 'series' || type === 'ova') { - const model = new SeriesModel({ - subType: type, - title: result.title, - englishTitle: result.title_english ?? result.title, - year: result.year ?? result.aired?.prop?.from?.year ?? '', - dataSource: this.apiName, - url: result.url, - id: result.mal_id, - - genres: result.genres?.map((x: any) => x.name) ?? [], - writer: [], - studio: result.studios?.map((x: any) => x.name) ?? [], - episodes: result.episodes, - duration: result.duration ?? 'unknown', - onlineRating: result.score ?? 0, - streamingServices: result.streaming?.map((x: any) => x.name) ?? [], - image: result.images?.jpg?.image_url ? `![](${result.images?.jpg?.image_url})` : '', - - released: true, - 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, - - userData: { - watched: false, - lastWatched: '', - personalRating: 0, - }, - } as SeriesModel); - - return model; - } - - return; - } -} +import { APIModel } from '../APIModel'; +import { MediaTypeModel } from '../../models/MediaTypeModel'; +import { MovieModel } from '../../models/MovieModel'; +import MediaDbPlugin from '../../main'; +import { SeriesModel } from '../../models/SeriesModel'; +import { MediaType } from '../../utils/MediaType'; + +export class MALAPI extends APIModel { + plugin: MediaDbPlugin; + typeMappings: Map; + apiDateFormat: string = 'YYYY-MM-DDTHH:mm:ssZ'; // ISO + + constructor(plugin: MediaDbPlugin) { + super(); + + this.plugin = plugin; + this.apiName = 'MALAPI'; + this.apiDescription = 'A free API for Anime. Some results may take a long time to load.'; + this.apiUrl = 'https://jikan.moe/'; + this.types = [MediaType.Movie, MediaType.Series]; + this.typeMappings = new Map(); + this.typeMappings.set('movie', 'movie'); + this.typeMappings.set('special', 'special'); + this.typeMappings.set('tv', 'series'); + this.typeMappings.set('ova', 'ova'); + } + + async searchByTitle(title: string): Promise { + console.log(`MDB | api "${this.apiName}" queried by Title`); + + const searchUrl = `https://api.jikan.moe/v4/anime?q=${encodeURIComponent(title)}&limit=20${this.plugin.settings.sfwFilter ? '&sfw' : ''}`; + + const fetchData = await fetch(searchUrl); + console.debug(fetchData); + if (fetchData.status !== 200) { + throw Error(`MDB | Received status code ${fetchData.status} from an API.`); + } + const data = await fetchData.json(); + + console.debug(data); + + const ret: MediaTypeModel[] = []; + + for (const result of data.data) { + const type = this.typeMappings.get(result.type?.toLowerCase()); + if (type === undefined) { + ret.push( + new MovieModel({ + subType: '', + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.year ?? result.aired?.prop?.from?.year ?? '', + dataSource: this.apiName, + id: result.mal_id, + } as MovieModel), + ); + } + if (type === 'movie' || type === 'special') { + ret.push( + new MovieModel({ + subType: type, + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.year ?? result.aired?.prop?.from?.year ?? '', + dataSource: this.apiName, + id: result.mal_id, + } as MovieModel), + ); + } else if (type === 'series' || type === 'ova') { + ret.push( + new SeriesModel({ + subType: type, + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.year ?? result.aired?.prop?.from?.year ?? '', + dataSource: this.apiName, + id: result.mal_id, + } as SeriesModel), + ); + } + } + + return ret; + } + + async getById(id: string): Promise { + console.log(`MDB | api "${this.apiName}" queried by ID`); + + const searchUrl = `https://api.jikan.moe/v4/anime/${encodeURIComponent(id)}/full`; + const fetchData = await fetch(searchUrl); + + if (fetchData.status !== 200) { + throw Error(`MDB | Received status code ${fetchData.status} from an API.`); + } + + const data = await fetchData.json(); + console.debug(data); + const result = data.data; + + const type = this.typeMappings.get(result.type?.toLowerCase()); + if (type === undefined) { + const model = new MovieModel({ + subType: '', + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.year ?? result.aired?.prop?.from?.year ?? '', + dataSource: this.apiName, + url: result.url, + id: result.mal_id, + + plot: result.synopsis, + genres: result.genres?.map((x: any) => x.name) ?? [], + director: [], + writer: [], + studio: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown', + duration: result.duration ?? 'unknown', + onlineRating: result.score ?? 0, + actors: [], + image: result.images?.jpg?.image_url ? `![](${result.images?.jpg?.image_url})` : '', + + released: true, + premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', + streamingServices: result.streaming?.map((x: any) => x.name) ?? [], + + userData: { + watched: false, + lastWatched: '', + personalRating: 0, + }, + } as MovieModel); + + return model; + } + + if (type === 'movie' || type === 'special') { + const model = new MovieModel({ + subType: type, + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.year ?? result.aired?.prop?.from?.year ?? '', + dataSource: this.apiName, + url: result.url, + id: result.mal_id, + + plot: result.synopsis, + genres: result.genres?.map((x: any) => x.name) ?? [], + director: [], + writer: [], + studio: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown', + duration: result.duration ?? 'unknown', + onlineRating: result.score ?? 0, + actors: [], + image: result.images?.jpg?.image_url ? `![](${result.images?.jpg?.image_url})` : '', + + released: true, + premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', + streamingServices: result.streaming?.map((x: any) => x.name) ?? [], + + userData: { + watched: false, + lastWatched: '', + personalRating: 0, + }, + } as MovieModel); + + return model; + } else if (type === 'series' || type === 'ova') { + const model = new SeriesModel({ + subType: type, + title: result.title, + englishTitle: result.title_english ?? result.title, + year: result.year ?? result.aired?.prop?.from?.year ?? '', + dataSource: this.apiName, + url: result.url, + id: result.mal_id, + + genres: result.genres?.map((x: any) => x.name) ?? [], + writer: [], + studio: result.studios?.map((x: any) => x.name) ?? [], + episodes: result.episodes, + duration: result.duration ?? 'unknown', + onlineRating: result.score ?? 0, + streamingServices: result.streaming?.map((x: any) => x.name) ?? [], + image: result.images?.jpg?.image_url ? `![](${result.images?.jpg?.image_url})` : '', + + released: true, + 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, + + userData: { + watched: false, + lastWatched: '', + personalRating: 0, + }, + } as SeriesModel); + + return model; + } + + return; + } +} diff --git a/src/api/apis/OMDbAPI.ts b/src/api/apis/OMDbAPI.ts index 8e4e594..c873324 100644 --- a/src/api/apis/OMDbAPI.ts +++ b/src/api/apis/OMDbAPI.ts @@ -1,223 +1,223 @@ -import { APIModel } from '../APIModel'; -import { MediaTypeModel } from '../../models/MediaTypeModel'; -import { MovieModel } from '../../models/MovieModel'; -import MediaDbPlugin from '../../main'; -import { SeriesModel } from '../../models/SeriesModel'; -import { GameModel } from '../../models/GameModel'; -import { MediaType } from '../../utils/MediaType'; - -export class OMDbAPI extends APIModel { - plugin: MediaDbPlugin; - typeMappings: Map; - apiDateFormat: string = 'DD MMM YYYY'; - - constructor(plugin: MediaDbPlugin) { - super(); - - this.plugin = plugin; - this.apiName = 'OMDbAPI'; - this.apiDescription = 'A free API for Movies, Series and Games.'; - this.apiUrl = 'http://www.omdbapi.com/'; - this.types = [MediaType.Movie, MediaType.Series, MediaType.Game]; - this.typeMappings = new Map(); - this.typeMappings.set('movie', 'movie'); - this.typeMappings.set('series', 'series'); - this.typeMappings.set('game', 'game'); - } - - async searchByTitle(title: string): Promise { - console.log(`MDB | api "${this.apiName}" queried by Title`); - - const searchUrl = `http://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`; - const fetchData = await fetch(searchUrl); - - if (fetchData.status === 401) { - throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); - } - if (fetchData.status !== 200) { - throw Error(`MDB | Received status code ${fetchData.status} from an API.`); - } - - const data = await fetchData.json(); - - if (data.Response === 'False') { - if (data.Error === 'Movie not found!') { - return []; - } - - throw Error(`MDB | Received error from ${this.apiName}: \n${JSON.stringify(data, undefined, 4)}`); - } - if (!data.Search) { - return []; - } - - console.debug(data.Search); - - const ret: MediaTypeModel[] = []; - - for (const result of data.Search) { - const type = this.typeMappings.get(result.Type.toLowerCase()); - if (type === undefined) { - continue; - } - if (type === 'movie') { - ret.push( - new MovieModel({ - type: type, - title: result.Title, - englishTitle: result.Title, - year: result.Year, - dataSource: this.apiName, - id: result.imdbID, - } as MovieModel), - ); - } else if (type === 'series') { - ret.push( - new SeriesModel({ - type: type, - title: result.Title, - englishTitle: result.Title, - year: result.Year, - dataSource: this.apiName, - id: result.imdbID, - } as SeriesModel), - ); - } else if (type === 'game') { - ret.push( - new GameModel({ - type: type, - title: result.Title, - englishTitle: result.Title, - year: result.Year, - dataSource: this.apiName, - id: result.imdbID, - } as GameModel), - ); - } - } - - return ret; - } - - async getById(id: string): Promise { - console.log(`MDB | api "${this.apiName}" queried by ID`); - - const searchUrl = `http://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`; - const fetchData = await fetch(searchUrl); - - if (fetchData.status === 401) { - throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); - } - if (fetchData.status !== 200) { - throw Error(`MDB | Received status code ${fetchData.status} from an API.`); - } - - const result = await fetchData.json(); - // console.debug(result); - - if (result.Response === 'False') { - throw Error(`MDB | Received error from ${this.apiName}: ${result.Error}`); - } - - const type = this.typeMappings.get(result.Type.toLowerCase()); - if (type === undefined) { - throw Error(`${result.type.toLowerCase()} is an unsupported type.`); - } - - if (type === 'movie') { - const model = new MovieModel({ - type: type, - title: result.Title, - englishTitle: result.Title, - year: result.Year, - dataSource: this.apiName, - url: `https://www.imdb.com/title/${result.imdbID}/`, - id: result.imdbID, - - plot: result.Plot ?? '', - genres: result.Genre?.split(', ') ?? [], - director: result.Director?.split(', ') ?? [], - writer: result.Writer?.split(', ') ?? [], - studio: ['N/A'], - duration: result.Runtime ?? 'unknown', - onlineRating: Number.parseFloat(result.imdbRating ?? 0), - actors: result.Actors?.split(', ') ?? [], - image: result.Poster ? `"![](${result.Poster})"` : '', - - released: true, - streamingServices: [], - premiere: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', - - userData: { - watched: false, - lastWatched: '', - personalRating: 0, - }, - } as MovieModel); - - return model; - } else if (type === 'series') { - const model = new SeriesModel({ - type: type, - title: result.Title, - englishTitle: result.Title, - year: result.Year, - dataSource: this.apiName, - url: `https://www.imdb.com/title/${result.imdbID}/`, - id: result.imdbID, - - plot: result.Plot ?? '', - genres: result.Genre?.split(', ') ?? [], - writer: result.Writer?.split(', ') ?? [], - studio: [], - episodes: 0, - duration: result.Runtime ?? 'unknown', - onlineRating: Number.parseFloat(result.imdbRating ?? 0), - actors: result.Actors?.split(', ') ?? [], - image: result.Poster ? `![](${result.Poster})` : '', - - released: true, - streamingServices: [], - airing: false, - airedFrom: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', - airedTo: 'unknown', - - userData: { - watched: false, - lastWatched: '', - personalRating: 0, - }, - } as SeriesModel); - - return model; - } else if (type === 'game') { - const model = new GameModel({ - type: type, - title: result.Title, - englishTitle: result.Title, - year: result.Year, - dataSource: this.apiName, - url: `https://www.imdb.com/title/${result.imdbID}/`, - id: result.imdbID, - - developers: [], - publishers: [], - genres: result.Genre?.split(', ') ?? [], - onlineRating: Number.parseFloat(result.imdbRating ?? 0), - image: result.Poster ? `![](${result.Poster})` : '', - - released: true, - releaseDate: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', - - userData: { - played: false, - personalRating: 0, - }, - } as GameModel); - - return model; - } - - return; - } -} +import { APIModel } from '../APIModel'; +import { MediaTypeModel } from '../../models/MediaTypeModel'; +import { MovieModel } from '../../models/MovieModel'; +import MediaDbPlugin from '../../main'; +import { SeriesModel } from '../../models/SeriesModel'; +import { GameModel } from '../../models/GameModel'; +import { MediaType } from '../../utils/MediaType'; + +export class OMDbAPI extends APIModel { + plugin: MediaDbPlugin; + typeMappings: Map; + apiDateFormat: string = 'DD MMM YYYY'; + + constructor(plugin: MediaDbPlugin) { + super(); + + this.plugin = plugin; + this.apiName = 'OMDbAPI'; + this.apiDescription = 'A free API for Movies, Series and Games.'; + this.apiUrl = 'http://www.omdbapi.com/'; + this.types = [MediaType.Movie, MediaType.Series, MediaType.Game]; + this.typeMappings = new Map(); + this.typeMappings.set('movie', 'movie'); + this.typeMappings.set('series', 'series'); + this.typeMappings.set('game', 'game'); + } + + async searchByTitle(title: string): Promise { + console.log(`MDB | api "${this.apiName}" queried by Title`); + + const searchUrl = `http://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`; + const fetchData = await fetch(searchUrl); + + if (fetchData.status === 401) { + throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); + } + if (fetchData.status !== 200) { + throw Error(`MDB | Received status code ${fetchData.status} from an API.`); + } + + const data = await fetchData.json(); + + if (data.Response === 'False') { + if (data.Error === 'Movie not found!') { + return []; + } + + throw Error(`MDB | Received error from ${this.apiName}: \n${JSON.stringify(data, undefined, 4)}`); + } + if (!data.Search) { + return []; + } + + console.debug(data.Search); + + const ret: MediaTypeModel[] = []; + + for (const result of data.Search) { + const type = this.typeMappings.get(result.Type.toLowerCase()); + if (type === undefined) { + continue; + } + if (type === 'movie') { + ret.push( + new MovieModel({ + type: type, + title: result.Title, + englishTitle: result.Title, + year: result.Year, + dataSource: this.apiName, + id: result.imdbID, + } as MovieModel), + ); + } else if (type === 'series') { + ret.push( + new SeriesModel({ + type: type, + title: result.Title, + englishTitle: result.Title, + year: result.Year, + dataSource: this.apiName, + id: result.imdbID, + } as SeriesModel), + ); + } else if (type === 'game') { + ret.push( + new GameModel({ + type: type, + title: result.Title, + englishTitle: result.Title, + year: result.Year, + dataSource: this.apiName, + id: result.imdbID, + } as GameModel), + ); + } + } + + return ret; + } + + async getById(id: string): Promise { + console.log(`MDB | api "${this.apiName}" queried by ID`); + + const searchUrl = `http://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`; + const fetchData = await fetch(searchUrl); + + if (fetchData.status === 401) { + throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); + } + if (fetchData.status !== 200) { + throw Error(`MDB | Received status code ${fetchData.status} from an API.`); + } + + const result = await fetchData.json(); + // console.debug(result); + + if (result.Response === 'False') { + throw Error(`MDB | Received error from ${this.apiName}: ${result.Error}`); + } + + const type = this.typeMappings.get(result.Type.toLowerCase()); + if (type === undefined) { + throw Error(`${result.type.toLowerCase()} is an unsupported type.`); + } + + if (type === 'movie') { + const model = new MovieModel({ + type: type, + title: result.Title, + englishTitle: result.Title, + year: result.Year, + dataSource: this.apiName, + url: `https://www.imdb.com/title/${result.imdbID}/`, + id: result.imdbID, + + plot: result.Plot ?? '', + genres: result.Genre?.split(', ') ?? [], + director: result.Director?.split(', ') ?? [], + writer: result.Writer?.split(', ') ?? [], + studio: ['N/A'], + duration: result.Runtime ?? 'unknown', + onlineRating: Number.parseFloat(result.imdbRating ?? 0), + actors: result.Actors?.split(', ') ?? [], + image: result.Poster ? `"![](${result.Poster})"` : '', + + released: true, + streamingServices: [], + premiere: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', + + userData: { + watched: false, + lastWatched: '', + personalRating: 0, + }, + } as MovieModel); + + return model; + } else if (type === 'series') { + const model = new SeriesModel({ + type: type, + title: result.Title, + englishTitle: result.Title, + year: result.Year, + dataSource: this.apiName, + url: `https://www.imdb.com/title/${result.imdbID}/`, + id: result.imdbID, + + plot: result.Plot ?? '', + genres: result.Genre?.split(', ') ?? [], + writer: result.Writer?.split(', ') ?? [], + studio: [], + episodes: 0, + duration: result.Runtime ?? 'unknown', + onlineRating: Number.parseFloat(result.imdbRating ?? 0), + actors: result.Actors?.split(', ') ?? [], + image: result.Poster ? `![](${result.Poster})` : '', + + released: true, + streamingServices: [], + airing: false, + airedFrom: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', + airedTo: 'unknown', + + userData: { + watched: false, + lastWatched: '', + personalRating: 0, + }, + } as SeriesModel); + + return model; + } else if (type === 'game') { + const model = new GameModel({ + type: type, + title: result.Title, + englishTitle: result.Title, + year: result.Year, + dataSource: this.apiName, + url: `https://www.imdb.com/title/${result.imdbID}/`, + id: result.imdbID, + + developers: [], + publishers: [], + genres: result.Genre?.split(', ') ?? [], + onlineRating: Number.parseFloat(result.imdbRating ?? 0), + image: result.Poster ? `![](${result.Poster})` : '', + + released: true, + releaseDate: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', + + userData: { + played: false, + personalRating: 0, + }, + } as GameModel); + + return model; + } + + return; + } +} From 8335112bb2df0436b61e04cb92aa4f6276832fe9 Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Sun, 12 May 2024 20:20:34 +0200 Subject: [PATCH 3/5] Added an option for the poster embeds and also added embeds to the other apis --- src/api/apis/BoardGameGeekAPI.ts | 4 +++- src/api/apis/MALAPI.ts | 7 ++++--- src/api/apis/MALAPIManga.ts | 4 ++-- src/api/apis/MobyGamesAPI.ts | 2 +- src/api/apis/MusicBrainzAPI.ts | 8 ++++++-- src/api/apis/OMDbAPI.ts | 6 +++--- src/api/apis/OpenLibraryAPI.ts | 4 +++- src/api/apis/SteamAPI.ts | 2 +- src/settings/Settings.ts | 11 +++++++++++ 9 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/api/apis/BoardGameGeekAPI.ts b/src/api/apis/BoardGameGeekAPI.ts index 6480380..8692b75 100644 --- a/src/api/apis/BoardGameGeekAPI.ts +++ b/src/api/apis/BoardGameGeekAPI.ts @@ -75,7 +75,9 @@ export class BoardGameGeekAPI extends APIModel { const boardgame = response.querySelector('boardgame')!; const title = boardgame.querySelector('name[primary=true]')!.textContent!; const year = boardgame.querySelector('yearpublished')?.textContent ?? ''; - const image = boardgame.querySelector('image')?.textContent ?? undefined; + const image = this.plugin.settings.embedPosters + ? `![](${boardgame.querySelector('image')?.textContent ?? undefined})` + : boardgame.querySelector('image')?.textContent ?? undefined; const onlineRating = Number.parseFloat(boardgame.querySelector('statistics ratings average')?.textContent ?? '0'); const genres = Array.from(boardgame.querySelectorAll('boardgamecategory')).map(n => n!.textContent!); const complexityRating = Number.parseFloat(boardgame.querySelector('averageweight')?.textContent ?? '0'); diff --git a/src/api/apis/MALAPI.ts b/src/api/apis/MALAPI.ts index b55a2a2..f512753 100644 --- a/src/api/apis/MALAPI.ts +++ b/src/api/apis/MALAPI.ts @@ -116,7 +116,7 @@ export class MALAPI extends APIModel { duration: result.duration ?? 'unknown', onlineRating: result.score ?? 0, actors: [], - image: result.images?.jpg?.image_url ? `![](${result.images?.jpg?.image_url})` : '', + image: this.plugin.settings.embedPosters ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', released: true, premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', @@ -150,7 +150,7 @@ export class MALAPI extends APIModel { duration: result.duration ?? 'unknown', onlineRating: result.score ?? 0, actors: [], - image: result.images?.jpg?.image_url ? `![](${result.images?.jpg?.image_url})` : '', + image: this.plugin.settings.embedPosters ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', released: true, premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', @@ -174,6 +174,7 @@ export class MALAPI extends APIModel { url: result.url, id: result.mal_id, + plot: result.synopsis, genres: result.genres?.map((x: any) => x.name) ?? [], writer: [], studio: result.studios?.map((x: any) => x.name) ?? [], @@ -181,7 +182,7 @@ export class MALAPI extends APIModel { duration: result.duration ?? 'unknown', onlineRating: result.score ?? 0, streamingServices: result.streaming?.map((x: any) => x.name) ?? [], - image: result.images?.jpg?.image_url ? `![](${result.images?.jpg?.image_url})` : '', + image: this.plugin.settings.embedPosters ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', released: true, airedFrom: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', diff --git a/src/api/apis/MALAPIManga.ts b/src/api/apis/MALAPIManga.ts index 7cea003..75731ee 100644 --- a/src/api/apis/MALAPIManga.ts +++ b/src/api/apis/MALAPIManga.ts @@ -61,7 +61,7 @@ export class MALAPIManga extends APIModel { chapters: result.chapters, volumes: result.volumes, onlineRating: result.score ?? 0, - image: result.images?.jpg?.image_url ?? '', + image: this.plugin.settings.embedPosters ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', released: true, publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown', @@ -111,7 +111,7 @@ export class MALAPIManga extends APIModel { chapters: result.chapters, volumes: result.volumes, onlineRating: result.score ?? 0, - image: result.images?.jpg?.image_url ?? '', + image: this.plugin.settings.embedPosters ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', released: true, publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown', diff --git a/src/api/apis/MobyGamesAPI.ts b/src/api/apis/MobyGamesAPI.ts index adbefb2..7f28f15 100644 --- a/src/api/apis/MobyGamesAPI.ts +++ b/src/api/apis/MobyGamesAPI.ts @@ -86,7 +86,7 @@ export class MobyGamesAPI extends APIModel { publishers: [], genres: result.genres?.map((x: any) => x.genre_name) ?? [], onlineRating: result.moby_score, - image: result.sample_cover.image ?? '', + image: this.plugin.settings.embedPosters ? `![](${result.sample_cover.image ?? ''})` ?? '' : result.sample_cover.image ?? '', released: true, releaseDate: result.platforms[0].first_release_date ?? 'unknown', diff --git a/src/api/apis/MusicBrainzAPI.ts b/src/api/apis/MusicBrainzAPI.ts index b927f37..d14d5d5 100644 --- a/src/api/apis/MusicBrainzAPI.ts +++ b/src/api/apis/MusicBrainzAPI.ts @@ -51,7 +51,9 @@ 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: this.plugin.settings.embedPosters + ? `![](${'https://coverartarchive.org/release-group/' + result.id + '/front'})` + : 'https://coverartarchive.org/release-group/' + result.id + '/front', artists: result['artist-credit'].map((a: any) => a.name), subType: result['primary-type'], @@ -89,7 +91,9 @@ 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: this.plugin.settings.embedPosters + ? `![](${'https://coverartarchive.org/release-group/' + result.id + '/front'})` + : 'https://coverartarchive.org/release-group/' + result.id + '/front', artists: result['artist-credit'].map((a: any) => a.name), genres: result.genres.map((g: any) => g.name), diff --git a/src/api/apis/OMDbAPI.ts b/src/api/apis/OMDbAPI.ts index c873324..95df0c0 100644 --- a/src/api/apis/OMDbAPI.ts +++ b/src/api/apis/OMDbAPI.ts @@ -142,7 +142,7 @@ export class OMDbAPI extends APIModel { duration: result.Runtime ?? 'unknown', onlineRating: Number.parseFloat(result.imdbRating ?? 0), actors: result.Actors?.split(', ') ?? [], - image: result.Poster ? `"![](${result.Poster})"` : '', + image: this.plugin.settings.embedPosters ? (result.Poster ? `![](${result.Poster})` : '') : result.Poster ? result.Poster : '', released: true, streamingServices: [], @@ -174,7 +174,7 @@ export class OMDbAPI extends APIModel { duration: result.Runtime ?? 'unknown', onlineRating: Number.parseFloat(result.imdbRating ?? 0), actors: result.Actors?.split(', ') ?? [], - image: result.Poster ? `![](${result.Poster})` : '', + image: this.plugin.settings.embedPosters ? (result.Poster ? `![](${result.Poster})` : '') : result.Poster ? result.Poster : '', released: true, streamingServices: [], @@ -204,7 +204,7 @@ export class OMDbAPI extends APIModel { publishers: [], genres: result.Genre?.split(', ') ?? [], onlineRating: Number.parseFloat(result.imdbRating ?? 0), - image: result.Poster ? `![](${result.Poster})` : '', + image: this.plugin.settings.embedPosters ? (result.Poster ? `![](${result.Poster})` : '') : result.Poster ? result.Poster : '', released: true, releaseDate: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', diff --git a/src/api/apis/OpenLibraryAPI.ts b/src/api/apis/OpenLibraryAPI.ts index 725db0e..55c8f63 100644 --- a/src/api/apis/OpenLibraryAPI.ts +++ b/src/api/apis/OpenLibraryAPI.ts @@ -78,7 +78,9 @@ export class OpenLibraryAPI extends APIModel { plot: result.description ?? '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`, + image: this.plugin.settings.embedPosters + ? `![](${`https://covers.openlibrary.org/b/OLID/` + result.cover_edition_key + `-L.jpg`}` + : `https://covers.openlibrary.org/b/OLID/` + result.cover_edition_key + `-L.jpg`, released: true, diff --git a/src/api/apis/SteamAPI.ts b/src/api/apis/SteamAPI.ts index 45182e0..69c88e7 100644 --- a/src/api/apis/SteamAPI.ts +++ b/src/api/apis/SteamAPI.ts @@ -115,7 +115,7 @@ export class SteamAPI extends APIModel { publishers: result['publishers'], genres: result.genres?.map((x: any) => x.description) ?? [], onlineRating: Number.parseFloat(result.metacritic?.score ?? 0), - image: result.header_image ?? '', + image: this.plugin.settings.embedPosters ? `![](${result.header_image ?? ''})` : result.header_image ?? '', released: !result.release_date?.comming_soon, releaseDate: this.plugin.dateFormatter.format(result.release_date?.date, this.apiDateFormat) ?? 'unknown', diff --git a/src/settings/Settings.ts b/src/settings/Settings.ts index 5d91d47..9c696f5 100644 --- a/src/settings/Settings.ts +++ b/src/settings/Settings.ts @@ -18,6 +18,7 @@ export interface MediaDbPluginSettings { openNoteInNewTab: boolean; useDefaultFrontMatter: boolean; enableTemplaterIntegration: boolean; + embedPosters: boolean; apiToggle: { OMDbAPI: { movie: boolean; @@ -83,6 +84,7 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = { openNoteInNewTab: true, useDefaultFrontMatter: true, enableTemplaterIntegration: false, + embedPosters: false, apiToggle: { OMDbAPI: { movie: true, @@ -279,6 +281,15 @@ export class MediaDbSettingTab extends PluginSettingTab { void this.plugin.saveSettings(); }); }); + new Setting(containerEl) + .setName('Embed posters in YAML') + .setDesc('Embed the poster urls as images in the yaml to integrate with dataview.') + .addToggle(cb => { + cb.setValue(this.plugin.settings.embedPosters).onChange(data => { + this.plugin.settings.embedPosters = data; + void this.plugin.saveSettings(); + }); + }); containerEl.createEl('h3', { text: 'APIs Per Media Type' }); containerEl.createEl('h5', { text: 'Movies' }); From 125467180efddc7ddcab2d1323ac11e9963bddf9 Mon Sep 17 00:00:00 2001 From: ReconVirus Date: Tue, 14 May 2024 03:06:42 -0700 Subject: [PATCH 4/5] adding a replace('[Written by MAL Rewrite]' --- src/api/apis/MALAPI.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/apis/MALAPI.ts b/src/api/apis/MALAPI.ts index f512753..5d33f10 100644 --- a/src/api/apis/MALAPI.ts +++ b/src/api/apis/MALAPI.ts @@ -108,7 +108,7 @@ export class MALAPI extends APIModel { url: result.url, id: result.mal_id, - plot: result.synopsis, + plot: result.synopsis ? result.synopsis.replace('[Written by MAL Rewrite]', '').trim() : '', genres: result.genres?.map((x: any) => x.name) ?? [], director: [], writer: [], @@ -174,7 +174,7 @@ export class MALAPI extends APIModel { url: result.url, id: result.mal_id, - plot: result.synopsis, + plot: result.synopsis ? result.synopsis.replace('[Written by MAL Rewrite]', '').trim() : '', genres: result.genres?.map((x: any) => x.name) ?? [], writer: [], studio: result.studios?.map((x: any) => x.name) ?? [], From 3d865dba50d2a1ac18ec1e04e80978c11b625343 Mon Sep 17 00:00:00 2001 From: ReconVirus Date: Thu, 30 May 2024 06:09:55 -0700 Subject: [PATCH 5/5] added a processImageLink helper function to handle ternary operator --- src/api/apis/BoardGameGeekAPI.ts | 9 ++++++--- src/api/apis/MALAPI.ts | 6 +++--- src/api/apis/MALAPIManga.ts | 4 ++-- src/api/apis/MobyGamesAPI.ts | 2 +- src/api/apis/MusicBrainzAPI.ts | 4 ++-- src/api/apis/OMDbAPI.ts | 6 +++--- src/api/apis/OpenLibraryAPI.ts | 2 +- src/api/apis/SteamAPI.ts | 2 +- src/settings/Settings.ts | 12 ++++++------ 9 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/api/apis/BoardGameGeekAPI.ts b/src/api/apis/BoardGameGeekAPI.ts index 8692b75..eb395ef 100644 --- a/src/api/apis/BoardGameGeekAPI.ts +++ b/src/api/apis/BoardGameGeekAPI.ts @@ -18,6 +18,11 @@ export class BoardGameGeekAPI extends APIModel { this.types = [MediaType.BoardGame]; } + processImageLink(boardgameElement: { querySelector: (arg0: string) => { (): any; new (): any; textContent: any } }) { + const imageContent = boardgameElement.querySelector('image')?.textContent; + return this.plugin.settings.generateEmbedLinksForImages && imageContent ? `![](${imageContent})` : imageContent ?? undefined; + } + async searchByTitle(title: string): Promise { console.log(`MDB | api "${this.apiName}" queried by Title`); @@ -75,9 +80,7 @@ export class BoardGameGeekAPI extends APIModel { const boardgame = response.querySelector('boardgame')!; const title = boardgame.querySelector('name[primary=true]')!.textContent!; const year = boardgame.querySelector('yearpublished')?.textContent ?? ''; - const image = this.plugin.settings.embedPosters - ? `![](${boardgame.querySelector('image')?.textContent ?? undefined})` - : boardgame.querySelector('image')?.textContent ?? undefined; + const image = this.processImageLink(boardgame); const onlineRating = Number.parseFloat(boardgame.querySelector('statistics ratings average')?.textContent ?? '0'); const genres = Array.from(boardgame.querySelectorAll('boardgamecategory')).map(n => n!.textContent!); const complexityRating = Number.parseFloat(boardgame.querySelector('averageweight')?.textContent ?? '0'); diff --git a/src/api/apis/MALAPI.ts b/src/api/apis/MALAPI.ts index 5d33f10..8165dc9 100644 --- a/src/api/apis/MALAPI.ts +++ b/src/api/apis/MALAPI.ts @@ -116,7 +116,7 @@ export class MALAPI extends APIModel { duration: result.duration ?? 'unknown', onlineRating: result.score ?? 0, actors: [], - image: this.plugin.settings.embedPosters ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', + image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', released: true, premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', @@ -150,7 +150,7 @@ export class MALAPI extends APIModel { duration: result.duration ?? 'unknown', onlineRating: result.score ?? 0, actors: [], - image: this.plugin.settings.embedPosters ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', + image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', released: true, premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', @@ -182,7 +182,7 @@ export class MALAPI extends APIModel { duration: result.duration ?? 'unknown', onlineRating: result.score ?? 0, streamingServices: result.streaming?.map((x: any) => x.name) ?? [], - image: this.plugin.settings.embedPosters ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', + image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', released: true, airedFrom: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown', diff --git a/src/api/apis/MALAPIManga.ts b/src/api/apis/MALAPIManga.ts index 75731ee..e91cda5 100644 --- a/src/api/apis/MALAPIManga.ts +++ b/src/api/apis/MALAPIManga.ts @@ -61,7 +61,7 @@ export class MALAPIManga extends APIModel { chapters: result.chapters, volumes: result.volumes, onlineRating: result.score ?? 0, - image: this.plugin.settings.embedPosters ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', + image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', released: true, publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown', @@ -111,7 +111,7 @@ export class MALAPIManga extends APIModel { chapters: result.chapters, volumes: result.volumes, onlineRating: result.score ?? 0, - image: this.plugin.settings.embedPosters ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', + image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '', released: true, publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown', diff --git a/src/api/apis/MobyGamesAPI.ts b/src/api/apis/MobyGamesAPI.ts index 7f28f15..3d5e4a4 100644 --- a/src/api/apis/MobyGamesAPI.ts +++ b/src/api/apis/MobyGamesAPI.ts @@ -86,7 +86,7 @@ export class MobyGamesAPI extends APIModel { publishers: [], genres: result.genres?.map((x: any) => x.genre_name) ?? [], onlineRating: result.moby_score, - image: this.plugin.settings.embedPosters ? `![](${result.sample_cover.image ?? ''})` ?? '' : result.sample_cover.image ?? '', + image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.sample_cover.image ?? ''})` ?? '' : result.sample_cover.image ?? '', released: true, releaseDate: result.platforms[0].first_release_date ?? 'unknown', diff --git a/src/api/apis/MusicBrainzAPI.ts b/src/api/apis/MusicBrainzAPI.ts index d14d5d5..53102e3 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: this.plugin.settings.embedPosters + image: this.plugin.settings.generateEmbedLinksForImages ? `![](${'https://coverartarchive.org/release-group/' + result.id + '/front'})` : 'https://coverartarchive.org/release-group/' + result.id + '/front', @@ -91,7 +91,7 @@ export class MusicBrainzAPI extends APIModel { dataSource: this.apiName, url: 'https://musicbrainz.org/release-group/' + result.id, id: result.id, - image: this.plugin.settings.embedPosters + image: this.plugin.settings.generateEmbedLinksForImages ? `![](${'https://coverartarchive.org/release-group/' + result.id + '/front'})` : 'https://coverartarchive.org/release-group/' + result.id + '/front', diff --git a/src/api/apis/OMDbAPI.ts b/src/api/apis/OMDbAPI.ts index 95df0c0..c4fd55a 100644 --- a/src/api/apis/OMDbAPI.ts +++ b/src/api/apis/OMDbAPI.ts @@ -142,7 +142,7 @@ export class OMDbAPI extends APIModel { duration: result.Runtime ?? 'unknown', onlineRating: Number.parseFloat(result.imdbRating ?? 0), actors: result.Actors?.split(', ') ?? [], - image: this.plugin.settings.embedPosters ? (result.Poster ? `![](${result.Poster})` : '') : result.Poster ? result.Poster : '', + image: this.plugin.settings.generateEmbedLinksForImages ? (result.Poster ? `![](${result.Poster})` : '') : result.Poster ? result.Poster : '', released: true, streamingServices: [], @@ -174,7 +174,7 @@ export class OMDbAPI extends APIModel { duration: result.Runtime ?? 'unknown', onlineRating: Number.parseFloat(result.imdbRating ?? 0), actors: result.Actors?.split(', ') ?? [], - image: this.plugin.settings.embedPosters ? (result.Poster ? `![](${result.Poster})` : '') : result.Poster ? result.Poster : '', + image: this.plugin.settings.generateEmbedLinksForImages ? (result.Poster ? `![](${result.Poster})` : '') : result.Poster ? result.Poster : '', released: true, streamingServices: [], @@ -204,7 +204,7 @@ export class OMDbAPI extends APIModel { publishers: [], genres: result.Genre?.split(', ') ?? [], onlineRating: Number.parseFloat(result.imdbRating ?? 0), - image: this.plugin.settings.embedPosters ? (result.Poster ? `![](${result.Poster})` : '') : result.Poster ? result.Poster : '', + image: this.plugin.settings.generateEmbedLinksForImages ? (result.Poster ? `![](${result.Poster})` : '') : result.Poster ? result.Poster : '', released: true, releaseDate: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown', diff --git a/src/api/apis/OpenLibraryAPI.ts b/src/api/apis/OpenLibraryAPI.ts index 55c8f63..d41f7c5 100644 --- a/src/api/apis/OpenLibraryAPI.ts +++ b/src/api/apis/OpenLibraryAPI.ts @@ -78,7 +78,7 @@ export class OpenLibraryAPI extends APIModel { plot: result.description ?? 'unknown', pages: result.number_of_pages_median ?? 'unknown', onlineRating: Number.parseFloat(Number(result.ratings_average ?? 0).toFixed(2)), - image: this.plugin.settings.embedPosters + image: this.plugin.settings.generateEmbedLinksForImages ? `![](${`https://covers.openlibrary.org/b/OLID/` + result.cover_edition_key + `-L.jpg`}` : `https://covers.openlibrary.org/b/OLID/` + result.cover_edition_key + `-L.jpg`, diff --git a/src/api/apis/SteamAPI.ts b/src/api/apis/SteamAPI.ts index 69c88e7..bc76393 100644 --- a/src/api/apis/SteamAPI.ts +++ b/src/api/apis/SteamAPI.ts @@ -115,7 +115,7 @@ export class SteamAPI extends APIModel { publishers: result['publishers'], genres: result.genres?.map((x: any) => x.description) ?? [], onlineRating: Number.parseFloat(result.metacritic?.score ?? 0), - image: this.plugin.settings.embedPosters ? `![](${result.header_image ?? ''})` : result.header_image ?? '', + image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.header_image ?? ''})` : result.header_image ?? '', released: !result.release_date?.comming_soon, releaseDate: this.plugin.dateFormatter.format(result.release_date?.date, this.apiDateFormat) ?? 'unknown', diff --git a/src/settings/Settings.ts b/src/settings/Settings.ts index 9c696f5..5e72ea1 100644 --- a/src/settings/Settings.ts +++ b/src/settings/Settings.ts @@ -18,7 +18,7 @@ export interface MediaDbPluginSettings { openNoteInNewTab: boolean; useDefaultFrontMatter: boolean; enableTemplaterIntegration: boolean; - embedPosters: boolean; + generateEmbedLinksForImages: boolean; apiToggle: { OMDbAPI: { movie: boolean; @@ -84,7 +84,7 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = { openNoteInNewTab: true, useDefaultFrontMatter: true, enableTemplaterIntegration: false, - embedPosters: false, + generateEmbedLinksForImages: false, apiToggle: { OMDbAPI: { movie: true, @@ -282,11 +282,11 @@ export class MediaDbSettingTab extends PluginSettingTab { }); }); new Setting(containerEl) - .setName('Embed posters in YAML') - .setDesc('Embed the poster urls as images in the yaml to integrate with dataview.') + .setName('Embed image links in YAML') + .setDesc('Save image links as markdown embeds in the frontmatter, for easier handling with e.g. Dataview.') .addToggle(cb => { - cb.setValue(this.plugin.settings.embedPosters).onChange(data => { - this.plugin.settings.embedPosters = data; + cb.setValue(this.plugin.settings.generateEmbedLinksForImages).onChange(data => { + this.plugin.settings.generateEmbedLinksForImages = data; void this.plugin.saveSettings(); }); });