Updated image url for omdb and steam
changed steam to a vertical poster to fit the other posters and upgraded the quality of omdb from SX300 to SX600
This commit is contained in:
parent
657668dc7d
commit
a615e7f768
3 changed files with 31 additions and 4 deletions
|
|
@ -151,7 +151,7 @@ export class OMDbAPI extends APIModel {
|
||||||
duration: result.Runtime ?? 'unknown',
|
duration: result.Runtime ?? 'unknown',
|
||||||
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
|
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
|
||||||
actors: result.Actors?.split(', ') ?? [],
|
actors: result.Actors?.split(', ') ?? [],
|
||||||
image: result.Poster ?? '',
|
image: result.Poster ? result.Poster.replace('_SX300', '_SX600') : '',
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
streamingServices: [],
|
streamingServices: [],
|
||||||
|
|
@ -181,7 +181,7 @@ export class OMDbAPI extends APIModel {
|
||||||
duration: result.Runtime ?? 'unknown',
|
duration: result.Runtime ?? 'unknown',
|
||||||
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
|
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
|
||||||
actors: result.Actors?.split(', ') ?? [],
|
actors: result.Actors?.split(', ') ?? [],
|
||||||
image: result.Poster ?? '',
|
image: result.Poster ? result.Poster.replace('_SX300', '_SX600') : '',
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
streamingServices: [],
|
streamingServices: [],
|
||||||
|
|
@ -209,7 +209,7 @@ export class OMDbAPI extends APIModel {
|
||||||
publishers: [],
|
publishers: [],
|
||||||
genres: result.Genre?.split(', ') ?? [],
|
genres: result.Genre?.split(', ') ?? [],
|
||||||
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
|
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
|
||||||
image: result.Poster ?? '',
|
image: result.Poster ? result.Poster.replace('_SX300', '_SX600') : '',
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
releaseDate: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown',
|
releaseDate: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown',
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { GameModel } from '../../models/GameModel';
|
||||||
import type { MediaTypeModel } from '../../models/MediaTypeModel';
|
import type { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||||
import { MediaType } from '../../utils/MediaType';
|
import { MediaType } from '../../utils/MediaType';
|
||||||
import { APIModel } from '../APIModel';
|
import { APIModel } from '../APIModel';
|
||||||
|
import { imageUrlExists } from '../../utils/Utils';
|
||||||
|
|
||||||
export class SteamAPI extends APIModel {
|
export class SteamAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
|
|
@ -85,6 +86,16 @@ export class SteamAPI extends APIModel {
|
||||||
|
|
||||||
// console.debug(result);
|
// console.debug(result);
|
||||||
|
|
||||||
|
// Check if a poster version of the image exists, else use the header image
|
||||||
|
const imageUrl = `https://steamcdn-a.akamaihd.net/steam/apps/${result.steam_appid}/library_600x900_2x.jpg`;
|
||||||
|
const exists = await imageUrlExists(imageUrl);
|
||||||
|
let finalimageurl;
|
||||||
|
if (exists) {
|
||||||
|
finalimageurl = imageUrl;
|
||||||
|
} else {
|
||||||
|
finalimageurl = result.header_image ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
return new GameModel({
|
return new GameModel({
|
||||||
type: MediaType.Game,
|
type: MediaType.Game,
|
||||||
title: result.name,
|
title: result.name,
|
||||||
|
|
@ -98,7 +109,7 @@ export class SteamAPI extends APIModel {
|
||||||
publishers: result.publishers,
|
publishers: result.publishers,
|
||||||
genres: result.genres?.map((x: any) => x.description) ?? [],
|
genres: result.genres?.map((x: any) => x.description) ?? [],
|
||||||
onlineRating: Number.parseFloat(result.metacritic?.score ?? 0),
|
onlineRating: Number.parseFloat(result.metacritic?.score ?? 0),
|
||||||
image: result.header_image ?? '',
|
image: finalimageurl ?? '',
|
||||||
|
|
||||||
released: !result.release_date?.coming_soon,
|
released: !result.release_date?.coming_soon,
|
||||||
releaseDate: this.plugin.dateFormatter.format(result.release_date?.date, this.apiDateFormat) ?? 'unknown',
|
releaseDate: this.plugin.dateFormatter.format(result.release_date?.date, this.apiDateFormat) ?? 'unknown',
|
||||||
|
|
|
||||||
|
|
@ -234,3 +234,19 @@ export async function useTemplaterPluginInFile(app: App, file: TFile): Promise<v
|
||||||
export type ModelToData<T> = {
|
export type ModelToData<T> = {
|
||||||
[K in keyof T as T[K] extends Function ? never : K]?: T[K];
|
[K in keyof T as T[K] extends Function ? never : K]?: T[K];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Checks if a given URL points to an existing image (status 200), or returns false for 404/other errors.
|
||||||
|
|
||||||
|
export async function imageUrlExists(url: string): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
// @ts-ignore
|
||||||
|
const response = await requestUrl({
|
||||||
|
url,
|
||||||
|
method: 'HEAD',
|
||||||
|
throw: false,
|
||||||
|
});
|
||||||
|
return response.status === 200;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue