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

Added slideshow based screensaver. #270

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions addon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<extension point="xbmc.python.pluginsource" library="plugin.py">
<provides>executable</provides>
</extension>
<extension point="xbmc.ui.screensaver" library="screensaver.py"/>
<extension point="xbmc.service" library="service.py" start="startup"></extension>
<extension point="xbmc.addon.metadata">
<summary lang="en">Plex for Kodi</summary>
Expand Down
1 change: 1 addition & 0 deletions lib/_included_packages/plexnet/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def isPhotoOrDirectoryItem(self):


@plexobjects.registerLibFactory('photo')
@plexobjects.registerLibFactory('image')
def PhotoFactory(data, initpath=None, server=None, container=None):
if data.tag == 'Photo':
return Photo(data, initpath=initpath, server=server, container=container)
Expand Down
3 changes: 3 additions & 0 deletions lib/_included_packages/plexnet/plexlibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def optimize(self):

def refresh(self):
self.server.query('/library/sections/all/refresh')

def randomArts(self):
return plexobjects.listItems(self.server, '/library/arts?sort=random&type=1%2c2%2c8&X-Plex-Container-Start=0&X-Plex-Container-Size=50')


class LibrarySection(plexobjects.PlexObject):
Expand Down
1 change: 1 addition & 0 deletions lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class AdvancedSettings(object):
("auto_seek", True),
("dynamic_timeline_seek", False),
("fast_back", False),
("screensaver_quiz", False),
)

def __init__(self):
Expand Down
108 changes: 108 additions & 0 deletions lib/windows/slidehshow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import time
import random

import kodigui

from lib import util
from plexnet import plexapp

class Slideshow(kodigui.BaseWindow, util.CronReceiver):
xmlFile = 'script-plex-slideshow.xml'
path = util.ADDON.getAddonInfo('path')
theme = 'Main'
res = '1080i'
width = 1920
height = 1080

TIME_BETWEEN_IMAGES = 15
TIME_HIDE_TITLE_IN_QUIZ = 5
TIME_DISPLAY_MOVE = 60

CONTROL_INFO_GROUP = 100

def __init__(self, *args, **kwargs):
kodigui.BaseWindow.__init__(self, *args, **kwargs)
self.timeBetweenImages = self.TIME_BETWEEN_IMAGES
self.timeBetweenDisplayMove = self.TIME_DISPLAY_MOVE
self.timeTitleIsHidden = self.TIME_HIDE_TITLE_IN_QUIZ
self.quizMode = util.advancedSettings.screensaverQuiz
self.initialized = False

def onFirstInit(self):
self.setProperty('clock', '')
self.setProperty('title', '')
self.setProperty('thumb', '')
self.setProperty('align', '0')

self.infoGroupControl = self.getControl(self.CONTROL_INFO_GROUP)

util.CRON.registerReceiver(self)
self.timeFormat = util.timeFormat.replace(":%S", "")
self.lastTime = ''
self.displayPosition = 0
self.changeTime = time.time() - 1
self.displayMoveTime = time.time() + self.timeBetweenDisplayMove
self.revealTitleTime = None

self.selectedServer = plexapp.SERVERMANAGER.selectedServer
self.index = -1
self.images = []

self.initialized = True

def tick(self):
if not self.initialized:
return

currentTime = time.time()
timestr = time.strftime(self.timeFormat, time.localtime(currentTime))
if not util.padHour and timestr[0] == "0" and timestr[1] != ":":
timestr = timestr[1:]

if currentTime > self.changeTime:
nextIndex = self.index + 1

if nextIndex >= len(self.images):
if self.selectedServer != None:
self.images = self.selectedServer.library.randomArts();
util.DEBUG_LOG('[SS] Fetched {0} items'.format(len(self.images)))
nextIndex = 0

if len(self.images) == 0:
title = 'No Images'
url = ''
else:
image = self.images[nextIndex]
title = image.get('title')
key = image.get('key')
url = self.selectedServer.getImageTranscodeURL(key, self.width, self.height)
if not self.quizMode:
self.setProperty('title', title)
else:
self.setProperty('title', '')
self.quizTitle = title
self.revealTitleTime = currentTime + self.timeTitleIsHidden
self.setProperty('thumb', url)

self.index = nextIndex
self.changeTime = time.time() + self.timeBetweenImages

if self.revealTitleTime != None and currentTime > self.revealTitleTime:
self.setProperty('title', self.quizTitle)
self.revealTitleTime = None

if currentTime > self.displayMoveTime:
oldDisplayPosition = self.displayPosition
self.displayPosition = (oldDisplayPosition + random.randint(1, 3)) % 4

if (oldDisplayPosition&2) != (self.displayPosition&2):
self.setProperty('align', str((self.displayPosition&2)>>1))

if (oldDisplayPosition&1) != (self.displayPosition&1):
newY = self.height - self.infoGroupControl.getY() - self.infoGroupControl.getHeight()
self.infoGroupControl.setPosition(self.infoGroupControl.getX(), newY)

self.displayMoveTime = currentTime + self.timeBetweenDisplayMove

if timestr != self.lastTime:
self.setProperty('clock', timestr)
7 changes: 7 additions & 0 deletions resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,13 @@ msgctxt "#32485"
msgid "Go back instantly with the previous menu action in scrolled views"
msgstr ""

msgctxt "#32488"
msgid "Screensaver"
msgstr ""

msgctxt "#32489"
msgid "Quiz Mode"
msgstr ""
msgctxt "#32492"
msgid "Kodi Subtitle Settings"
msgstr ""
3 changes: 3 additions & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
<category label="32467">
<setting id="fast_back" type="bool" label="32485" default="false" />
</category>
<category label="32488">
<setting id="screensaver_quiz" type="bool" label="32489" default="false" />
</category>
</settings>
63 changes: 63 additions & 0 deletions resources/skins/Main/1080i/script-plex-slideshow.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<window>
<zorder>6</zorder>
<controls>
<control type="group">
<control type="image" id="1">
<posx>0</posx>
<posy>0</posy>
<width>1920</width>
<height>1080</height>
<texture background="true"></texture>
<aspectratio>keep</aspectratio>
<fadetime>1000</fadetime>
<texture>$INFO[Window.Property(thumb)]</texture>
</control>
<control type="group" id="100">
<posx>20</posx>
<posy>20</posy>
<height>100</height>
<width>1880</width>
<control type="label" id="101">
<visible>String.IsEqual(Window.Property(align),0)</visible>
<posy>0</posy>
<height>50</height>
<font>font45</font>
<align>left</align>
<textcolor>FFFFFFFF</textcolor>
<shadowcolor>FF000000</shadowcolor>
<label>$INFO[Window.Property(clock)]</label>
</control>
<control type="label" id="105">
<visible>String.IsEqual(Window.Property(align),0)</visible>
<posy>50</posy>
<height>20</height>
<font>font16</font>
<align>left</align>
<textcolor>FFFFFFFF</textcolor>
<shadowcolor>FF000000</shadowcolor>
<label>$INFO[Window.Property(title)]</label>
</control>
<control type="label" id="111">
<visible>String.IsEqual(Window.Property(align),1)</visible>
<posy>0</posy>
<height>50</height>
<font>font45</font>
<align>right</align>
<textcolor>FFFFFFFF</textcolor>
<shadowcolor>FF000000</shadowcolor>
<label>$INFO[Window.Property(clock)]</label>
</control>
<control type="label" id="115">
<visible>String.IsEqual(Window.Property(align),1)</visible>
<posy>50</posy>
<height>20</height>
<font>font16</font>
<align>right</align>
<textcolor>FFFFFFFF</textcolor>
<shadowcolor>FF000000</shadowcolor>
<label>$INFO[Window.Property(title)]</label>
</control>
</control>
</control>
</controls>
</window>
24 changes: 24 additions & 0 deletions screensaver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import xbmc

from lib import plex, util

from lib.windows import slidehshow

class ScreensaverMonitor(xbmc.Monitor):
def __init__( self, *args, **kwargs ):
self.action = kwargs['action']

def onScreensaverDeactivated(self):
self.action()

def main():
util.DEBUG_LOG("[SS] Starting")
if plex.init():
with util.Cron(1):
ss = slidehshow.Slideshow.create()
ss.monitor = ScreensaverMonitor(action = ss.close)
ss.modal()
del ss

if __name__ == '__main__':
main()