Skip to content

Commit

Permalink
Merge pull request #33 from Raph9213/fix-discord-cover
Browse files Browse the repository at this point in the history
  • Loading branch information
malmeloo authored Sep 16, 2023
2 parents d43d516 + 9578a46 commit 4640090
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions riitag/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _parse_db(self, db: str):


class RiitagTitle:
COVER_URL = 'https://art.gametdb.com/{console}/{img_type}/US/{game_id}.{file_type}'
COVER_URL = 'https://art.gametdb.com/{console}/{img_type}/{region}/{game_id}.{file_type}'
NOTFOUND_URL = 'https://discord.dolphin-emu.org/cover-art/unknown.png'
IMG_TYPES = (
'coverHQ',
Expand All @@ -110,15 +110,19 @@ class RiitagTitle:
'disc',
'discM'
)
CONSOLE_NAMES = {
'wii': 'Wii',
'wiiu': 'Wii U',
}
REGION = (
'EN',
'US'
'JA'
)
FILE_TYPES = (
'png',
'jpg'
)
CONSOLE_NAMES = {
'wii': 'Wii',
'wiiu': 'Wii U'
}

def __init__(self, resolver: RiitagTitleResolver, console: str, game_id: str):
self._resolver = resolver

Expand All @@ -136,20 +140,22 @@ def console_name(self):

def get_cover_url(self):
for img_type in self.IMG_TYPES:
for file_type in self.FILE_TYPES:
try:
url = self.COVER_URL.format(
console=self.console.lower(),
img_type=img_type,
game_id=self.game_id,
file_type=file_type
)
r = requests.head(url)
except requests.RequestException:
continue

if r.status_code == 200:
return url
for region in self.REGION:
for file_type in self.FILE_TYPES:
try:
url = self.COVER_URL.format(
console=self.console.lower(),
img_type=img_type,
game_id=self.game_id,
file_type=file_type,
region=region
)
r = requests.head(url)
except requests.RequestException:
continue

if r.status_code == 200:
return url

return self.NOTFOUND_URL

Expand Down

0 comments on commit 4640090

Please sign in to comment.