ckosmic / ScoreSaberWidget

ScoreSaber Scriptable widget for iOS that shows a selected player's stats
8 stars 5 forks source link

Error: Cannot parse response to an image. #1

Closed BrendonGames closed 2 years ago

BrendonGames commented 2 years ago

The title is the error i’m receiving and I have no idea why it happens.

here’s a photo of the error: 773F9EB2-E247-4FDC-9926-7C5A14A41283

I’ve been using this widget for a while and it suddenly stopped working. I waited a few hours and reinstalled, but it still doesn’t work.

ckosmic commented 2 years ago

Looks like the ScoreSaber API or frontend changed :/ I'll look into it.

qe201020335 commented 2 years ago

It is because ScoreSaber no longer serves the country flags pictures. It is using twemoji's image. https://scoresaber.com/imports/images/flags/ca.png will return 404 instead of the flag for Canada.

Here is how ScoreSaber fetches the twimoji https://github.com/ScoreSaber/ScoreSaber-Frontend/blob/main/src/lib/components/image/country-image.svelte

BrendonGames commented 2 years ago

Although I’m not good enough to get the image, I have managed to rewrite the code a little to add the country as text: E4838FE1-D3F9-4446-80BF-92B25E7E4B9F

BrendonGames commented 2 years ago

Here's the scriptable file for plain text country: ScoreSaber.zip

qe201020335 commented 2 years ago

The flag image returned by twimoji is svg and I did some google found out Scriptable doesn't really have a good support for svg.

Here is the code I copied from the ScoreSaber frontend.

const toTwemojiFlag = (input) =>
    `https://twemoji.maxcdn.com/v/13.1.0/svg/${input
        .toLowerCase()
        .match(/[a-z]/g)
        .map((i) => (i.codePointAt(0) + 127365).toString(16))
        .join('-')}.svg`;

const toEmojiFlag = (countryCode) => countryCode.toLowerCase().replace(/[a-z]/g, (i) => String.fromCodePoint((i.codePointAt(0) ?? 0) - 97 + 0x1f1e6));

toTwemojiFlag will return a url to the country flag svg which we can't use at the moment. toEmojiFlag will directly return the Unicode emoji for the input country code. For example "CA" => 🇨🇦 Use the unicode conversion is working

image

Will make a pr

ckosmic commented 2 years ago

Fixed in https://github.com/ckosmic/ScoreSaberWidget/pull/2