Skip to content

Commit 2ee640d

Browse files
authored
Merge pull request #631 from anxdpanic/pr_isengard
fixup fanart on streams and videos
2 parents b560169 + 44d0aa6 commit 2ee640d

4 files changed

Lines changed: 75 additions & 22 deletions

File tree

resources/lib/twitch_addon/addon/converter.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def followed_game_to_listitem(self, game):
9191

9292
def channel_to_listitem(self, channel):
9393
image = channel.get(Keys.PROFILE_IMAGE_URL) if channel.get(Keys.PROFILE_IMAGE_URL) else Images.ICON
94-
video_banner = channel.get(Keys.OFFLINE_IMAGE_URL) if channel.get(Keys.OFFLINE_IMAGE_URL) else Images.FANART
94+
fanart = self.get_fanart(channel.get(Keys.OFFLINE_IMAGE_URL), Images.FANART)
9595
context_menu = list()
9696
context_menu.extend(menu_items.refresh())
9797
name = channel.get(Keys.DISPLAY_NAME) if channel.get(Keys.DISPLAY_NAME) else channel.get(Keys.LOGIN)
@@ -100,7 +100,7 @@ def channel_to_listitem(self, channel):
100100
return {'label': name,
101101
'path': kodi.get_plugin_url({'mode': MODES.CHANNELVIDEOS, 'channel_id': channel[Keys.ID],
102102
'channel_name': channel[Keys.LOGIN], 'display_name': name}),
103-
'art': the_art({'fanart': video_banner, 'poster': image, 'thumb': image}),
103+
'art': the_art({'fanart': fanart, 'poster': image, 'thumb': image}),
104104
'context_menu': context_menu,
105105
'info': self.get_plot_for_channel(channel)}
106106

@@ -139,6 +139,7 @@ def video_list_to_listitem(self, video):
139139
date = video.get(Keys.CREATED_AT)[:10] if video.get(Keys.CREATED_AT) else ''
140140
year = video.get(Keys.CREATED_AT)[:4] if video.get(Keys.CREATED_AT) else ''
141141
image = self.get_thumbnail(video.get(Keys.THUMBNAIL_URL), Images.VIDEOTHUMB)
142+
fanart = self.get_fanart(video.get(Keys.OFFLINE_IMAGE_URL), Images.FANART)
142143
context_menu = list()
143144
context_menu.extend(menu_items.refresh())
144145
display_name = to_string(video.get(Keys.USER_NAME) if video.get(Keys.USER_NAME) else video.get(Keys.USER_LOGIN))
@@ -160,10 +161,10 @@ def video_list_to_listitem(self, video):
160161
'is_playable': True,
161162
'info': info,
162163
'content_type': 'video',
163-
'art': the_art({'poster': image, 'thumb': image, 'icon': image})}
164+
'art': the_art({'fanart': fanart, 'poster': image, 'thumb': image, 'icon': image})}
164165

165166
def search_stream_to_listitem(self, search):
166-
video_banner = Images.FANART
167+
fanart = self.get_fanart(search.get(Keys.OFFLINE_IMAGE_URL), Images.FANART)
167168
image = self.get_thumbnail(search.get(Keys.THUMBNAIL_URL), Images.VIDEOTHUMB)
168169
if get_refresh_stamp():
169170
image = '?timestamp='.join([image, quote(get_refresh_stamp())])
@@ -193,10 +194,10 @@ def search_stream_to_listitem(self, search):
193194
'is_playable': True,
194195
'info': info,
195196
'content_type': 'video',
196-
'art': the_art({'fanart': video_banner, 'poster': image, 'thumb': image, 'icon': image})}
197+
'art': the_art({'fanart': fanart, 'poster': image, 'thumb': image, 'icon': image})}
197198

198199
def search_channel_to_listitem(self, search):
199-
video_banner = Images.FANART
200+
fanart = self.get_fanart(search.get(Keys.OFFLINE_IMAGE_URL), Images.FANART)
200201
image = self.get_thumbnail(search.get(Keys.THUMBNAIL_URL), Images.VIDEOTHUMB)
201202
if get_refresh_stamp():
202203
image = '?timestamp='.join([image, quote(get_refresh_stamp())])
@@ -218,10 +219,10 @@ def search_channel_to_listitem(self, search):
218219
'context_menu': context_menu,
219220
'info': info,
220221
'content_type': 'video',
221-
'art': the_art({'fanart': video_banner, 'poster': image, 'thumb': image, 'icon': image})}
222+
'art': the_art({'fanart': fanart, 'poster': image, 'thumb': image, 'icon': image})}
222223

223224
def stream_to_listitem(self, stream):
224-
video_banner = Images.FANART
225+
fanart = self.get_fanart(stream.get(Keys.OFFLINE_IMAGE_URL), Images.FANART)
225226
preview = self.get_thumbnail(stream.get(Keys.THUMBNAIL_URL), Images.VIDEOTHUMB)
226227
logo = Images.VIDEOTHUMB
227228
if preview and get_refresh_stamp():
@@ -253,7 +254,7 @@ def stream_to_listitem(self, stream):
253254
'is_playable': True,
254255
'info': info,
255256
'content_type': 'video',
256-
'art': the_art({'fanart': video_banner, 'poster': image, 'thumb': image, 'icon': image})}
257+
'art': the_art({'fanart': fanart, 'poster': image, 'thumb': image, 'icon': image})}
257258

258259
def clip_to_playitem(self, clip):
259260
# path is returned '' and must be set after
@@ -643,7 +644,18 @@ def get_boxart(boxart, default=Images.BOXART):
643644
boxart = boxart.replace('52x72', '{width}x{height}').replace('285x380', '{width}x{height}')
644645

645646
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)
647+
boxart = boxart.replace('%{width}', '{width}').replace('%{height}', '{height}')
648+
return boxart.format(width=width, height=height)
648649

649650
return boxart or default
651+
652+
@staticmethod
653+
def get_fanart(fanart, default=Images.FANART):
654+
if not fanart:
655+
return default
656+
657+
if '{width}' in fanart and '{height}' in fanart:
658+
fanart = fanart.replace('%{width}', '{width}').replace('%{height}', '{height}')
659+
return fanart.format(width='0', height='0')
660+
661+
return fanart or default

resources/lib/twitch_addon/routes/channel_videos.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def route(api, broadcast_type, channel_id=None, game=None, after='MA=='):
2323
kodi.set_view('videos', set_sort=True)
2424
per_page = utils.get_items_per_page()
2525
all_items = list()
26+
user_ids = list()
27+
2628
if game is not None:
2729
period = utils.get_sort('top_videos', 'period')
2830
videos = api.get_top_videos(after=after, first=per_page, game_id=game,
@@ -38,9 +40,22 @@ def route(api, broadcast_type, channel_id=None, game=None, after='MA=='):
3840
videos = api.get_channel_videos(channel_id, broadcast_type, period, after=after, first=per_page,
3941
sort_by=sort_by, language=language)
4042

41-
if Keys.DATA in videos:
42-
for stream in videos[Keys.DATA]:
43-
all_items.append(stream)
43+
for video in videos[Keys.DATA]:
44+
if video.get(Keys.USER_ID):
45+
user_ids.append(video[Keys.USER_ID])
46+
47+
if user_ids:
48+
channels = api.get_users(user_ids)
49+
if Keys.DATA in channels:
50+
for idx, video in enumerate(videos[Keys.DATA]):
51+
videos[Keys.DATA][idx][Keys.OFFLINE_IMAGE_URL] = ''
52+
for channel in channels[Keys.DATA]:
53+
if channel.get(Keys.ID) == video.get(Keys.USER_ID):
54+
videos[Keys.DATA][idx][Keys.OFFLINE_IMAGE_URL] = channel[Keys.OFFLINE_IMAGE_URL]
55+
break
56+
57+
for video in videos[Keys.DATA]:
58+
all_items.append(video)
4459

4560
if len(all_items) > 0:
4661
for video in all_items:

resources/lib/twitch_addon/routes/followed.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,25 @@ def route(api, content, after='MA=='):
3030
kodi.set_view('videos', set_sort=True)
3131

3232
all_items = list()
33+
user_ids = list()
3334

3435
streams = api.get_followed_streams(user_id=user_id, first=per_page, after=after)
35-
36-
if Keys.DATA in streams:
37-
for stream in streams[Keys.DATA]:
38-
all_items.append(stream)
36+
for stream in streams[Keys.DATA]:
37+
if stream.get(Keys.USER_ID):
38+
user_ids.append(stream[Keys.USER_ID])
39+
40+
if user_ids:
41+
channels = api.get_users(user_ids)
42+
if Keys.DATA in channels:
43+
for idx, stream in enumerate(streams[Keys.DATA]):
44+
streams[Keys.DATA][idx][Keys.OFFLINE_IMAGE_URL] = ''
45+
for channel in channels[Keys.DATA]:
46+
if channel.get(Keys.ID) == stream.get(Keys.USER_ID):
47+
streams[Keys.DATA][idx][Keys.OFFLINE_IMAGE_URL] = channel[Keys.OFFLINE_IMAGE_URL]
48+
break
49+
50+
for stream in streams[Keys.DATA]:
51+
all_items.append(stream)
3952

4053
if len(all_items) > 0:
4154
for stream in all_items:

resources/lib/twitch_addon/routes/streams.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,26 @@ def route(api, after='MA=='):
2323
per_page = utils.get_items_per_page()
2424

2525
all_items = list()
26+
user_ids = list()
2627

2728
language = utils.get_language()
2829
streams = api.get_all_streams(after=after, first=per_page, language=language)
29-
30-
if Keys.DATA in streams:
31-
for stream in streams[Keys.DATA]:
32-
all_items.append(stream)
30+
for stream in streams[Keys.DATA]:
31+
if stream.get(Keys.USER_ID):
32+
user_ids.append(stream[Keys.USER_ID])
33+
34+
if user_ids:
35+
channels = api.get_users(user_ids)
36+
if Keys.DATA in channels:
37+
for idx, stream in enumerate(streams[Keys.DATA]):
38+
streams[Keys.DATA][idx][Keys.OFFLINE_IMAGE_URL] = ''
39+
for channel in channels[Keys.DATA]:
40+
if channel.get(Keys.ID) == stream.get(Keys.USER_ID):
41+
streams[Keys.DATA][idx][Keys.OFFLINE_IMAGE_URL] = channel[Keys.OFFLINE_IMAGE_URL]
42+
break
43+
44+
for stream in streams[Keys.DATA]:
45+
all_items.append(stream)
3346

3447
if len(all_items) > 0:
3548
for stream in all_items:

0 commit comments

Comments
 (0)