fix(battlenet): use the right artwork for each game (#2092)

* fix(battlenet): use the right artwork for each game

World of Warcraft: Forever took retail art and its logo from a loose name lookup, and only fetched its own art when the Store tab was opened. Shop pages also supplied trailer stills and seasonal promos.

Each game now has chosen Blizzard key art with the shop page as a fallback, installed games fetch their art without opening the store, and lookups by name must match exactly. Art found by the old lookup is fetched again once.

* fix(battlenet): keep cached art if the new art cannot be fetched

Classic's variants fetch through the shared title, and a failing chosen image falls back to the shop page.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-04 14:12:16 -05:00
1 parent 5cf69732ef
commit f1c1ca59fe
7 files changed
+146 -19

No files matched your search

@@ -243,6 +243,8 @@ object AddedGameArt {
val steam: (String, File, Set<Slot>) -> Boolean,
val sgdbGame: (String, Int?, String) -> Int?,
val sgdb: (String, Int, File, Set<Slot>) -> Boolean,
val sgdbExactGame: (String, Int?, String) -> Int? = { _, _, _ -> null },
val battleNetArt: (Context, BattleNet.Title) -> Boolean = { _, _ -> false },
)
private val network = Sources(
@@ -251,6 +253,8 @@ object AddedGameArt {
steam = ::download,
sgdbGame = SteamGridDb::gameId,
sgdb = SteamGridDb::download,
sgdbExactGame = SteamGridDb::exactGameId,
battleNetArt = { context, title -> BattleNet.fetchCovers(context, listOf(BattleNet.artTitle(title))) },
)
private val EXTRAS = setOf(Slot.LOGO, Slot.ICON)
@@ -288,6 +292,9 @@ object AddedGameArt {
var changed = false
for (game in games) {
if (forgetOtherAppsArt(context, game)) changed = true
if (forgetNameMatchedBattleNetArt(context, game)) changed = true
val battleNetTitle = game.storeId?.takeIf { game.source == Store.BATTLENET.id }?.let(BattleNet::title)
if (battleNetTitle != null && runCatching { sources.battleNetArt(context, battleNetTitle) }.getOrDefault(false)) changed = true
val cache = cacheDir(context, game)
val start = missing(context, game)
val again = refetch(cache) intersect start
@@ -318,7 +325,7 @@ object AddedGameArt {
if (need.isNotEmpty() && sgdbKey.isNotEmpty()) {
if (sgdbDown) asked = false else try {
val gridId = remembered(File(cache, "sgdb-id"), keyChangedAt) {
sources.sgdbGame(sgdbKey, match.appId, game.name)?.toString()
(if (battleNetTitle != null) sources.sgdbExactGame else sources.sgdbGame)(sgdbKey, match.appId, game.name)?.toString()
}?.toIntOrNull()
if (gridId != null && sources.sgdb(sgdbKey, gridId, cache, need)) changed = true
} catch (e: Exception) {
@@ -343,6 +350,21 @@ object AddedGameArt {
if (slots.isEmpty()) File(cache, REFETCH).delete() else File(cache, REFETCH).writeText(slots.joinToString(",") { it.key })
}
internal const val BATTLENET_ART_CHECKED = "battlenet-art-2"
internal fun forgetNameMatchedBattleNetArt(context: Context, game: AddedGames.Game): Boolean {
val title = game.storeId?.takeIf { game.source == Store.BATTLENET.id }?.let(BattleNet::title) ?: return false
val cache = cacheDir(context, game)
val checked = File(cache, BATTLENET_ART_CHECKED)
if (title.steam != null || checked.isFile) return false
val dropped = EXTRAS.filter { File(cache, SteamGridDb.cacheName(it)).delete() }
EXTRAS.forEach { File(cache, SteamGridDb.cacheName(it) + ".src").delete() }
listOf("sgdb-id", EXTRAS_TRIED).forEach { File(cache, it).delete() }
cache.mkdirs()
checked.writeText("")
return dropped.isNotEmpty()
}
internal fun forgetOtherAppsArt(context: Context, game: AddedGames.Game): Boolean {
val cache = cacheDir(context, game)
val recorded = SteamMatch.get(context, game.folder.path)?.takeIf { it.appId != null }
@@ -70,15 +70,22 @@ object SteamGridDb {
if (!tmp.renameTo(f)) { f.delete(); tmp.renameTo(f) }
}
fun gameId(key: String, steamAppId: Int?, name: String): Int? {
fun gameId(key: String, steamAppId: Int?, name: String): Int? = gameId(key, steamAppId, name, ::match)
fun exactGameId(key: String, steamAppId: Int?, name: String): Int? = gameId(key, steamAppId, name, ::exactMatch)
private fun gameId(key: String, steamAppId: Int?, name: String, pick: (String, List<Pair<Int, String>>) -> Int?): Int? {
if (steamAppId != null) {
json(key, "$API/games/steam/$steamAppId")?.optJSONObject("data")?.optInt("id")?.takeIf { it > 0 }?.let { return it }
}
val term = URLEncoder.encode(name, "UTF-8").replace("+", "%20")
val results = json(key, "$API/search/autocomplete/$term")?.optJSONArray("data") ?: return null
return match(name, (0 until results.length()).map { results.getJSONObject(it) }.map { it.optInt("id") to it.optString("name") })
return pick(name, (0 until results.length()).map { results.getJSONObject(it) }.map { it.optInt("id") to it.optString("name") })
}
internal fun exactMatch(name: String, results: List<Pair<Int, String>>): Int? =
results.firstOrNull { (id, got) -> id > 0 && AddedGameArt.nameMatch(name, got) == 3 }?.first
internal fun match(name: String, results: List<Pair<Int, String>>): Int? =
results.map { (id, got) -> id to AddedGameArt.nameMatch(name, got) }
.filter { it.second > 0 && it.first > 0 }
@@ -66,8 +66,10 @@ object BattleNet {
private const val COVER_RETRY_MS = 24 * 3600_000L
internal fun artTitle(title: Title) = TITLES.firstOrNull { it.code == title.code } ?: title
private fun coverDir(context: Context, title: Title) =
File(context.filesDir, "battlenet-art/${(TITLES.firstOrNull { it.code == title.code } ?: title).uid}")
File(context.filesDir, "battlenet-art/${artTitle(title).uid}")
fun cover(context: Context, title: Title): File? = art(context, title).cover
@@ -79,7 +81,7 @@ object BattleNet {
var got = false
for (title in titles) {
val dir = coverDir(context, title)
val tried = File(dir, ".tried")
val tried = File(dir, ".tried-2")
val wide = File(dir, BLIZZARD)
val done = File(dir, "p.jpg").isFile && (title.shop == null || wide.isFile)
if (done || System.currentTimeMillis() - tried.lastModified() < COVER_RETRY_MS) continue
@@ -87,11 +89,15 @@ object BattleNet {
if (title.steam != null && runCatching { art.download(title.steam.toString(), dir) }.getOrDefault(false)) got = true
if (title.shop != null && !wide.isFile) {
val cover = File(dir, BLIZZARD_COVER).takeUnless { File(dir, "p.jpg").isFile }
if (runCatching { com.droiddeck.launcher.stores.battlenet.BlizzardArt.fetch(title.shop, wide, cover) }
.onFailure { Log.w(TAG, "Blizzard art for ${title.uid}: ${it.javaClass.simpleName}") }.getOrDefault(false)) got = true
if (runCatching { com.droiddeck.launcher.stores.battlenet.BlizzardArt.fetch(title.code, title.shop, wide, cover) }
.onFailure { Log.w(TAG, "Blizzard art for ${title.uid}: ${it.javaClass.simpleName}") }.getOrDefault(false)) {
got = true
File(dir, OLD_BLIZZARD).delete()
File(dir, OLD_BLIZZARD_COVER).delete()
}
}
if (!File(dir, "p.jpg").isFile && !File(dir, BLIZZARD_COVER).isFile && key.isNotEmpty()) {
val id = runCatching { com.droiddeck.launcher.frontend.SteamGridDb.gameId(key, title.steam, title.name) }.getOrNull()
val id = runCatching { com.droiddeck.launcher.frontend.SteamGridDb.exactGameId(key, title.steam, title.name) }.getOrNull()
if (id != null && runCatching { com.droiddeck.launcher.frontend.SteamGridDb.download(key, id, dir) }.getOrDefault(false)) got = true
}
runCatching { tried.writeText("") ; tried.setLastModified(System.currentTimeMillis()) }
@@ -111,13 +117,15 @@ object BattleNet {
class Art(val cover: File?, val header: File?)
private const val BLIZZARD = "blizzard.jpg"
private const val BLIZZARD_COVER = "p-blizzard.jpg"
private const val BLIZZARD = "blizzard-2.jpg"
private const val BLIZZARD_COVER = "p-blizzard-2.jpg"
private const val OLD_BLIZZARD = "blizzard.jpg"
private const val OLD_BLIZZARD_COVER = "p-blizzard.jpg"
fun art(context: Context, title: Title): Art {
val dir = coverDir(context, title)
fun first(vararg names: String) = names.map { File(dir, it) }.firstOrNull { it.isFile }
return Art(first("p.jpg", BLIZZARD_COVER), first(BLIZZARD, "header.jpg"))
return Art(first("p.jpg", BLIZZARD_COVER, OLD_BLIZZARD_COVER), first(BLIZZARD, OLD_BLIZZARD, "header.jpg"))
}
fun prefix(context: Context) = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/steamapps/compatdata/$APP_ID")
@@ -17,6 +17,41 @@ internal object BlizzardArt {
private val OG = Regex("""<meta property="og:image" content="(https://[^"]+)"""")
private val THUMB = Regex("""\\?"imageUrl\\?":\\?"(//catalog\.blzstatic\.com/[^"\\]+)""")
private val HOSTS = listOf(".blzstatic.com", ".blz-contentstack.com", "blz-contentstack-images.akamaized.net")
private const val KEY_ART_ASSETS = "https://blz-contentstack-images.akamaized.net/v3/assets/bltf408a0557f4e4998/"
private const val KEY_ART_CATALOG = "https://catalog.blzstatic.com/"
internal val KEY_ART = mapOf(
"WoW" to "${KEY_ART_ASSETS}blt80af93933ab07df3/68b8bf2d804a9776216cd63e/Midnight_keyart.png",
"WoWC" to "${KEY_ART_ASSETS}blt6a80c8e7260f84f2/690d2219b415dd246153245b/BCC.png",
"WoWF" to "${KEY_ART_ASSETS}blt1d58537e928b17c5/6ae2c99668c747dd1b4f558b/WoW_Forever_AnimatedTrailerSupportAssets_BnetShop_1920x1080.png",
"D3" to "${KEY_ART_CATALOG}/f96/8d92f4d8bd316d3787f02d8a86935d6a-Store_Product_960x540_D3.jpg",
"D3CN" to "${KEY_ART_CATALOG}/f96/8d92f4d8bd316d3787f02d8a86935d6a-Store_Product_960x540_D3.jpg",
"S2" to "${KEY_ART_ASSETS}blt4b6d6857f147a6de/61254804841f180993fedb61/6885-32192.png",
"S1" to "${KEY_ART_ASSETS}blt03d69a4563a6ae63/6a34b50f799ece2cb2da248c/9458-28298.jpg",
"WTCG" to "${KEY_ART_ASSETS}blt5a3d84e1d0b2bbcf/662aea9f842cecfd4fd95327/HS_Key_Art_SG2.png",
"Hero" to "${KEY_ART_ASSETS}blt73de967d17ca81ca/67db7dea931b380b4c76239a/Hanamura_Loading_Screen7.png",
"W3" to "${KEY_ART_ASSETS}blt66c211421d2c5495/6a7e66d8dee8846a67cba6fa/WC_Rebirth_Announce_BnetShop_ComparsionCard_Reforged_1920x1080.png",
"VIPR" to "${KEY_ART_ASSETS}bltd11d425fcbbe3c46/63eecbbd1e040260dfbede83/BO4_(2).png",
"ODIN" to "${KEY_ART_CATALOG}/ffe/5e9926e8de75095fa953b8e71aea966c-_Kronos-Bnet_Game-Card_Feature_3A_Standard-960x540.jpg",
"LAZR" to "${KEY_ART_CATALOG}/7f/ec4770b465f107f24f9a46a66d163ab9-Lazarus-Bnet_Placeholder-Card_PDG-960x540-For_20200331.jpg",
"ZEUS" to "${KEY_ART_ASSETS}blt3e4e126b8153648b/63eeca6b998e686b2e53b748/CW-keyArt-thumb.jpg",
"FORE" to "${KEY_ART_ASSETS}bltff4d6ec7afd2e49a/63f695ff583a5b674fbcde69/CODVG_Reveal_Ultimate_Keyart_Textless-Bnet-Launcher_Content_UI_(Phoenix)-1920x1080_01a_FINAL.jpg",
"AUKS" to "${KEY_ART_ASSETS}bltd31831eda9199937/62abc0df5cbe472513c0ce59/Cortez_Base_Game-Bnet_Game-Card_Feature-960x540.jpg",
"PNTA" to "${KEY_ART_ASSETS}bltd6fa384b60ff3fbd/64cc2fe367e57a3aa2cec653/Jupiter_Coming_Soon-Bnet_Game-Content_UI_(Phoenix)-EN-1920x1080_textless.jpg",
"WLBY" to "${KEY_ART_ASSETS}blt861e34883e31a113/63eec7f166192b60e0205205/CB4_Launch_Keyart_CTA_02-Bnet-Launcher_Launcher_2.0-1920x1080_textless.jpg",
"RTRO" to "${KEY_ART_ASSETS}bltc2737ca8175c8330/620d7693f2a06e30446fa9c7/BCO_PR_Shop_Assets_prod-thumb_TS01.jpg",
"ANBS" to "${KEY_ART_ASSETS}bltcd126fd51eb09be1/6a21ee1fc451656b3d6841b5/DI_Art_Warlock-Login_illustration_(all_classes)-Illustration_(2).png",
"Fen" to "${KEY_ART_ASSETS}blt8de255bf153ad1e2/63d0275cd791066264c678f4/en_D4_pre-purchase_blog_1920x1080_Primary_TS01.jpg",
"D1" to "${KEY_ART_ASSETS}bltf183b52d38f5d94e/65a089802357a8ed25a05da1/blizzard_diablo_launch_desktop_shopproductasset_bchbnet_stat_enus_1920x1080_EE01.png",
"W1" to "${KEY_ART_ASSETS}blt20214ec16801085a/65a07418cd72b186912c1fac/blizzard_warcraft1_launch_desktop_shopproductasset_bchbnet_stat_enus_1920x1080_EE01.png",
"W2" to "${KEY_ART_ASSETS}blt45a874eacd7a27e4/65a08bf2db6bb9361a1fbc63/blizzard_warcraft2_launch_desktop_shopproductasset_bchbnet_stat_enus_1920x1080_EE01.png",
"W1R" to "${KEY_ART_CATALOG}/7d/405b3c58ecc70c495dcf4b333cdd9e01-WC01_keyArt_finalcopy.png",
"W2R" to "${KEY_ART_CATALOG}/7d/924e7c287781c84865b662d20029680c-WC02_KeyArt_finalcopyV2.png",
"GRY" to "${KEY_ART_ASSETS}bltd22bde30bb1b973e/652d87d52c84c8e75f881b5f/SplashAnims_landscape_1.png",
"ARIS" to "${KEY_ART_ASSETS}bltc5face49eea05c7e/67ca48cb4b61d73198918ba6/shop_product_feature_card_aries_standard.webp",
"SCOR" to "${KEY_ART_ASSETS}blt82dbffc2b51e8aa1/67a562cc7113284f3b17ff7d/phx_notification_browsing_card_scorpio_announce.webp",
"ARK" to "${KEY_ART_ASSETS}blt4a061067c30285dc/6837812aedfd13b46a16c38b/shop_asset_gallery_card_arkansas_wishlist.webp",
"AQUA" to "${KEY_ART_ASSETS}blte982469df0746ee4/672ea9f71dee4754a60cde05/shop_product_edition_card_avowed_standard.jpg",
)
internal fun imageUrl(page: String): String? {
val og = OG.find(page)?.groupValues?.get(1)?.takeUnless { "youtube" in it || "maxresdefault" in it }
@@ -24,16 +59,23 @@ internal object BlizzardArt {
return (sequenceOf(og) + thumbs).filterNotNull().firstOrNull(::allowed)
}
private fun allowed(url: String): Boolean {
internal fun allowed(url: String): Boolean {
val host = runCatching { URL(url).host }.getOrNull() ?: return false
return HOSTS.any { h -> host == h.trimStart('.') || host.endsWith(h) }
}
fun fetch(slug: String, wide: File, cover: File?): Boolean {
val page = get(URL(SHOP + slug), MAX_PAGE, true)?.toString(Charsets.UTF_8) ?: return false
val url = imageUrl(page) ?: return false
val bytes = get(URL(url.substringBefore('?') + "?imwidth=$WIDE"), MAX_IMAGE, false) ?: return false
val art = BitmapFactory.decodeByteArray(bytes, 0, bytes.size) ?: return false
private fun image(url: String): Bitmap? {
val bytes = get(URL(url.substringBefore('?') + "?imwidth=$WIDE"), MAX_IMAGE, false) ?: return null
return BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
}
private fun shopImage(slug: String): Bitmap? {
val page = get(URL(SHOP + slug), MAX_PAGE, true)?.toString(Charsets.UTF_8) ?: return null
return imageUrl(page)?.let(::image)
}
fun fetch(code: String, slug: String, wide: File, cover: File?): Boolean {
val art = runCatching { KEY_ART[code]?.let(::image) }.getOrNull() ?: shopImage(slug) ?: return false
try {
val scaled = if (art.width > WIDE) Bitmap.createScaledBitmap(art, WIDE, art.height * WIDE / art.width, true) else art
save(scaled, wide)