Skip to content

Commit 4753a5b

Browse files
committed
centralize background fetching by using util.backgroundFromArt; stop using aSet and use addonSettings instead; support per-related-show-background-art for subitems window
1 parent 1ea6c93 commit 4753a5b

File tree

12 files changed

+47
-68
lines changed

12 files changed

+47
-68
lines changed

lib/player.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,9 +848,7 @@ def createTrackListItem(self, track, fanart=None, index=0):
848848
art = fanart or track.defaultArt
849849
li.setArt({
850850
'fanart': art.asTranscodedImageURL(1920, 1080),
851-
'landscape': art.asTranscodedImageURL(1920, 1080, blur=util.aSet.backgroundArtBlurAmount,
852-
opacity=util.aSet.backgroundArtOpacityAmount,
853-
background=colors.noAlpha.Background)
851+
'landscape': util.backgroundFromArt(art)
854852
})
855853
if fanart:
856854
li.setArt({'fanart': fanart})

lib/util.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import xbmc
1616
import xbmcgui
1717
import xbmcaddon
18+
import colors
1819

1920
from plexnet import signalsmixin
2021

@@ -54,7 +55,7 @@ def DEBUG_LOG(msg):
5455
if _SHUTDOWN:
5556
return
5657

57-
if not aSet.debug and not xbmc.getCondVisibility('System.GetBool(debug.showloginfo)'):
58+
if not addonSettings.debug and not xbmc.getCondVisibility('System.GetBool(debug.showloginfo)'):
5859
return
5960

6061
LOG(msg)
@@ -488,13 +489,13 @@ def __init__(self):
488489
getSetting(setting, default))
489490

490491

491-
addonSettings = aSet = AddonSettings()
492+
addonSettings = AddonSettings()
492493

493494

494495
def getAddonSettings():
495496
# yes, global, hang me!
496-
global addonSettings, aSet
497-
addonSettings = aSet = AddonSettings()
497+
global addonSettings
498+
addonSettings = AddonSettings()
498499

499500

500501
def getPlatform():
@@ -520,6 +521,15 @@ def getProgressImage(obj):
520521
return 'script.plex/progress/{0}.png'.format(pct)
521522

522523

524+
def backgroundFromArt(art, width=1920, height=1080, background=colors.noAlpha.Background):
525+
return art.asTranscodedImageURL(
526+
width, height,
527+
blur=addonSettings.backgroundArtBlurAmount,
528+
opacity=addonSettings.backgroundArtOpacityAmount,
529+
background=background
530+
)
531+
532+
523533
def trackIsPlaying(track):
524534
return xbmc.getCondVisibility('String.StartsWith(MusicPlayer.Comment,{0})'.format('PLEX-{0}:'.format(track.ratingKey)))
525535

lib/windows/episodes.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,12 @@ def onAction(self, action):
179179
self.prev()
180180

181181
elif action.getId() in MOVE_SET:
182-
if util.aSet.backgroundArtPerItem and self.lastFocusID == self.RELATED_LIST_ID:
182+
if util.addonSettings.backgroundArtPerItem and self.lastFocusID == self.RELATED_LIST_ID:
183183
mli = self.relatedListControl.getSelectedItem()
184184
if mli:
185185
self.setProperty(
186-
'background', mli.dataSource.art.asTranscodedImageURL(
187-
self.width, self.height,
188-
blur=util.aSet.backgroundArtBlurAmount,
189-
opacity=util.aSet.backgroundArtOpacityAmount,
190-
background=colors.noAlpha.Background)
186+
'background', util.backgroundFromArt(mli.dataSource.art, width=self.width,
187+
height=self.height)
191188
)
192189

193190
if controlID == self.EPISODE_LIST_ID:
@@ -638,9 +635,7 @@ def updateProperties(self):
638635

639636
self.setProperty(
640637
'background',
641-
(self.show_ or self.season.show()).art.asTranscodedImageURL(
642-
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
643-
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background)
638+
util.backgroundFromArt((self.show_ or self.season.show()).art, width=self.width, height=self.height)
644639
)
645640
self.setProperty('season.thumb', self.season.thumb.asTranscodedImageURL(*self.POSTER_DIM))
646641
self.setProperty('show.title', showTitle)
@@ -664,9 +659,7 @@ def updateItems(self, item=None):
664659

665660
def setItemInfo(self, video, mli):
666661
# video.reload(checkFiles=1)
667-
mli.setProperty('background', video.art.asTranscodedImageURL(
668-
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
669-
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background))
662+
mli.setProperty('background', util.backgroundFromArt(video.art, width=self.width, height=self.height))
670663
mli.setProperty('title', video.title)
671664
mli.setProperty('show.title', video.grandparentTitle or (self.show_.title if self.show_ else ''))
672665
mli.setProperty('duration', util.durationToText(video.duration.asInt()))

lib/windows/home.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -584,13 +584,9 @@ def checkHubItem(self, controlID):
584584
mli = control.getSelectedItem()
585585
is_valid_mli = mli and mli.getProperty('is.end') != '1'
586586

587-
if util.aSet.backgroundArtPerItem and is_valid_mli:
587+
if util.addonSettings.backgroundArtPerItem and is_valid_mli:
588588
self.setProperty(
589-
'background', mli.dataSource.art.asTranscodedImageURL(
590-
self.width, self.height,
591-
blur=util.aSet.backgroundArtBlurAmount,
592-
opacity=util.aSet.backgroundArtOpacityAmount,
593-
background=colors.noAlpha.Background)
589+
'background', util.backgroundFromArt(mli.dataSource.art, width=self.width, height=self.height)
594590
)
595591

596592
if not mli or not mli.getProperty('is.end'):
@@ -958,10 +954,7 @@ def _showHub(self, hub, hubitems=None, index=None, with_progress=False, with_art
958954
if not self.backgroundSet:
959955
self.backgroundSet = True
960956
self.setProperty(
961-
'background', obj.art.asTranscodedImageURL(self.width, self.height,
962-
blur=util.aSet.backgroundArtBlurAmount,
963-
opacity=util.aSet.backgroundArtOpacityAmount,
964-
background=colors.noAlpha.Background)
957+
'background', util.backgroundFromArt(obj.art, width=self.width, height=self.height)
965958
)
966959
mli = self.createListItem(obj, wide=with_art)
967960
if mli:

lib/windows/library.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,9 +1219,7 @@ def setBackground(self, items):
12191219
self.backgroundSet = True
12201220

12211221
item = random.choice(items)
1222-
self.setProperty('background', item.art.asTranscodedImageURL(
1223-
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
1224-
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background))
1222+
self.setProperty('background', util.backgroundFromArt(item.art, width=self.width, height=self.height))
12251223

12261224
def fill(self):
12271225
if self.chunkMode:
@@ -1415,9 +1413,7 @@ def fillPhotos(self):
14151413
return
14161414

14171415
photo = random.choice(photos)
1418-
self.setProperty('background', photo.art.asTranscodedImageURL(
1419-
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
1420-
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background))
1416+
self.setProperty('background', util.backgroundFromArt(photo.art, width=self.width, height=self.height))
14211417
thumbDim = TYPE_KEYS.get(self.section.type, TYPE_KEYS['movie'])['thumb_dim']
14221418
fallback = 'script.plex/thumb_fallbacks/{0}.png'.format(TYPE_KEYS.get(self.section.type, TYPE_KEYS['movie'])['fallback'])
14231419

lib/windows/photos.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,7 @@ def _reallyShowPhoto(self):
245245
url = photo.server.getImageTranscodeURL(meta.get('url', ''), self.width, self.height)
246246
self.setRotation(0)
247247
self.setProperty('photo', url)
248-
self.setProperty('background', photo.thumb.asTranscodedImageURL(
249-
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
250-
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background))
248+
self.setProperty('background', util.backgroundFromArt(photo.thumb, width=self.width, height=self.height))
251249

252250
self.setProperty('photo.title', photo.title)
253251
self.setProperty('photo.date', util.cleanLeadingZeros(photo.originallyAvailableAt.asDatetime('%d %B %Y')))

lib/windows/playlist.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@ def optionsButtonClicked(self):
225225
def setProperties(self):
226226
self.setProperty(
227227
'background',
228-
self.playlist.composite.asTranscodedImageURL(
229-
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
230-
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background)
228+
util.backgroundFromArt(self.playlist.composite, width=self.width, height=self.height)
231229
)
232230
self.setProperty('playlist.thumb', self.playlist.composite.asTranscodedImageURL(*self.ALBUM_THUMB_DIM))
233231
self.setProperty('playlist.title', self.playlist.title)

lib/windows/playlists.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ def fill(self):
119119

120120
self.setProperty(
121121
'background',
122-
playlists[0].composite.asTranscodedImageURL(self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
123-
opacity=util.aSet.backgroundArtOpacityAmount,
124-
background=colors.noAlpha.Background)
122+
util.backgroundFromArt(playlists[0].composite, width=self.width, height=self.height)
125123
)
126124

127125
for pl in playlists:

lib/windows/preplay.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,12 @@ def onAction(self, action):
9999
self.setFocusId(self.lastFocusID)
100100

101101
if action.getId() in MOVE_SET:
102-
if util.aSet.backgroundArtPerItem and self.lastFocusID == self.RELATED_LIST_ID:
102+
if util.addonSettings.backgroundArtPerItem and self.lastFocusID == self.RELATED_LIST_ID:
103103
mli = self.relatedListControl.getSelectedItem()
104104
if mli:
105105
self.setProperty(
106-
'background', mli.dataSource.art.asTranscodedImageURL(
107-
self.width, self.height,
108-
blur=util.aSet.backgroundArtBlurAmount,
109-
opacity=util.aSet.backgroundArtOpacityAmount,
110-
background=colors.noAlpha.Background)
106+
'background', util.backgroundFromArt(mli.dataSource.art, width=self.width,
107+
height=self.height)
111108
)
112109

113110
if action in(xbmcgui.ACTION_NAV_BACK, xbmcgui.ACTION_CONTEXT_MENU):
@@ -449,9 +446,7 @@ def setup(self):
449446
self.fillRoles(hasPrev)
450447

451448
def setInfo(self):
452-
self.setProperty('background', self.video.art.asTranscodedImageURL(
453-
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
454-
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background))
449+
self.setProperty('background', util.backgroundFromArt(self.video.art, width=self.width, height=self.height))
455450
self.setProperty('title', self.video.title)
456451
self.setProperty('duration', util.durationToText(self.video.duration.asInt()))
457452
self.setProperty('summary', self.video.summary.strip().replace('\t', ' '))

lib/windows/subitems.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import search
2323

2424
from lib.util import T
25+
from lib.windows.home import MOVE_SET
2526

2627

2728
class ShowWindow(kodigui.ControlledWindow, windowutils.UtilMixin):
@@ -104,9 +105,7 @@ def updateProperties(self):
104105
self.setProperty('thumb', self.mediaItem.defaultThumb.asTranscodedImageURL(*self.THUMB_DIMS[self.mediaItem.type]['main.thumb']))
105106
self.setProperty(
106107
'background',
107-
self.mediaItem.art.asTranscodedImageURL(self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
108-
opacity=util.aSet.backgroundArtOpacityAmount,
109-
background=colors.noAlpha.Background)
108+
util.backgroundFromArt(self.mediaItem.art, width=self.width, height=self.height)
110109
)
111110
self.setProperty('duration', util.durationToText(self.mediaItem.fixedDuration()))
112111
self.setProperty('info', '')
@@ -177,6 +176,15 @@ def onAction(self, action):
177176
self.setFocusId(self.OPTIONS_GROUP_ID)
178177
return
179178

179+
elif action.getId() in MOVE_SET:
180+
if util.addonSettings.backgroundArtPerItem and self.lastFocusID == self.RELATED_LIST_ID:
181+
mli = self.relatedListControl.getSelectedItem()
182+
if mli:
183+
self.setProperty(
184+
'background', util.backgroundFromArt(mli.dataSource.art, width=self.width,
185+
height=self.height)
186+
)
187+
180188
if action == xbmcgui.ACTION_LAST_PAGE and xbmc.getCondVisibility('ControlGroup(300).HasFocus(0)'):
181189
self.next()
182190
elif action == xbmcgui.ACTION_NEXT_ITEM:
@@ -594,9 +602,7 @@ def updateProperties(self):
594602
self.setProperty('thumb', self.mediaItem.defaultThumb.asTranscodedImageURL(*self.THUMB_DIMS[self.mediaItem.type]['main.thumb']))
595603
self.setProperty(
596604
'background',
597-
self.mediaItem.art.asTranscodedImageURL(self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
598-
opacity=util.aSet.backgroundArtOpacityAmount,
599-
background=colors.noAlpha.Background)
605+
util.backgroundFromArt(self.mediaItem.art, width=self.width, height=self.height)
600606
)
601607

602608
@busy.dialog()

0 commit comments

Comments
 (0)