Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced Settings: Make background art blur and opacity configurable; display background art per item #197

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,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=128, opacity=60, background=colors.noAlpha.Background)
'landscape': util.backgroundFromArt(art)
})
if fanart:
li.setArt({'fanart': fanart})
Expand Down
13 changes: 13 additions & 0 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 @@ -469,6 +470,9 @@ class AdvancedSettings(object):
("auto_seek", True),
("dynamic_timeline_seek", False),
("fast_back", False),
("dynamic_backgrounds", False),
("background_art_blur_amount", 128),
("background_art_opacity_amount", 60),
)

def __init__(self):
Expand Down Expand Up @@ -548,6 +552,15 @@ def getProgressImage(obj):
return 'script.plex/progress/{0}.png'.format(pct)


def backgroundFromArt(art, width=1920, height=1080, background=colors.noAlpha.Background):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put the width and height values into global values and use those here.

return art.asTranscodedImageURL(
width, height,
blur=advancedSettings.backgroundArtBlurAmount,
opacity=advancedSettings.backgroundArtOpacityAmount,
background=background
)


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

Expand Down
5 changes: 3 additions & 2 deletions lib/windows/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import preplayutils

from lib.util import T
from lib.windows.home import MOVE_SET
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this used anywhere.



class EpisodeReloadTask(backgroundthread.Task):
Expand Down Expand Up @@ -646,7 +647,7 @@ def updateProperties(self):

self.setProperty(
'background',
(self.show_ or self.season.show()).art.asTranscodedImageURL(self.width, self.height, blur=128, opacity=60, background=colors.noAlpha.Background)
util.backgroundFromArt((self.show_ or self.season.show()).art, width=self.width, height=self.height)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just drop the width and height here (and for the rest). We can change it in the util in the unlikely event we need to change this globally, and in the even more unlikely event we need to change it on a per screen basis, we can just add it at that time.

)
self.setProperty('season.thumb', self.season.thumb.asTranscodedImageURL(*self.POSTER_DIM))
self.setProperty('show.title', showTitle)
Expand All @@ -670,7 +671,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=128, opacity=60, 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
12 changes: 11 additions & 1 deletion lib/windows/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,13 @@ def checkSectionItem(self, force=False, action=None):
def checkHubItem(self, controlID):
control = self.hubControls[controlID - 400]
mli = control.getSelectedItem()
is_valid_mli = mli and mli.getProperty('is.end') != '1'

if util.advancedSettings.dynamicBackgrounds and is_valid_mli:
self.setProperty(
'background', util.backgroundFromArt(mli.dataSource.art, width=self.width, height=self.height)
)

if not mli or not mli.getProperty('is.end') or mli.getProperty('is.updating') == '1':
return

Expand Down Expand Up @@ -651,6 +658,9 @@ def _sectionChanged(self):
def _sectionReallyChanged(self):
section = self.lastSection
self.setProperty('hub.focus', '')
if util.advancedSettings.dynamicBackgrounds:
self.backgroundSet = False

util.DEBUG_LOG('Section changed ({0}): {1}'.format(section.key, repr(section.title)))
self.showHubs(section)
self.lastSection = section
Expand Down Expand Up @@ -973,7 +983,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=128, opacity=60, 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
29 changes: 23 additions & 6 deletions lib/windows/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,14 @@ def onAction(self, action):
self.setBoolProperty('dragging', self.dragging)

if action.getId() in MOVE_SET:
if util.advancedSettings.dynamicBackgrounds:
mli = self.showPanelControl.getSelectedItem()
if mli and mli.dataSource:
self.setProperty(
'background', util.backgroundFromArt(mli.dataSource.art, width=self.width,
height=self.height)
)

controlID = self.getFocusId()
if controlID == self.POSTERS_PANEL_ID or controlID == self.SCROLLBAR_ID:
self.updateKey()
Expand Down Expand Up @@ -1229,13 +1237,21 @@ def updateItem(self, mli=None):
backgroundthread.BGThreader.moveToFront(task)
break

def setBackground(self, items):
def setBackground(self, items, position, randomize=True):
if self.backgroundSet:
return
self.backgroundSet = True

item = random.choice(items)
self.setProperty('background', item.art.asTranscodedImageURL(self.width, self.height, blur=128, opacity=60, background=colors.noAlpha.Background))
if randomize:
item = random.choice(items)
self.setProperty('background', util.backgroundFromArt(item.art, width=self.width, height=self.height))
else:
# we want the first item of the first chunk
if position is not 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this check to the caller and remove the position argument from this function.

return

self.setProperty('background', util.backgroundFromArt(items[0].art,
width=self.width, height=self.height))
self.backgroundSet = True

def fill(self):
if self.chunkMode:
Expand Down Expand Up @@ -1429,7 +1445,7 @@ def fillPhotos(self):
return

photo = random.choice(photos)
self.setProperty('background', photo.art.asTranscodedImageURL(self.width, self.height, blur=128, opacity=60, 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 Expand Up @@ -1507,7 +1523,8 @@ def _chunkCallback(self, items, start):
if self.chunkMode and not self.chunkMode.posIsValid(start):
return
pos = start
self.setBackground(items)
self.setBackground(items, pos, randomize=not util.advancedSettings.dynamicBackgrounds)

thumbDim = TYPE_KEYS.get(self.section.type, TYPE_KEYS['movie'])['thumb_dim']
artDim = TYPE_KEYS.get(self.section.type, TYPE_KEYS['movie']).get('art_dim', (256, 256))

Expand Down
2 changes: 1 addition & 1 deletion lib/windows/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def optionsButtonClicked(self):
def setProperties(self):
self.setProperty(
'background',
self.playlist.composite.asTranscodedImageURL(self.width, self.height, blur=128, opacity=60, 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
2 changes: 1 addition & 1 deletion lib/windows/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def fill(self):

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

for pl in playlists:
Expand Down
3 changes: 2 additions & 1 deletion lib/windows/preplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from lib import metadata

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

VIDEO_RELOAD_KW = dict(includeRelated=1, includeRelatedCount=10)

Expand Down Expand Up @@ -447,7 +448,7 @@ def setup(self):
self.fillRoles(hasPrev)

def setInfo(self):
self.setProperty('background', self.video.art.asTranscodedImageURL(self.width, self.height, blur=128, opacity=60, 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
5 changes: 3 additions & 2 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 @@ -105,7 +106,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=128, opacity=60, 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 @@ -607,7 +608,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=128, opacity=60, background=colors.noAlpha.Background)
util.backgroundFromArt(self.mediaItem.art, width=self.width, height=self.height)
)

@busy.dialog()
Expand Down
2 changes: 1 addition & 1 deletion lib/windows/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def trackPanelClicked(self):
def updateProperties(self):
self.setProperty(
'background',
self.album.art.asTranscodedImageURL(self.width, self.height, blur=128, opacity=60, 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
4 changes: 2 additions & 2 deletions lib/windows/videoplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def setInfo(self):
if self.next:
self.setProperty(
'post.play.background',
self.next.art.asTranscodedImageURL(self.width, self.height, blur=128, opacity=60, 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 @@ -373,7 +373,7 @@ def setInfo(self):
if self.prev:
self.setProperty(
'post.play.background',
self.prev.art.asTranscodedImageURL(self.width, self.height, blur=128, opacity=60, 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
12 changes: 12 additions & 0 deletions resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,18 @@ msgctxt "#32467"
msgid "User Interface"
msgstr ""

msgctxt "#32468"
msgid "Show dynamic background art"
msgstr ""

msgctxt "#32469"
msgid "Background art blur amount"
msgstr ""

msgctxt "#32470"
msgid "Background art opacity"
msgstr ""

msgctxt "#32471"
msgid "Use Plex/Kodi steps for timeline"
msgstr ""
Expand Down
12 changes: 12 additions & 0 deletions resources/language/German/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,18 @@ msgctxt "#32467"
msgid "User Interface"
msgstr "Benutzeroberfläche"

msgctxt "#32468"
msgid "Show dynamic background art"
msgstr "Dynamische Hintergrundbilder aktivieren"

msgctxt "#32469"
msgid "Background art blur amount"
msgstr "Unschärfe der Hintergrundbilder"

msgctxt "#32470"
msgid "Background art opacity"
msgstr "Deckkraft der Hintergrundbilder"

msgctxt "#32471"
msgid "Use Plex/Kodi steps for timeline"
msgstr "Plex/Kodi-Skip-Schritte für die Zeitachse verwenden"
Expand Down
3 changes: 3 additions & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
</category>
<category label="32467">
<setting id="fast_back" type="bool" label="32485" default="false" />
<setting id="dynamic_backgrounds" type="bool" label="32468" default="false" />
<setting id="background_art_blur_amount" type="slider" label="32469" default="128" range="0,256" />
<setting id="background_art_opacity_amount" type="slider" label="32470" default="60" range="0,100" />
</category>
</settings>