add cached random movie list that refreshes very 5 minutes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<addon id="plugin.video.embycon"
|
||||
name="EmbyCon"
|
||||
version="1.7.4"
|
||||
version="1.7.5"
|
||||
provider-name="Team B">
|
||||
<requires>
|
||||
<import addon="xbmc.python" version="2.25.0"/>
|
||||
|
||||
@@ -426,6 +426,13 @@ class DownloadUtils():
|
||||
filter_string = getDetailsString()
|
||||
url = url.replace("{field_filters}", filter_string)
|
||||
|
||||
if url.find("{random_movies}") != -1:
|
||||
home_window = HomeWindow()
|
||||
random_movies = home_window.getProperty("random-movies")
|
||||
if not random_movies:
|
||||
return return_data
|
||||
url = url.replace("{random_movies}", random_movies)
|
||||
|
||||
log.debug("After: {0}", url)
|
||||
|
||||
try:
|
||||
|
||||
@@ -1054,31 +1054,21 @@ def showWidgets():
|
||||
"plugin://plugin.video.embycon/?mode=GET_CONTENT&use_cache=false&media_type=Movies&url=" + urllib.quote(url))
|
||||
|
||||
url = ("{server}/emby/Users/{userid}/Items" +
|
||||
"?SortBy=Random" +
|
||||
"&Limit={ItemLimit}" +
|
||||
"&CollapseBoxSetItems=false" +
|
||||
"&GroupItemsIntoCollections=false" +
|
||||
"&format=json" +
|
||||
"?Limit={ItemLimit}" +
|
||||
"&Ids={random_movies}" +
|
||||
"&Fields={field_filters}" +
|
||||
"&ImageTypeLimit=1" +
|
||||
"&IsMissing=False" +
|
||||
"&Filters=IsUnplayed,IsNotFolder" +
|
||||
"&IsPlayed=false" +
|
||||
"&Recursive=true" +
|
||||
"&SortBy=Random" +
|
||||
#"&SortOrder=Descending" +
|
||||
"&IsVirtualUnaired=false" +
|
||||
"&IsMissing=False" +
|
||||
"&IncludeItemTypes=Movie")
|
||||
"&ImageTypeLimit=1")
|
||||
addMenuDirectoryItem(string_load(30269) + " (" + show_x_filtered_items + ")",
|
||||
"plugin://plugin.video.embycon/?mode=GET_CONTENT&use_cache=false&media_type=Movies&url=" + urllib.quote(url))
|
||||
|
||||
addMenuDirectoryItem(string_load(30257) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=recent_movies')
|
||||
addMenuDirectoryItem(string_load(30258) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=inprogress_movies')
|
||||
addMenuDirectoryItem(string_load(30287) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=recent_tvshows')
|
||||
addMenuDirectoryItem(string_load(30263) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=recent_episodes')
|
||||
addMenuDirectoryItem(string_load(30264) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=inprogress_episodes')
|
||||
addMenuDirectoryItem(string_load(30265) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=nextup_episodes')
|
||||
addMenuDirectoryItem(" - " + string_load(30257) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=recent_movies')
|
||||
addMenuDirectoryItem(" - " + string_load(30258) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=inprogress_movies')
|
||||
addMenuDirectoryItem(" - " + string_load(30269) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=random_movies')
|
||||
|
||||
addMenuDirectoryItem(" - " + string_load(30287) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=recent_tvshows')
|
||||
addMenuDirectoryItem(" - " + string_load(30263) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=recent_episodes')
|
||||
addMenuDirectoryItem(" - " + string_load(30264) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=inprogress_episodes')
|
||||
addMenuDirectoryItem(" - " + string_load(30265) + " (" + show_x_filtered_items + ")", 'plugin://plugin.video.embycon/?mode=WIDGET_CONTENT&type=nextup_episodes')
|
||||
|
||||
xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
||||
|
||||
@@ -1094,12 +1084,12 @@ def show_search():
|
||||
xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
||||
|
||||
|
||||
def set_library_window_values():
|
||||
log.debug("set_library_window_values called")
|
||||
def set_library_window_values(force=False):
|
||||
log.debug("set_library_window_values Called forced={0}", force)
|
||||
home_window = HomeWindow()
|
||||
|
||||
already_set = home_window.getProperty("view_item.0.name")
|
||||
if already_set:
|
||||
if not force and already_set:
|
||||
return
|
||||
|
||||
for index in range(0, 20):
|
||||
|
||||
@@ -6,6 +6,7 @@ import json
|
||||
import urllib
|
||||
import hashlib
|
||||
import time
|
||||
import random
|
||||
|
||||
from downloadutils import DownloadUtils
|
||||
from utils import getArt
|
||||
@@ -22,12 +23,49 @@ background_items = []
|
||||
background_current_item = 0
|
||||
|
||||
|
||||
def set_background_image():
|
||||
log.debug("set_background_image Called")
|
||||
def set_random_movies():
|
||||
log.debug("set_random_movies Called")
|
||||
|
||||
url = ('{server}/emby/Users/{userid}/Items' +
|
||||
'?Recursive=true' +
|
||||
'&limit=20' +
|
||||
'&Filters=IsUnplayed' +
|
||||
'&IsPlayed=false' +
|
||||
'&SortBy=Random' +
|
||||
'&IncludeItemTypes=Movie' +
|
||||
'&ImageTypeLimit=0')
|
||||
results = downloadUtils.downloadUrl(url, suppress=True)
|
||||
results = json.loads(results)
|
||||
|
||||
randon_movies_list = []
|
||||
if results is not None:
|
||||
items = results.get("Items", [])
|
||||
for item in items:
|
||||
randon_movies_list.append(item.get("Id"))
|
||||
|
||||
random.shuffle(randon_movies_list)
|
||||
movies_list_string = ",".join(randon_movies_list)
|
||||
home_window = HomeWindow()
|
||||
m = hashlib.md5()
|
||||
m.update(movies_list_string)
|
||||
new_widget_hash = m.hexdigest()
|
||||
|
||||
log.debug("set_random_movies : {0}", movies_list_string)
|
||||
log.debug("set_random_movies : {0}", new_widget_hash)
|
||||
home_window.setProperty("random-movies", movies_list_string)
|
||||
home_window.setProperty("random-movies-changed", new_widget_hash)
|
||||
|
||||
|
||||
def set_background_image(force=False):
|
||||
log.debug("set_background_image Called forced={0}", force)
|
||||
|
||||
global background_current_item
|
||||
global background_items
|
||||
|
||||
if force:
|
||||
background_current_item = 0
|
||||
background_items = []
|
||||
|
||||
if len(background_items) == 0 or background_current_item >= len(background_items):
|
||||
log.debug("set_background_image: Need to load more backgrounds {0} - {1}",
|
||||
len(background_items), background_current_item)
|
||||
@@ -233,6 +271,9 @@ def populateWidgetItems(items_url, widget_type, override_select_action=None):
|
||||
result = data_manager.GetContent(items_url)
|
||||
log.debug("WIDGET_DATA: {0}", result)
|
||||
|
||||
if result is None:
|
||||
return []
|
||||
|
||||
simmilar_to = None
|
||||
if result is not None and isinstance(result, dict) and result.get("Items") is not None:
|
||||
simmilar_to = result.get("BaselineItemName", None)
|
||||
@@ -388,14 +429,7 @@ def getWidgetContent(handle, params):
|
||||
|
||||
elif widget_type == "random_movies":
|
||||
xbmcplugin.setContent(handle, 'movies')
|
||||
items_url += ("&Filters=IsUnplayed,IsNotFolder" +
|
||||
"&IsPlayed=false" +
|
||||
"&Recursive=true" +
|
||||
"&SortBy=Random" +
|
||||
"&SortOrder=Descending" +
|
||||
"&IsVirtualUnaired=false" +
|
||||
"&IsMissing=False" +
|
||||
"&IncludeItemTypes=Movie")
|
||||
items_url += "&Ids={random_movies}"
|
||||
|
||||
elif widget_type == "recent_tvshows":
|
||||
xbmcplugin.setContent(handle, 'episodes')
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
<param name="list_id" value="3900"/>
|
||||
</include>
|
||||
<include content="WidgetListPoster" condition="true">
|
||||
<param name="content_path" value="plugin://plugin.video.embycon?mode=WIDGET_CONTENT&type=random_movies&reload=$INFO[Window(Home).Property(plugin.video.embycon-embycon_widget_reload)]"/>
|
||||
<param name="content_path" value="plugin://plugin.video.embycon?mode=WIDGET_CONTENT&type=random_movies&reload=$INFO[Window(Home).Property(plugin.video.embycon-random-movies-changed)]"/>
|
||||
<param name="widget_header" value="Random"/>
|
||||
<param name="widget_target" value="videos"/>
|
||||
<param name="list_id" value="3100"/>
|
||||
|
||||
@@ -195,7 +195,7 @@
|
||||
<control type="panel" id="$PARAM[list_id]">
|
||||
<left>0</left>
|
||||
<top>115</top>
|
||||
<visible>Integer.IsGreater(Container($PARAM[list_id]).NumItems,0) | Container($PARAM[list_id]).IsUpdating</visible>
|
||||
<visible allowhiddenfocus="true">Integer.IsGreater(Container($PARAM[list_id]).NumItems,0) | Container($PARAM[list_id]).IsUpdating</visible>
|
||||
<right>0</right>
|
||||
<height>500</height>
|
||||
<include content="WidgetListCommon">
|
||||
@@ -313,8 +313,8 @@
|
||||
<include content="WidgetListCommon">
|
||||
<param name="list_id" value="$PARAM[list_id]"/>
|
||||
</include>
|
||||
<visible>$PARAM[visible]</visible>
|
||||
<visible>Integer.IsGreater(Container($PARAM[list_id]).NumItems,0) | Container($PARAM[list_id]).IsUpdating</visible>
|
||||
<visible allowhiddenfocus="true">$PARAM[visible]</visible>
|
||||
<visible allowhiddenfocus="true">Integer.IsGreater(Container($PARAM[list_id]).NumItems,0) | Container($PARAM[list_id]).IsUpdating</visible>
|
||||
<itemlayout width="310" height="500">
|
||||
<control type="group">
|
||||
<left>70</left>
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
<param name="list_id" value="3900"/>
|
||||
</include>
|
||||
<include content="WidgetListPoster" condition="true">
|
||||
<param name="content_path" value="plugin://plugin.video.embycon?mode=WIDGET_CONTENT&type=random_movies&reload=$INFO[Window(Home).Property(plugin.video.embycon-embycon_widget_reload)]"/>
|
||||
<param name="content_path" value="plugin://plugin.video.embycon?mode=WIDGET_CONTENT&type=random_movies&reload=$INFO[Window(Home).Property(plugin.video.embycon-random-movies-changed)]"/>
|
||||
<param name="widget_header" value="Random"/>
|
||||
<param name="widget_target" value="videos"/>
|
||||
<param name="list_id" value="3100"/>
|
||||
|
||||
@@ -195,7 +195,7 @@
|
||||
<control type="panel" id="$PARAM[list_id]">
|
||||
<left>0</left>
|
||||
<top>115</top>
|
||||
<visible>Integer.IsGreater(Container($PARAM[list_id]).NumItems,0) | Container($PARAM[list_id]).IsUpdating</visible>
|
||||
<visible allowhiddenfocus="true">Integer.IsGreater(Container($PARAM[list_id]).NumItems,0) | Container($PARAM[list_id]).IsUpdating</visible>
|
||||
<right>0</right>
|
||||
<height>503</height>
|
||||
<include content="WidgetListCommon">
|
||||
@@ -326,8 +326,8 @@
|
||||
<include content="WidgetListCommon">
|
||||
<param name="list_id" value="$PARAM[list_id]"/>
|
||||
</include>
|
||||
<visible>$PARAM[visible]</visible>
|
||||
<visible>Integer.IsGreater(Container($PARAM[list_id]).NumItems,0) | Container($PARAM[list_id]).IsUpdating</visible>
|
||||
<visible allowhiddenfocus="true">$PARAM[visible]</visible>
|
||||
<visible allowhiddenfocus="true">Integer.IsGreater(Container($PARAM[list_id]).NumItems,0) | Container($PARAM[list_id]).IsUpdating</visible>
|
||||
<itemlayout width="310" height="500">
|
||||
<control type="group">
|
||||
<left>70</left>
|
||||
|
||||
25
service.py
25
service.py
@@ -15,7 +15,7 @@ from resources.lib.downloadutils import DownloadUtils
|
||||
from resources.lib.simple_logging import SimpleLogging
|
||||
from resources.lib.play_utils import Service, PlaybackService, sendProgress
|
||||
from resources.lib.kodi_utils import HomeWindow
|
||||
from resources.lib.widgets import checkForNewContent, set_background_image
|
||||
from resources.lib.widgets import checkForNewContent, set_background_image, set_random_movies
|
||||
from resources.lib.websocket_client import WebSocketClient
|
||||
from resources.lib.menu_functions import set_library_window_values
|
||||
from resources.lib.context_monitor import ContextMonitor
|
||||
@@ -44,6 +44,7 @@ home_window = HomeWindow()
|
||||
last_progress_update = time.time()
|
||||
last_content_check = time.time()
|
||||
last_background_update = 0
|
||||
last_random_movie_update = 0
|
||||
websocket_client = WebSocketClient()
|
||||
|
||||
# session id
|
||||
@@ -67,6 +68,7 @@ if context_menu:
|
||||
|
||||
background_interval = int(settings.getSetting('background_interval'))
|
||||
newcontent_interval = int(settings.getSetting('newcontent_interval'))
|
||||
random_movie_list_interval = 300
|
||||
|
||||
# monitor.abortRequested() is causes issues, it currently triggers for all addon cancelations which causes
|
||||
# the service to exit when a user cancels an addon load action. This is a bug in Kodi.
|
||||
@@ -83,17 +85,26 @@ while not xbmc.abortRequested:
|
||||
sendProgress(monitor)
|
||||
|
||||
else:
|
||||
if newcontent_interval != 0 and (time.time() - last_content_check) > newcontent_interval:
|
||||
user_changed = False
|
||||
if prev_user_id != home_window.getProperty("userid"):
|
||||
log.debug("user_change_detected")
|
||||
prev_user_id = home_window.getProperty("userid")
|
||||
user_changed = True
|
||||
|
||||
if random_movie_list_interval != 0 and user_changed or (time.time() - last_random_movie_update) > random_movie_list_interval:
|
||||
last_random_movie_update = time.time()
|
||||
set_random_movies()
|
||||
|
||||
if newcontent_interval != 0 and user_changed or (time.time() - last_content_check) > newcontent_interval:
|
||||
last_content_check = time.time()
|
||||
checkForNewContent()
|
||||
|
||||
if background_interval != 0 and (time.time() - last_background_update) > background_interval:
|
||||
if background_interval != 0 and user_changed or (time.time() - last_background_update) > background_interval:
|
||||
last_background_update = time.time()
|
||||
set_library_window_values()
|
||||
set_background_image()
|
||||
set_library_window_values(user_changed)
|
||||
set_background_image(user_changed)
|
||||
|
||||
if remote_control and prev_user_id != home_window.getProperty("userid"):
|
||||
prev_user_id = home_window.getProperty("userid")
|
||||
if remote_control and user_changed:
|
||||
websocket_client.stop_client()
|
||||
websocket_client = WebSocketClient()
|
||||
websocket_client.start()
|
||||
|
||||
Reference in New Issue
Block a user