Skip to content

Commit 56f6bee

Browse files
committed
Refactoring of the art dictionaries
1 parent 106e462 commit 56f6bee

2 files changed

Lines changed: 33 additions & 25 deletions

File tree

resources/arts.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,28 @@
2020
allowable_methods=('HEAD',), allowable_codes=(200, 404),
2121
old_data_on_error=True,
2222
fast_save=True)
23+
# Existing Steam art types urls, to format to format with appid / img_icon_path
24+
STEAM_ARTS_TYPES = { # img_icon_path is provided by steam API to get the icon. https://developer.valvesoftware.com/wiki/Steam_Web_API#GetOwnedGames_.28v0001.29
25+
'poster': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/library_600x900.jpg', # Can return 404
26+
'hero': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/library_hero.jpg', # Can return 404
27+
'header': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/header.jpg',
28+
'generated_bg': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/page_bg_generated_v6b.jpg', # Auto generated background with a shade of blue.
29+
'icon': 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/{appid}/{img_icon_path}.jpg',
30+
'logo': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/logo.png' # Can return 404
31+
}
2332

24-
# Dictionary containing for each art type, a base_url for the art (to format with appid / img_icon_path afterwards), and a fallback art type.
25-
ARTS_DATA = { # img_icon_path is a path provided by steam to get the icon. https://developer.valvesoftware.com/wiki/Steam_Web_API#GetOwnedGames_.28v0001.29
26-
'poster': {'base_url': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/library_600x900.jpg', 'fallback_media': 'landscape'}, # Can return 404
27-
'banner': {'base_url': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/library_hero.jpg', 'fallback_media': 'landscape'}, # Can return 404
28-
'landscape': {'base_url': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/header.jpg', 'fallback_media': None},
29-
'thumb': {'base_url': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/header.jpg', 'fallback_media': None},
30-
'fanart': {'base_url': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/library_hero.jpg', 'fallback_media': 'fanart2'}, # Can return 404
31-
'fanart2': {'base_url': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/header.jpg', 'fallback_media': 'fanart3'},
32-
'fanart3': {'base_url': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/page_bg_generated_v6b.jpg', 'fallback_media': None},
33-
'icon': {'base_url': 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/{appid}/{img_icon_path}.jpg', 'fallback_media': None},
34-
'clearlogo': {'base_url': 'http://cdn.akamai.steamstatic.com/steam/apps/{appid}/logo.png', 'fallback_media': None} # Can return 404
33+
# Dictionary containing for each art type, a url for the art (to format with appid / img_icon_path afterwards), and a fallback art type.
34+
# Having no fallback also means that the art url won't be tested
35+
ARTS_ASSIGNMENTS = {
36+
'poster': {'url': STEAM_ARTS_TYPES['poster'], 'fallback': 'landscape'},
37+
'banner': {'url': STEAM_ARTS_TYPES['hero'], 'fallback': 'landscape'},
38+
'fanart': {'url': STEAM_ARTS_TYPES['hero'], 'fallback': 'fanart1'},
39+
'fanart1': {'url': STEAM_ARTS_TYPES['header'], 'fallback': None},
40+
'fanart2': {'url': STEAM_ARTS_TYPES['generated_bg'], 'fallback': None}, # Multiple fanart https://kodi.wiki/view/Artwork_types#fanart.23
41+
'landscape': {'url': STEAM_ARTS_TYPES['header'], 'fallback': None},
42+
'thumb': {'url': STEAM_ARTS_TYPES['header'], 'fallback': None},
43+
'icon': {'url': STEAM_ARTS_TYPES['icon'], 'fallback': None},
44+
'clearlogo': {'url': STEAM_ARTS_TYPES['logo'], 'fallback': None}
3545
}
3646

3747

@@ -65,17 +75,17 @@ def resolve_art_url(art_type, appid, img_icon_path='', art_fallback_enabled=artF
6575
:return: resolved art URL. Can be the URL of another available art if .
6676
"""
6777
valid_art_url = None
68-
requested_art_data = ARTS_DATA.get(art_type, None)
78+
requested_art = ARTS_ASSIGNMENTS.get(art_type, None)
6979

70-
while valid_art_url is None and requested_art_data is not None: # If the current media type is defined and we did not find a valid url yet
71-
art_url = requested_art_data.get('base_url').format(appid=appid, img_icon_path=img_icon_path) # We replace "{appid}" and "{img_icon_path}" in the url
72-
fallback_art_type = requested_art_data.get("fallback_media", None)
80+
while valid_art_url is None and requested_art is not None: # If the current media type is defined and we did not find a valid url yet
81+
art_url = requested_art.get('url').format(appid=appid, img_icon_path=img_icon_path) # We replace "{appid}" and "{img_icon_path}" in the url
82+
fallback_art_type = requested_art.get("fallback", None)
7383
if (not art_fallback_enabled) or (fallback_art_type is None) or is_art_url_available(art_url):
7484
# If art fallback is disabled, or if there is no fallback defined, we directly assume the art url as valid.
7585
# Otherwise, if art fallback is enabled and there is a fallback defined, we check if is_art_url_available before proceeding
7686
valid_art_url = art_url
7787
else: # If art fallback is enabled and art is not available, we set the current art data to the defined fallback, before retrying.
78-
requested_art_data = ARTS_DATA.get(fallback_art_type, None) # Art data will be None if the fallback_art_type does not exist in the art_urls dict
88+
requested_art = ARTS_ASSIGNMENTS.get(fallback_art_type, None) # Art data will be None if the fallback_art_type does not exist in the art_urls dict
7989

8090
if valid_art_url is None: # If the previous loop could not find a valid media url among the defined art types
8191
show_error(None, "Issue obtaining a media", display_notification=False)

resources/main.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,14 @@ def create_arts_dictionary(app_entry):
161161
"""
162162

163163
appid = str(app_entry['appid'])
164+
img_icon_url = app_entry['img_icon_url']
165+
art_dictionary = {}
164166

165-
art_dictionary = {
166-
'poster': arts.resolve_art_url('poster', appid),
167-
'landscape': arts.resolve_art_url('landscape', appid),
168-
'banner': arts.resolve_art_url('banner', appid),
169-
'clearlogo': arts.resolve_art_url('clearlogo', appid),
170-
'thumb': arts.resolve_art_url('thumb', appid),
171-
'fanart': arts.resolve_art_url('fanart', appid),
172-
'icon': arts.resolve_art_url('icon', appid, app_entry['img_icon_url'])
173-
}
167+
# Multiple fanart https://kodi.wiki/view/Artwork_types#fanart.23
168+
SUPPORTED_ART_TYPES = ['poster', 'landscape', 'banner', 'clearlogo', 'thumb', 'fanart', 'fanart1', 'fanart2', 'icon']
169+
170+
for art_type in SUPPORTED_ART_TYPES:
171+
art_dictionary[art_type] = arts.resolve_art_url(art_type, appid, img_icon_url)
174172
return art_dictionary
175173

176174

0 commit comments

Comments
 (0)