From 6fda96e3668edf1ce69f0b5e46dd4599dc2fcc5b Mon Sep 17 00:00:00 2001 From: Alhaziel Date: Sat, 11 Jan 2020 18:47:29 +0100 Subject: [PATCH] Episodio Successivo (Nuovo Metodo) --- platformcode/launcher.py | 98 +++++++++++-------- platformcode/platformtools.py | 4 - resources/settings.xml | 2 +- specials/nextep.py | 179 ++++++++++++++++++---------------- specials/videolibrary.py | 6 +- 5 files changed, 158 insertions(+), 131 deletions(-) diff --git a/platformcode/launcher.py b/platformcode/launcher.py index 4612c013..ac5725b1 100644 --- a/platformcode/launcher.py +++ b/platformcode/launcher.py @@ -448,6 +448,7 @@ def play_from_library(item): import xbmcplugin import xbmc from time import sleep, time + from specials import nextep # Intentamos reproducir una imagen (esto no hace nada y ademas no da error) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, @@ -460,8 +461,10 @@ def play_from_library(item): # modificamos el action (actualmente la videoteca necesita "findvideos" ya que es donde se buscan las fuentes item.action = "findvideos" + check_next_ep = nextep.check(item) - window_type = config.get_setting("window_type", "videolibrary") + + window_type = 1 if check_next_ep else config.get_setting("window_type", "videolibrary") # y volvemos a lanzar kodi if xbmc.getCondVisibility('Window.IsMedia') and not window_type == 1: @@ -472,60 +475,69 @@ def play_from_library(item): # Ventana emergente item.play_from = 'window' - from specials import videolibrary + + from specials import videolibrary, autoplay p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(70004)) p_dialog.update(0, '') itemlist = videolibrary.findvideos(item) + if check_next_ep and autoplay.is_active(item.contentChannel): + p_dialog.update(100, '') + sleep(0.5) + p_dialog.close() + item = nextep.return_item(item) + if item.next_ep: + return play_from_library(item) + it = item + logger.info('STOP:\n'+str(item)) - while platformtools.is_playing(): - # Ventana convencional - sleep(5) - p_dialog.update(50, '') + else: + while platformtools.is_playing(): + # Ventana convencional + sleep(5) + p_dialog.update(50, '') - '''# Se filtran los enlaces segun la lista negra - if config.get_setting('filter_servers', "servers"): - itemlist = servertools.filter_servers(itemlist)''' + if item.show_server or not check_next_ep: - # Se limita la cantidad de enlaces a mostrar - if config.get_setting("max_links", "videolibrary") != 0: - itemlist = limit_itemlist(itemlist) + '''# Se filtran los enlaces segun la lista negra + if config.get_setting('filter_servers', "servers"): + itemlist = servertools.filter_servers(itemlist)''' - # Se "limpia" ligeramente la lista de enlaces - if config.get_setting("replace_VD", "videolibrary") == 1: - itemlist = reorder_itemlist(itemlist) + # Se limita la cantidad de enlaces a mostrar + if config.get_setting("max_links", "videolibrary") != 0: + itemlist = limit_itemlist(itemlist) + + # Se "limpia" ligeramente la lista de enlaces + if config.get_setting("replace_VD", "videolibrary") == 1: + itemlist = reorder_itemlist(itemlist) - p_dialog.update(100, '') - sleep(0.5) - p_dialog.close() + p_dialog.update(100, '') + sleep(0.5) + p_dialog.close() - if len(itemlist) > 0: - while not xbmc.Monitor().abortRequested(): - # El usuario elige el mirror - opciones = [] - for item in itemlist: - opciones.append(item.title) + if len(itemlist) > 0: + while not xbmc.Monitor().abortRequested(): + # El usuario elige el mirror + opciones = [] + for item in itemlist: + opciones.append(item.title) - # Se abre la ventana de seleccion - if (item.contentSerieName != "" and - item.contentSeason != "" and - item.contentEpisodeNumber != ""): - cabecera = ("%s - %sx%s -- %s" % - (item.contentSerieName, - item.contentSeason, - item.contentEpisodeNumber, - config.get_localized_string(30163))) - else: - cabecera = config.get_localized_string(30163) + # Se abre la ventana de seleccion + if (item.contentSerieName != "" and + item.contentSeason != "" and + item.contentEpisodeNumber != ""): + cabecera = ("%s - %sx%s -- %s" % + (item.contentSerieName, + item.contentSeason, + item.contentEpisodeNumber, + config.get_localized_string(30163))) + else: + cabecera = config.get_localized_string(30163) - SHOW = True - if config.get_setting('autoplay') and config.get_setting('hide_servers'): - SHOW = False - if SHOW: seleccion = platformtools.dialog_select(cabecera, opciones) if seleccion == -1: @@ -534,8 +546,10 @@ def play_from_library(item): item = videolibrary.play(itemlist[seleccion])[0] platformtools.play_video(item) - from specials import autoplay - if (platformtools.is_playing() and item.action) or item.server == 'torrent' or autoplay.is_active(item.contentChannel): - break + if (platformtools.is_playing() and item.action) or item.server == 'torrent' or autoplay.is_active(item.contentChannel): + break + if it.show_server and check_next_ep: + logger.info('PARTITO') + nextep.run(it) diff --git a/platformcode/platformtools.py b/platformcode/platformtools.py index a0adb2fe..d1636478 100644 --- a/platformcode/platformtools.py +++ b/platformcode/platformtools.py @@ -1140,10 +1140,6 @@ def set_player(item, xlistitem, mediaurl, view, strm): from platformcode import xbmc_videolibrary xbmc_videolibrary.mark_auto_as_watched(item) - if (strm or item.strm_path) and config.get_setting('next_ep') > 0 and item.contentType != 'movie' and item.play_from != 'window': - from specials.nextep import afther_stop - afther_stop(item) - def torrent_client_installed(show_tuple=False): # Plugins externos se encuentra en servers/torrent.json nodo clients diff --git a/resources/settings.xml b/resources/settings.xml index 5f280348..2a2adbbc 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -59,7 +59,7 @@ - + diff --git a/specials/nextep.py b/specials/nextep.py index e59ae683..1972d86f 100644 --- a/specials/nextep.py +++ b/specials/nextep.py @@ -1,30 +1,73 @@ # -*- coding: utf-8 -*- -import xbmc, os, urlparse +import xbmc, xbmcgui, os from platformcode import config, platformtools, logger from time import time, sleep from core import scrapertools from core import jsontools, filetools -import threading +from lib.concurrent import futures + +PLAYER_STOP = 13 + +def check(item): + return True if config.get_setting('next_ep') > 0 and item.contentType != 'movie' else False -def afther_stop(item): +def return_item(item): logger.info('AS ITEM\n'+str(item)) - def next_ep(item): - logger.info() - condition = config.get_setting('next_ep') - # from core.support import dbg; dbg() + with futures.ThreadPoolExecutor() as executor: + future = executor.submit(next_ep, item) + item = future.result() + return item - if condition == 1: # Hide servers afther stop video - while not platformtools.is_playing(): - pass - while platformtools.is_playing(): - pass - sleep(0.5) - xbmc.executebuiltin('Action(Back)') +def run(item): + logger.info('AS ITEM\n'+str(item)) + with futures.ThreadPoolExecutor() as executor: + future = executor.submit(next_ep, item) + item = future.result() + if item.next_ep: + from platformcode.launcher import play_from_library + return play_from_library(item) - elif condition == 2: # Bring servers afther stop video - from platformcode.launcher import play_from_library - # Check if next episode exist + +def videolibrary(item): + from threading import Thread + item.videolibrary = True + Thread(target=next_ep, args=[item]).start() + + +def next_ep(item): + logger.info() + condition = config.get_setting('next_ep') + item.next_ep = False + item.show_server = True + + VL = True if item.videolibrary else False + + time_over = False + time_limit = time() + 30 + time_steps = [20,30,40,50,60] + TimeFromEnd = time_steps[config.get_setting('next_ep_seconds')] + + # wait until the video plays + while not platformtools.is_playing() and time() < time_limit: + sleep(1) + + while platformtools.is_playing() and time_over == False: + try: + Total = xbmc.Player().getTotalTime() + Actual = xbmc.Player().getTime() + Difference = Total - Actual + if Total > TimeFromEnd >= Difference: + time_over = True + except: + break + + if time_over: + if condition == 1: # hide server afther x second + item.show_server = False + elif condition == 2: # play next fileif exist + + # check i next file exist current_filename = os.path.basename(item.strm_path) base_path = os.path.basename(os.path.normpath(os.path.dirname(item.strm_path))) logger.info('PATH:' + base_path) @@ -34,7 +77,7 @@ def afther_stop(item): for file in os.listdir(path): if file.endswith('.strm'): fileList.append(file) - # from core.support import dbg; dbg() + nextIndex = fileList.index(current_filename) + 1 if nextIndex == 0 or nextIndex == len(fileList): next_file = None @@ -43,82 +86,52 @@ def afther_stop(item): # start next episode window afther x time if next_file: - play_next = False - time_limit = time() + 30 - time_steps = [20,30,40,50,60] - TimeFromEnd = time_steps[config.get_setting('next_ep_seconds')] - logger.info('TEMPO: '+str(TimeFromEnd)) - while not platformtools.is_playing() and time() < time_limit: - sleep(1) + from core.item import Item + season_ep = next_file.split('.')[0] + season = season_ep.split('x')[0] + episode = season_ep.split('x')[1] + next_ep = '%sx%s' % (season, episode) + item = Item( + action= 'play_from_library', + channel= 'videolibrary', + contentEpisodeNumber= episode, + contentSeason= season, + contentTitle= next_ep, + contentType= 'tvshow', + infoLabels= {'episode': episode, 'mediatype': 'tvshow', 'season': season, 'title': next_ep}, + strm_path= filetools.join(base_path, next_file)) - sleep(1) + global ITEM + ITEM = item - while platformtools.is_playing() and play_next == False: - try: - Total = xbmc.Player().getTotalTime() - Actual = xbmc.Player().getTime() - Difference = Total - Actual - if Total > TimeFromEnd >= Difference: - play_next = True - except: - break + nextDialog = NextDialog('NextDialog.xml', config.get_runtime_path()) + nextDialog.show() + while platformtools.is_playing() and not nextDialog.is_still_watching(): + xbmc.sleep(100) + pass - # from core.support import dbg; dbg() - if play_next: - from core.item import Item - play_next = False - season_ep = next_file.split('.')[0] - season = season_ep.split('x')[0] - episode = season_ep.split('x')[1] - next_ep = '%sx%s' % (season, episode) - item = Item( - action= 'play_from_library', - channel= 'videolibrary', - contentEpisodeNumber= episode, - contentSeason= season, - contentTitle= next_ep, - contentType= 'tvshow', - infoLabels= {'episode': episode, 'mediatype': 'tvshow', 'season': season, 'title': next_ep}, - strm_path= filetools.join(base_path, next_file)) - - # item.contentSeason = item.infoLabels['season'] = season - # item.contentEpisodeNumber = item.infoLabels['episode'] = episode - # item.contentTitle = item.infoLabels['title'] = next_ep - # item.strm_path = filetools.join(base_path, next_file) - # logger.info('ITEM SUBMITTED:\n'+str(item)) + nextDialog.close() + logger.info('CONTINUE: ' +str(nextDialog.stillwatching)) - global ITEM - ITEM = item - nextDialog = NextDialog('NextDialog.xml', config.get_runtime_path()) - nextDialog.show() - while platformtools.is_playing() and not nextDialog.is_still_watching(): - xbmc.sleep(100) - pass - - nextDialog.close() - logger.info('CONTINUA: ' +str(nextDialog.stillwatching)) - - if nextDialog.stillwatching or nextDialog.continuewatching: - xbmc.Player().stop() - sleep(1) + if nextDialog.stillwatching or nextDialog.continuewatching: + item.next_ep = True + xbmc.Player().stop() + if VL: logger.info('BACK STILL') + sleep(1) xbmc.executebuiltin('Action(Back)') sleep(0.5) + from platformcode.launcher import play_from_library return play_from_library(item) - else: + else: + item.show_server = False + if VL: sleep(1) - logger.info('BACK NOT STILL') xbmc.executebuiltin('Action(Back)') + sleep(0.5) + return None - else: - return None - - thread = threading.Thread(target = next_ep, args = [item]) - thread.start() - -import xbmcgui - -PLAYER_STOP = 13 + return item class NextDialog(xbmcgui.WindowXMLDialog): diff --git a/specials/videolibrary.py b/specials/videolibrary.py index e6f9b937..4f4f3c88 100644 --- a/specials/videolibrary.py +++ b/specials/videolibrary.py @@ -577,7 +577,11 @@ def findvideos(item): # return sorted(itemlist, key=lambda it: it.title.lower()) autoplay.play_multi_channel(item, itemlist) - + from inspect import stack + from specials import nextep + logger.info('STACK= ' + stack()[1][3]) + if nextep.check(item) and stack()[1][3] == 'run': + nextep.videolibrary(item) return itemlist