test salvataggio viewmode in realtime

This commit is contained in:
marco
2020-04-22 17:59:25 +02:00
parent 5d1d48b2d2
commit 6eaaa46779
2 changed files with 74 additions and 43 deletions

View File

@@ -135,12 +135,15 @@ def dialog_browse(_type, heading, default=""):
def itemlist_refresh():
pos = Item().fromurl(xbmc.getInfoLabel('ListItem.FileNameAndPath')).pos + 1
pos = Item().fromurl(xbmc.getInfoLabel('ListItem.FileNameAndPath')).itemlistPosition
logger.info('Current position: ' + str(pos))
xbmc.executebuiltin("Container.Refresh")
win = xbmcgui.Window(xbmcgui.getCurrentWindowId())
cid = win.getFocusId()
ctl = win.getControl(cid)
ctl.selectItem(pos)
while Item().fromurl(xbmc.getInfoLabel('ListItem.FileNameAndPath')).itemlistPosition != pos:
win = xbmcgui.Window(xbmcgui.getCurrentWindowId())
cid = win.getFocusId()
ctl = win.getControl(cid)
ctl.selectItem(pos)
def itemlist_update(item, replace=False):
@@ -178,7 +181,7 @@ def render_items(itemlist, parent_item):
dirItems = []
for n, item in enumerate(itemlist):
item.pos = n
item.itemlistPosition = n + 1
item_url = item.tourl()
if item.category == "":
@@ -239,54 +242,60 @@ def render_items(itemlist, parent_item):
logger.info('END render_items')
def set_view_mode(item, parent_item):
def mode(content, Type):
mode = int(config.get_setting('view_mode_%s' % content).split(',')[-1])
if mode == 0:
logger.info('default mode')
mode = 55
elif not Type:
Type = 'addons'
xbmcplugin.setContent(handle=int(sys.argv[1]), content=Type)
xbmc.executebuiltin('Container.SetViewMode(%s)' % mode)
logger.info('TYPE: ' + Type + ' - ' + 'CONTENT: ' + content)
def getCurrentView(item=None, parent_item=None):
if not parent_item:
parent_item = Item().fromurl(xbmc.getInfoLabel('Container.FolderPath'))
if not item:
item = Item().fromurl(xbmc.getInfoLabel('Container.ListItem(1).FileNameAndPath'))
parent_actions = ['peliculas', 'novedades', 'search', 'get_from_temp', 'channel_search', 'newest', 'discover_list', 'new_search']
if parent_item.action == 'findvideos':
return 'server', ''
elif parent_item.action == 'mainlist':
return 'channel', ''
elif (item.contentType in ['movie'] and parent_item.action in parent_actions) \
or (item.channel in ['videolibrary'] and parent_item.action in ['list_movies']) \
or (parent_item.channel in ['favorites'] and parent_item.action in ['mainlist']) \
or parent_item.action in ['now_on_tv', 'now_on_misc', 'now_on_misc_film', 'mostrar_perfil']:
return 'movie', 'movies'
elif (item.contentType in ['tvshow'] and parent_item.action in parent_actions) \
or (item.channel in ['videolibrary'] and parent_item.action in ['list_tvshows']):
return 'tvshow', 'tvshows'
elif parent_item.action in ['get_seasons']:
return 'season', 'tvshows'
elif parent_item.action in ['episodios', 'get_episodes'] or item.contentType == 'episode':
return 'episode', 'tvshows'
else:
return 'addon', ''
def set_view_mode(item, parent_item):
def reset_view_mode():
for mode in ['addon','channel','movie','tvshow','season','episode','server']:
config.set_setting('skin_name', xbmc.getSkinDir())
config.set_setting('view_mode_%s' % mode, config.get_localized_string(70003) + ' , 0')
parent_actions = ['peliculas', 'novedades', 'search', 'get_from_temp', 'channel_search', 'newest', 'discover_list', 'new_search']
if xbmc.getSkinDir() != config.get_setting('skin_name') or not config.get_setting('skin_name'):
reset_view_mode()
xbmcplugin.setContent(handle=int(sys.argv[1]), content='')
xbmc.executebuiltin('Container.SetViewMode(%s)' % 55)
elif parent_item.action == 'findvideos':
mode('server', '')
elif parent_item.action == 'mainlist':
mode('channel', '')
elif (item.contentType in ['movie'] and parent_item.action in parent_actions ) \
or (item.channel in ['videolibrary'] and parent_item.action in ['list_movies']) \
or (parent_item.channel in ['favorites'] and parent_item.action in ['mainlist']) \
or parent_item.action in ['now_on_tv', 'now_on_misc', 'now_on_misc_film', 'mostrar_perfil']:
mode('movie', 'movies')
elif (item.contentType in ['tvshow'] and parent_item.action in parent_actions ) \
or (item.channel in ['videolibrary'] and parent_item.action in ['list_tvshows']):
mode('tvshow', 'tvshows')
elif parent_item.action in ['get_seasons']:
mode('season', 'tvshows')
elif parent_item.action in ['episodios', 'get_episodes'] or item.contentType == 'episode':
mode('episode', 'tvshows')
else:
mode('addon', '')
content, Type = getCurrentView(item, parent_item)
mode = int(config.get_setting('view_mode_%s' % content).split(',')[-1])
if mode == 0:
logger.info('default mode')
mode = 55
elif not Type:
Type = 'addons'
xbmcplugin.setContent(handle=int(sys.argv[1]), content=Type)
xbmc.executebuiltin('Container.SetViewMode(%s)' % mode)
logger.info('TYPE: ' + Type + ' - ' + 'CONTENT: ' + content)
def render_items_old(itemlist, parent_item):

View File

@@ -376,6 +376,25 @@ def callCloudflare():
httptools.downloadpage(url)
def viewmodeMonitor():
import xbmcgui
while True:
time.sleep(0.5)
try:
currentModeName = xbmc.getInfoLabel('Container.Viewmode')
win = xbmcgui.Window(xbmcgui.getCurrentWindowId())
currentMode = int(win.getFocusId())
if currentModeName and 'plugin.video.kod' in xbmc.getInfoLabel('Container.FolderPath') and currentMode < 1000 and currentMode > 50: # inside addon and in itemlist view
content, Type = platformtools.getCurrentView()
defaultMode = int(config.get_setting('view_mode_%s' % content).split(',')[-1])
if currentMode != defaultMode:
logger.info('viewmode changed: ' + currentModeName + '-' + str(currentMode) + ' - content: ' + content)
config.set_setting('view_mode_%s' % content, currentModeName + ', ' + str(currentMode))
except:
logger.error(traceback.print_exc())
if __name__ == "__main__":
# threading.Thread(target=callCloudflare())
# Se ejecuta en cada inicio
@@ -412,6 +431,8 @@ if __name__ == "__main__":
# Copia Custom code a las carpetas de Alfa desde la zona de Userdata
from platformcode import custom_code
custom_code.init()
from threading import Thread
Thread(target=viewmodeMonitor).start()
if not config.get_setting("update", "videolibrary") == 2:
check_for_update(overwrite=False)
@@ -432,3 +453,4 @@ if __name__ == "__main__":
while not xbmc.abortRequested:
monitor_update()
xbmc.sleep(3600)