Skip to content

Commit

Permalink
centralize background fetching by using util.backgroundFromArt; stop …
Browse files Browse the repository at this point in the history
…using aSet and use addonSettings instead; support per-related-show-background-art for subitems window
  • Loading branch information
pannal committed Jun 7, 2018
1 parent 1ea6c93 commit 4753a5b
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 68 deletions.
4 changes: 1 addition & 3 deletions lib/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,9 +848,7 @@ def createTrackListItem(self, track, fanart=None, index=0):
art = fanart or track.defaultArt
li.setArt({
'fanart': art.asTranscodedImageURL(1920, 1080),
'landscape': art.asTranscodedImageURL(1920, 1080, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount,
background=colors.noAlpha.Background)
'landscape': util.backgroundFromArt(art)
})
if fanart:
li.setArt({'fanart': fanart})
Expand Down
18 changes: 14 additions & 4 deletions lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import xbmc
import xbmcgui
import xbmcaddon
import colors

from plexnet import signalsmixin

Expand Down Expand Up @@ -54,7 +55,7 @@ def DEBUG_LOG(msg):
if _SHUTDOWN:
return

if not aSet.debug and not xbmc.getCondVisibility('System.GetBool(debug.showloginfo)'):
if not addonSettings.debug and not xbmc.getCondVisibility('System.GetBool(debug.showloginfo)'):
return

LOG(msg)
Expand Down Expand Up @@ -488,13 +489,13 @@ def __init__(self):
getSetting(setting, default))


addonSettings = aSet = AddonSettings()
addonSettings = AddonSettings()


def getAddonSettings():
# yes, global, hang me!
global addonSettings, aSet
addonSettings = aSet = AddonSettings()
global addonSettings
addonSettings = AddonSettings()


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


def backgroundFromArt(art, width=1920, height=1080, background=colors.noAlpha.Background):
return art.asTranscodedImageURL(
width, height,
blur=addonSettings.backgroundArtBlurAmount,
opacity=addonSettings.backgroundArtOpacityAmount,
background=background
)


def trackIsPlaying(track):
return xbmc.getCondVisibility('String.StartsWith(MusicPlayer.Comment,{0})'.format('PLEX-{0}:'.format(track.ratingKey)))

Expand Down
17 changes: 5 additions & 12 deletions lib/windows/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,12 @@ def onAction(self, action):
self.prev()

elif action.getId() in MOVE_SET:
if util.aSet.backgroundArtPerItem and self.lastFocusID == self.RELATED_LIST_ID:
if util.addonSettings.backgroundArtPerItem and self.lastFocusID == self.RELATED_LIST_ID:
mli = self.relatedListControl.getSelectedItem()
if mli:
self.setProperty(
'background', mli.dataSource.art.asTranscodedImageURL(
self.width, self.height,
blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount,
background=colors.noAlpha.Background)
'background', util.backgroundFromArt(mli.dataSource.art, width=self.width,
height=self.height)
)

if controlID == self.EPISODE_LIST_ID:
Expand Down Expand Up @@ -638,9 +635,7 @@ def updateProperties(self):

self.setProperty(
'background',
(self.show_ or self.season.show()).art.asTranscodedImageURL(
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background)
util.backgroundFromArt((self.show_ or self.season.show()).art, width=self.width, height=self.height)
)
self.setProperty('season.thumb', self.season.thumb.asTranscodedImageURL(*self.POSTER_DIM))
self.setProperty('show.title', showTitle)
Expand All @@ -664,9 +659,7 @@ def updateItems(self, item=None):

def setItemInfo(self, video, mli):
# video.reload(checkFiles=1)
mli.setProperty('background', video.art.asTranscodedImageURL(
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background))
mli.setProperty('background', util.backgroundFromArt(video.art, width=self.width, height=self.height))
mli.setProperty('title', video.title)
mli.setProperty('show.title', video.grandparentTitle or (self.show_.title if self.show_ else ''))
mli.setProperty('duration', util.durationToText(video.duration.asInt()))
Expand Down
13 changes: 3 additions & 10 deletions lib/windows/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,13 +584,9 @@ def checkHubItem(self, controlID):
mli = control.getSelectedItem()
is_valid_mli = mli and mli.getProperty('is.end') != '1'

if util.aSet.backgroundArtPerItem and is_valid_mli:
if util.addonSettings.backgroundArtPerItem and is_valid_mli:
self.setProperty(
'background', mli.dataSource.art.asTranscodedImageURL(
self.width, self.height,
blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount,
background=colors.noAlpha.Background)
'background', util.backgroundFromArt(mli.dataSource.art, width=self.width, height=self.height)
)

if not mli or not mli.getProperty('is.end'):
Expand Down Expand Up @@ -958,10 +954,7 @@ def _showHub(self, hub, hubitems=None, index=None, with_progress=False, with_art
if not self.backgroundSet:
self.backgroundSet = True
self.setProperty(
'background', obj.art.asTranscodedImageURL(self.width, self.height,
blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount,
background=colors.noAlpha.Background)
'background', util.backgroundFromArt(obj.art, width=self.width, height=self.height)
)
mli = self.createListItem(obj, wide=with_art)
if mli:
Expand Down
8 changes: 2 additions & 6 deletions lib/windows/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,9 +1219,7 @@ def setBackground(self, items):
self.backgroundSet = True

item = random.choice(items)
self.setProperty('background', item.art.asTranscodedImageURL(
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background))
self.setProperty('background', util.backgroundFromArt(item.art, width=self.width, height=self.height))

def fill(self):
if self.chunkMode:
Expand Down Expand Up @@ -1415,9 +1413,7 @@ def fillPhotos(self):
return

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

Expand Down
4 changes: 1 addition & 3 deletions lib/windows/photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ def _reallyShowPhoto(self):
url = photo.server.getImageTranscodeURL(meta.get('url', ''), self.width, self.height)
self.setRotation(0)
self.setProperty('photo', url)
self.setProperty('background', photo.thumb.asTranscodedImageURL(
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background))
self.setProperty('background', util.backgroundFromArt(photo.thumb, width=self.width, height=self.height))

self.setProperty('photo.title', photo.title)
self.setProperty('photo.date', util.cleanLeadingZeros(photo.originallyAvailableAt.asDatetime('%d %B %Y')))
Expand Down
4 changes: 1 addition & 3 deletions lib/windows/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ def optionsButtonClicked(self):
def setProperties(self):
self.setProperty(
'background',
self.playlist.composite.asTranscodedImageURL(
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background)
util.backgroundFromArt(self.playlist.composite, width=self.width, height=self.height)
)
self.setProperty('playlist.thumb', self.playlist.composite.asTranscodedImageURL(*self.ALBUM_THUMB_DIM))
self.setProperty('playlist.title', self.playlist.title)
Expand Down
4 changes: 1 addition & 3 deletions lib/windows/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ def fill(self):

self.setProperty(
'background',
playlists[0].composite.asTranscodedImageURL(self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount,
background=colors.noAlpha.Background)
util.backgroundFromArt(playlists[0].composite, width=self.width, height=self.height)
)

for pl in playlists:
Expand Down
13 changes: 4 additions & 9 deletions lib/windows/preplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,12 @@ def onAction(self, action):
self.setFocusId(self.lastFocusID)

if action.getId() in MOVE_SET:
if util.aSet.backgroundArtPerItem and self.lastFocusID == self.RELATED_LIST_ID:
if util.addonSettings.backgroundArtPerItem and self.lastFocusID == self.RELATED_LIST_ID:
mli = self.relatedListControl.getSelectedItem()
if mli:
self.setProperty(
'background', mli.dataSource.art.asTranscodedImageURL(
self.width, self.height,
blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount,
background=colors.noAlpha.Background)
'background', util.backgroundFromArt(mli.dataSource.art, width=self.width,
height=self.height)
)

if action in(xbmcgui.ACTION_NAV_BACK, xbmcgui.ACTION_CONTEXT_MENU):
Expand Down Expand Up @@ -449,9 +446,7 @@ def setup(self):
self.fillRoles(hasPrev)

def setInfo(self):
self.setProperty('background', self.video.art.asTranscodedImageURL(
self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount, background=colors.noAlpha.Background))
self.setProperty('background', util.backgroundFromArt(self.video.art, width=self.width, height=self.height))
self.setProperty('title', self.video.title)
self.setProperty('duration', util.durationToText(self.video.duration.asInt()))
self.setProperty('summary', self.video.summary.strip().replace('\t', ' '))
Expand Down
18 changes: 12 additions & 6 deletions lib/windows/subitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import search

from lib.util import T
from lib.windows.home import MOVE_SET


class ShowWindow(kodigui.ControlledWindow, windowutils.UtilMixin):
Expand Down Expand Up @@ -104,9 +105,7 @@ def updateProperties(self):
self.setProperty('thumb', self.mediaItem.defaultThumb.asTranscodedImageURL(*self.THUMB_DIMS[self.mediaItem.type]['main.thumb']))
self.setProperty(
'background',
self.mediaItem.art.asTranscodedImageURL(self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount,
background=colors.noAlpha.Background)
util.backgroundFromArt(self.mediaItem.art, width=self.width, height=self.height)
)
self.setProperty('duration', util.durationToText(self.mediaItem.fixedDuration()))
self.setProperty('info', '')
Expand Down Expand Up @@ -177,6 +176,15 @@ def onAction(self, action):
self.setFocusId(self.OPTIONS_GROUP_ID)
return

elif action.getId() in MOVE_SET:
if util.addonSettings.backgroundArtPerItem and self.lastFocusID == self.RELATED_LIST_ID:
mli = self.relatedListControl.getSelectedItem()
if mli:
self.setProperty(
'background', util.backgroundFromArt(mli.dataSource.art, width=self.width,
height=self.height)
)

if action == xbmcgui.ACTION_LAST_PAGE and xbmc.getCondVisibility('ControlGroup(300).HasFocus(0)'):
self.next()
elif action == xbmcgui.ACTION_NEXT_ITEM:
Expand Down Expand Up @@ -594,9 +602,7 @@ def updateProperties(self):
self.setProperty('thumb', self.mediaItem.defaultThumb.asTranscodedImageURL(*self.THUMB_DIMS[self.mediaItem.type]['main.thumb']))
self.setProperty(
'background',
self.mediaItem.art.asTranscodedImageURL(self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount,
background=colors.noAlpha.Background)
util.backgroundFromArt(self.mediaItem.art, width=self.width, height=self.height)
)

@busy.dialog()
Expand Down
4 changes: 1 addition & 3 deletions lib/windows/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ def trackPanelClicked(self):
def updateProperties(self):
self.setProperty(
'background',
self.album.art.asTranscodedImageURL(self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount,
background=colors.noAlpha.Background)
util.backgroundFromArt(self.album.art, width=self.width, height=self.height)
)
self.setProperty('album.thumb', self.album.thumb.asTranscodedImageURL(*self.THUMB_SQUARE_DIM))
self.setProperty('artist.title', self.album.parentTitle or '')
Expand Down
8 changes: 2 additions & 6 deletions lib/windows/videoplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,7 @@ def setInfo(self):
if self.next:
self.setProperty(
'post.play.background',
self.next.art.asTranscodedImageURL(self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount,
background=colors.noAlpha.Background)
util.backgroundFromArt(self.next.art, width=self.width, height=self.height)
)
self.setProperty('info.title', self.next.title)
self.setProperty('info.duration', util.durationToText(self.next.duration.asInt()))
Expand All @@ -364,9 +362,7 @@ def setInfo(self):
if self.prev:
self.setProperty(
'post.play.background',
self.prev.art.asTranscodedImageURL(self.width, self.height, blur=util.aSet.backgroundArtBlurAmount,
opacity=util.aSet.backgroundArtOpacityAmount,
background=colors.noAlpha.Background)
util.backgroundFromArt(self.prev.art, width=self.width, height=self.height)
)
self.setProperty('prev.info.title', self.prev.title)
self.setProperty('prev.info.duration', util.durationToText(self.prev.duration.asInt()))
Expand Down

0 comments on commit 4753a5b

Please sign in to comment.