|
20 | 20 | allowable_methods=('HEAD',), allowable_codes=(200, 404), |
21 | 21 | old_data_on_error=True, |
22 | 22 | 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 | +} |
23 | 32 |
|
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} |
35 | 45 | } |
36 | 46 |
|
37 | 47 |
|
@@ -65,17 +75,17 @@ def resolve_art_url(art_type, appid, img_icon_path='', art_fallback_enabled=artF |
65 | 75 | :return: resolved art URL. Can be the URL of another available art if . |
66 | 76 | """ |
67 | 77 | valid_art_url = None |
68 | | - requested_art_data = ARTS_DATA.get(art_type, None) |
| 78 | + requested_art = ARTS_ASSIGNMENTS.get(art_type, None) |
69 | 79 |
|
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) |
73 | 83 | if (not art_fallback_enabled) or (fallback_art_type is None) or is_art_url_available(art_url): |
74 | 84 | # If art fallback is disabled, or if there is no fallback defined, we directly assume the art url as valid. |
75 | 85 | # Otherwise, if art fallback is enabled and there is a fallback defined, we check if is_art_url_available before proceeding |
76 | 86 | valid_art_url = art_url |
77 | 87 | 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 |
79 | 89 |
|
80 | 90 | if valid_art_url is None: # If the previous loop could not find a valid media url among the defined art types |
81 | 91 | show_error(None, "Issue obtaining a media", display_notification=False) |
|
0 commit comments