Skip to content

Commit

Permalink
Steam Official artwork provider is working
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartondock committed May 30, 2024
1 parent 09c7119 commit 2e24193
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 66 deletions.
22 changes: 13 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"rxjs": "^7.8.1",
"steam-categories": "^1.1.4",
"steam-shortcut-editor": "^3.1.3",
"steamgriddb": "2.1.1",
"steamgriddb": "^2.2.0",
"to-css": "^1.2.1",
"windows-shortcuts-ps": "https://github.com/cbartondock/windows-shortcuts-ps.git",
"winreg": "^1.2.5",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/image-providers/available-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const imageProviderNames: Record<ImageProviderType, ImageProviderName> =
imported: 'Imported Artwork',
manual: 'Manually Added',
sgdb: 'SteamGridDB',
steamCDN: 'Steam CDN'
steamCDN: 'Steam Official'
}

export const allProviders: Record<ProviderCategoryType,
Expand Down
57 changes: 35 additions & 22 deletions src/lib/image-providers/steamcdn.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,53 @@ export class SteamCDNProvider extends GenericProvider {

retrieveUrls() {
let self = this;
this.xrw.promise = new Promise<void>((resolve) => {
let idPromise: Promise<number> = null;
if(sgdbIdRegex.test(self.proxy.title)) {
idPromise = Promise.resolve(parseInt(self.proxy.title.match(sgdbIdRegex)[1]))
} else {
idPromise = self.client.searchGame(self.proxy.title).then((res: any) => (res[0]||{}).id);
}
idPromise.then((chosenId: number|undefined)=> {
this.xrw.promise = new Promise<void>(async (resolve) => {
try {
let chosenId: number;
if(sgdbIdRegex.test(self.proxy.title)) {
chosenId = parseInt(self.proxy.title.match(sgdbIdRegex)[1]);
} else {
chosenId = ((await self.client.searchGame(self.proxy.title))[0]||{}).id;
}
if(!chosenId) {
if(self.proxy.imageType === 'long') { // Don't throw this error 5 times.
self.xrw.logError(`SGDB found no matching games for title "${self.proxy.title}"`)
}
self.proxy.completed();
resolve();
} else {
// convert sgdbId to steamId
// return CDN urls
for(let artworkType of artworkTypes) {
if(self.proxy.imageType === artworkType && self.proxy.imageType !== 'icon') {
self.proxy.image({
imageProvider: imageProviderNames.steamCDN,
imageUrl: `https://cdn.cloudflare.steamstatic.com/steam/apps/400/${steamArtworkDict[artworkType]}`,
loadStatus: 'notStarted'
})
// convert sgdbId to steamId
const platformData = ((await self.client.getGameById(chosenId, {platformdata: ['steam']}))||{}).external_platform_data;
if(platformData && platformData.steam && platformData.steam.length) {
const {id, metadata} = platformData.steam[0];
// return CDN urls
for(let artworkType of artworkTypes) {
if(self.proxy.imageType === artworkType && id) {
if(self.proxy.imageType === 'icon' && metadata.clienticon) {
self.proxy.image({
imageProvider: imageProviderNames.steamCDN,
imageUrl: `https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/${id}/${metadata.clienticon}.ico`,
loadStatus: 'notStarted'
})
} else {
self.proxy.image({
imageProvider: imageProviderNames.steamCDN,
imageUrl: `https://cdn.cloudflare.steamstatic.com/steam/apps/${id}/${steamArtworkDict[artworkType]}`,
loadStatus: 'notStarted'
})
}
}
}
}
self.proxy.completed();
resolve();
}
self.proxy.completed();
resolve();
}
}).catch((error: string) => {
}
catch(error) {
self.xrw.logError(error);
self.proxy.completed();
resolve();
});
};
})
}

Expand Down
61 changes: 29 additions & 32 deletions src/lib/image-providers/steamgriddb.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ export class SteamGridDbProvider extends GenericProvider {
retrieveUrls() {
let self = this;
let imageGameId: string;
this.xrw.promise = new Promise<void>((resolve) => {
let idPromise: Promise<number> = null;
if(sgdbIdRegex.test(self.proxy.title)) {
idPromise = Promise.resolve(parseInt(self.proxy.title.match(sgdbIdRegex)[1]))
} else {
idPromise = self.client.searchGame(self.proxy.title).then((res: any) => (res[0]||{}).id);
}
idPromise.then((chosenId: number|undefined)=>{
this.xrw.promise = new Promise<void>(async (resolve) => {
try {
let chosenId: number;
if(sgdbIdRegex.test(self.proxy.title)) {
chosenId = parseInt(self.proxy.title.match(sgdbIdRegex)[1]);
} else {
chosenId = ((await self.client.searchGame(self.proxy.title))[0]||{}).id;
}
if(!chosenId) {
if(self.proxy.imageType === 'long') { // Don't throw this error 5 times.
self.xrw.logError(`SGDB found no matching games for title "${self.proxy.title}"`)
Expand All @@ -70,55 +70,52 @@ export class SteamGridDbProvider extends GenericProvider {
humor: self.proxy.imageProviderAPIs.humor ? "any" : "false"
};
const choose = (x: any, fallback: string[]) => x && x.length ? x : fallback;
let res: any;
if(self.proxy.imageType === 'long') {
query = self.client.getGrids(Object.assign(params, {
res = await self.client.getGrids(Object.assign(params, {
dimensions: choose(self.proxy.imageProviderAPIs.sizes, ["460x215","920x430"]),
styles: self.proxy.imageProviderAPIs.styles
}))
} else if (self.proxy.imageType === 'tall') {
query = self.client.getGrids(Object.assign(params, {
res = await self.client.getGrids(Object.assign(params, {
dimensions: ["600x900"],
styles: self.proxy.imageProviderAPIs.styles
}));
} else if (self.proxy.imageType === 'hero') {
query = self.client.getHeroes(Object.assign(params, {
res = await self.client.getHeroes(Object.assign(params, {
dimensions: choose(self.proxy.imageProviderAPIs.sizesHero, null),
styles: self.proxy.imageProviderAPIs.stylesHero
}));
} else if (self.proxy.imageType === 'logo') {
query = self.client.getLogos(Object.assign(params, {
res = await self.client.getLogos(Object.assign(params, {
styles: self.proxy.imageProviderAPIs.stylesLogo
}));
} else if (self.proxy.imageType === 'icon') {
query = self.client.getIcons(Object.assign(params, {
res = await self.client.getIcons(Object.assign(params, {
dimensions: choose(self.proxy.imageProviderAPIs.sizesIcon, null),
styles: self.proxy.imageProviderAPIs.stylesIcon
}));
}
return query
}
})
.then((res: any)=>{
if(res !== null && res.length>0) {
for (let i=0; i < res.length; i++) {
self.proxy.image({
imageProvider: imageProviderNames.sgdb,
imageUrl: res[i].url,
imageGameId: imageGameId,
imageArtworkId: String(res[i].id),
imageUploader: res[i].author.name,
loadStatus: 'notStarted'
});
if(res !== null && res.length > 0) {
for (let i=0; i < res.length; i++) {
self.proxy.image({
imageProvider: imageProviderNames.sgdb,
imageUrl: res[i].url,
imageGameId: imageGameId,
imageArtworkId: String(res[i].id),
imageUploader: res[i].author.name,
loadStatus: 'notStarted'
});
}
}
self.proxy.completed();
resolve();
}
self.proxy.completed();
resolve();
})
.catch((error: string) => {
} catch(error) {
self.xrw.logError(error);
self.proxy.completed();
resolve();
});
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/models/preview.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { artworkTypes, viewTypes } from "../lib/artwork-types";
import { SteamList } from "./helpers.model";

export type ImageDownloadStatus = 'notStarted' | 'downloading' | 'done' | 'failed';
export type ImageProviderName = 'Fallback Artwork' | 'Current Artwork' | 'Backup Artwork' | 'Local Artwork' | 'Manually Added' | 'Imported Artwork' | 'SteamGridDB' | 'Steam CDN'
export type ImageProviderName = 'Fallback Artwork' | 'Current Artwork' | 'Backup Artwork' | 'Local Artwork' | 'Manually Added' | 'Imported Artwork' | 'SteamGridDB' | 'Steam Official'

export type ArtworkType = typeof artworkTypes[number];
export type ViewType = typeof viewTypes[number];
Expand Down

0 comments on commit 2e24193

Please sign in to comment.