benbarden / switchscores

The code behind switchscores.com.
9 stars 1 forks source link

Replace packshots with square images #154

Closed cosmo0 closed 1 year ago

cosmo0 commented 1 year ago

Some games have a "pack shot" instead of a square image ; example with Undernauts (see https://github.com/benbarden/switchscores/issues/140#issuecomment-1065513411)

All these games have a square image (visible in the Nintendo search results). It's possible to parse the pack shot URL and rebuild the square image.

Packshot:

//fs-prod-cdn.nintendo-europe.com/media/images/05_packshots/games_13/nintendo_switch8/PSNSwitch_UndernautsLabyrinthOfYomi_PEGI.jpg

Square:

//fs-prod-cdn.nintendo-europe.com/media/images/11_square_images/games_18/nintendo_switch5/SQNSwitch_UndernautsLabyrinthOfYomi_image500w.jpg

A regex like that: .*\/PS_([\w_]+)_PEGI\.jpg catches NSwitch_UndernautsLabyrinthOfYomi in its first group, and then you can rebuild the square URL : "//fs-prod-cdn.nintendo-europe.com/media/images/11_square_images/games_18/nintendo_switch_5/SQ_" + $capture + "_image500w.jpg"

benbarden commented 1 year ago

I don't know if there is a logical way to move from packshot to square. There are three parts that cause problems:

05_packshots / 11_square_images games_13 / games_18 nintendo_switch_8 / nintendo_switch_5

The numbers change, and the number used for the packshot doesn't appear to be the same as what's used for square.

benbarden commented 1 year ago

Probably the best way is to do it manually, sadly :(

cosmo0 commented 1 year ago

The numbers change but they're always the same for all type of images. Packshots are always 05_packshots/games_13/nintendo_switch_8/PS_, square images are always 11_square_images/games_18/nintendo_switch_5/SQ_.

cosmo0 commented 1 year ago

I've made a small JS program to demonstrate that you can always extract the square image from the large image: https://codepen.io/cosmo0/pen/mdjgKvY?editors=0011

Unfortunately it doesn't work from the URL because the game name casing changes :(

benbarden commented 1 year ago

Ah thanks! I'll have a look at this when I get time.

benbarden commented 1 year ago

Finally found some time to look at this. Your code is good (thanks!). One small thing, sometimes the header image is 1280 rather than 1600, so I've added a check for this in my version of the code.

I've got some further testing to do but I think I'll be able to get this done today or tomorrow.

benbarden commented 1 year ago

Code is live and I've downloaded approx 100 missing square images.

Couple of issues I can't fix:

Hopping Girl Kohane EX https://www.switchscores.com/staff/games/detail/9440

Header URL: https://fs-prod-cdn.nintendo-europe.com/media/images/10_share_images/games_15/nintendo_switch_download_software_1/2x1_NSwitchDS_HoppingGirlKohaneEx_image1600w.jpg

Square URL should be: https://fs-prod-cdn.nintendo-europe.com/media/images/11_square_images/games_18/nintendo_switch_download_software/1x1_NSwitchDS_HoppingGirlKohaneEx_image500w.jpg

My code gives that result, but the image doesn't exist.

Same issue for Tears of the Kingdom. It may be that the images are missing.

cosmo0 commented 1 year ago

From the search results, the image is:

https://fs-prod-cdn.nintendo-europe.com/media/images/11_square_images/games_18/nintendo_switch_download_software/1x1_NswitchDS_HoppingGirlKohaneEx_image500w.jpg

The first "S" in "1x1NswitchDS" in in lower case. It makes me believe their system is manual, and they made a mistake while renaming it? That would be wild.

Based on the search, Tears of the Kingdom's square image is:

https://fs-prod-cdn.nintendo-europe.com/media/images/11_square_images/games_18/nintendo_switch_5/1x1_NSwitch_TloZTearsOfTheKingdom_BASE_image500w.jpg

It has "BASE" in its title, while the large image has "Gamepage". It would demonstrate further that the images are manually renamed. For such a huge site, it blows my mind that basic operations like that are not automated.

benbarden commented 1 year ago

OK, thanks. I'll need to do manual fixes for these, but the original issue is solved so I'll close this.