Skip to content

Commit b560169

Browse files
authored
Merge pull request #629 from anxdpanic/pr_isengard
fixup boxart resolution
2 parents 0f1cc81 + 04c3faf commit b560169

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

resources/lib/twitch_addon/addon/converter.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def game_to_listitem(self, game):
5555
if not name:
5656
name = i18n('unknown_game')
5757

58-
image = self.get_thumbnail(game.get(Keys.BOX_ART_URL), Images.BOXART)
58+
image = self.get_boxart(game.get(Keys.BOX_ART_URL), Images.BOXART)
5959
context_menu = list()
6060
context_menu.extend(menu_items.refresh())
6161
if get_private_oauth_token():
@@ -68,8 +68,7 @@ def game_to_listitem(self, game):
6868
'context_menu': context_menu,
6969
'info': {u'plot': plot, u'plotoutline': plot, u'tagline': plot}}
7070

71-
@staticmethod
72-
def followed_game_to_listitem(game):
71+
def followed_game_to_listitem(self, game):
7372
viewer_count = i18n('unknown')
7473
if 'viewersCount' in game:
7574
viewer_count = str(game['viewersCount'])
@@ -78,7 +77,7 @@ def followed_game_to_listitem(game):
7877
name = name.encode('utf-8', 'ignore')
7978
if not name:
8079
name = i18n('unknown_game')
81-
image = game['boxArtURL'] or Images.BOXART
80+
image = self.get_boxart(game['boxArtURL'], Images.BOXART)
8281
context_menu = list()
8382
context_menu.extend(menu_items.refresh())
8483
context_menu.extend(menu_items.edit_follow_game(game['id'], name, follow=False))
@@ -625,3 +624,26 @@ def get_thumbnail(thumbnail, default=Images.THUMB):
625624
return thumbnail.format(width=width, height=height)
626625

627626
return thumbnail or default
627+
628+
@staticmethod
629+
def get_boxart(boxart, default=Images.BOXART):
630+
if not boxart:
631+
return default
632+
633+
sizes = {
634+
Keys.SOURCE: ('0', '0'),
635+
Keys.LARGE: ('540', '720'),
636+
Keys.MEDIUM: ('285', '380'),
637+
Keys.SMALL: ('52', '72'),
638+
}
639+
640+
thumbnail_size = get_thumbnail_size()
641+
width, height = sizes.get(thumbnail_size, Keys.SOURCE)
642+
643+
boxart = boxart.replace('52x72', '{width}x{height}').replace('285x380', '{width}x{height}')
644+
645+
if '{width}' in boxart and '{height}' in boxart:
646+
thumbnail = boxart.replace('%{width}', '{width}').replace('%{height}', '{height}')
647+
return thumbnail.format(width=width, height=height)
648+
649+
return boxart or default

0 commit comments

Comments
 (0)