Skip to content

Commit a615e7f

Browse files
committed
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
1 parent 657668d commit a615e7f

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/api/apis/OMDbAPI.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class OMDbAPI extends APIModel {
151151
duration: result.Runtime ?? 'unknown',
152152
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
153153
actors: result.Actors?.split(', ') ?? [],
154-
image: result.Poster ?? '',
154+
image: result.Poster ? result.Poster.replace('_SX300', '_SX600') : '',
155155

156156
released: true,
157157
streamingServices: [],
@@ -181,7 +181,7 @@ export class OMDbAPI extends APIModel {
181181
duration: result.Runtime ?? 'unknown',
182182
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
183183
actors: result.Actors?.split(', ') ?? [],
184-
image: result.Poster ?? '',
184+
image: result.Poster ? result.Poster.replace('_SX300', '_SX600') : '',
185185

186186
released: true,
187187
streamingServices: [],
@@ -209,7 +209,7 @@ export class OMDbAPI extends APIModel {
209209
publishers: [],
210210
genres: result.Genre?.split(', ') ?? [],
211211
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
212-
image: result.Poster ?? '',
212+
image: result.Poster ? result.Poster.replace('_SX300', '_SX600') : '',
213213

214214
released: true,
215215
releaseDate: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown',

src/api/apis/SteamAPI.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { GameModel } from '../../models/GameModel';
44
import type { MediaTypeModel } from '../../models/MediaTypeModel';
55
import { MediaType } from '../../utils/MediaType';
66
import { APIModel } from '../APIModel';
7+
import { imageUrlExists } from '../../utils/Utils';
78

89
export class SteamAPI extends APIModel {
910
plugin: MediaDbPlugin;
@@ -85,6 +86,16 @@ export class SteamAPI extends APIModel {
8586

8687
// console.debug(result);
8788

89+
// Check if a poster version of the image exists, else use the header image
90+
const imageUrl = `https://steamcdn-a.akamaihd.net/steam/apps/${result.steam_appid}/library_600x900_2x.jpg`;
91+
const exists = await imageUrlExists(imageUrl);
92+
let finalimageurl;
93+
if (exists) {
94+
finalimageurl = imageUrl;
95+
} else {
96+
finalimageurl = result.header_image ?? '';
97+
}
98+
8899
return new GameModel({
89100
type: MediaType.Game,
90101
title: result.name,
@@ -98,7 +109,7 @@ export class SteamAPI extends APIModel {
98109
publishers: result.publishers,
99110
genres: result.genres?.map((x: any) => x.description) ?? [],
100111
onlineRating: Number.parseFloat(result.metacritic?.score ?? 0),
101-
image: result.header_image ?? '',
112+
image: finalimageurl ?? '',
102113

103114
released: !result.release_date?.coming_soon,
104115
releaseDate: this.plugin.dateFormatter.format(result.release_date?.date, this.apiDateFormat) ?? 'unknown',

src/utils/Utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,19 @@ export async function useTemplaterPluginInFile(app: App, file: TFile): Promise<v
234234
export type ModelToData<T> = {
235235
[K in keyof T as T[K] extends Function ? never : K]?: T[K];
236236
};
237+
238+
// Checks if a given URL points to an existing image (status 200), or returns false for 404/other errors.
239+
240+
export async function imageUrlExists(url: string): Promise<boolean> {
241+
try {
242+
// @ts-ignore
243+
const response = await requestUrl({
244+
url,
245+
method: 'HEAD',
246+
throw: false,
247+
});
248+
return response.status === 200;
249+
} catch {
250+
return false;
251+
}
252+
}

0 commit comments

Comments
 (0)