Downloader: sistemata finestra selezione, fix riproduzione da sezione videoteca e ottimizzazione

This commit is contained in:
marco
2023-04-11 20:51:58 +02:00
parent 6e5bfecd6a
commit ae162428ce
4 changed files with 31 additions and 24 deletions

View File

@@ -18,6 +18,8 @@ metodos:
"""
from __future__ import division
import xbmc
from future import standard_library
from core.item import Item
@@ -108,7 +110,7 @@ class Downloader(object):
try:
self.start()
while self.state == self.states.downloading:
time.sleep(0.2)
xbmc.sleep(200)
line1 = "%s" % (self.filename)
line2 = config.get_localized_string(59983) % ( self.downloaded[1], self.downloaded[2], self.size[1], self.size[2], self.speed[1], self.speed[2], self.connections[0], self.connections[1])
line3 = config.get_localized_string(60202) % (self.remaining_time)
@@ -173,7 +175,7 @@ class Downloader(object):
downloaded2 = self._start_downloaded
t = time.time()
t2 = time.time()
time.sleep(1)
xbmc.sleep(1000)
while self.state == self.states.downloading:
self._average_speed = old_div((self.downloaded[0] - self._start_downloaded), (time.time() - self._start_time))
@@ -182,11 +184,10 @@ class Downloader(object):
if time.time() - t > 5:
t = t2
downloaded = downloaded2
t2 = time.time()
downloaded2 = self.downloaded[0]
time.sleep(0.5)
xbmc.sleep(500)
# Internal functions
def __init__(self, url, path, filename=None, headers=[], resume=True, max_connections=10, block_size=2 ** 17,
@@ -413,6 +414,7 @@ class Downloader(object):
logger.info("Thread started: %s" % threading.current_thread().name)
while self._state == self.states.downloading:
xbmc.sleep(100)
if not self.pending_parts and not self.download_parts and not self.save_parts: # Download finished
self._state = self.states.completed
self.file.close()
@@ -483,7 +485,7 @@ class Downloader(object):
self.download_parts.remove(id)
self.save_parts.add(id)
while self._state == self.states.downloading and len(self._buffer) > self._max_connections + self._max_buffer:
time.sleep(0.1)
xbmc.sleep(100)
def __set_part_stopped__(self, id):
if self._download_info["parts"][id]["status"] == self.states.downloading:
@@ -512,7 +514,7 @@ class Downloader(object):
connection = self.__open_connection__(self._download_info["parts"][id]["current"], self._download_info["parts"][id]["end"])
except:
self.__set_part__error__(id)
time.sleep(5)
xbmc.sleep(5000)
continue
self.__set_part__downloading__(id)

View File

@@ -312,7 +312,7 @@ def findvideos(item, itemlist=[]):
p_dialog.update(100)
p_dialog.close()
serverlist = [s for s in itemlist if s.server]
serverlist = [s for s in itemlist if s.server or s.contentChannel == 'local']
if itemlist and not serverlist:
platformtools.render_items(itemlist, item)

View File

@@ -1810,7 +1810,7 @@ def channelImport(channelId):
channel = None
return channel
def serverWindow(item, itemlist):
def serverWindow(item, itemlist, runDirectly=True):
from core import db
LEFT = 1
RIGHT = 2
@@ -2027,6 +2027,8 @@ def serverWindow(item, itemlist):
selection = ServerSkinWindow("DialogSelect.xml", config.get_runtime_path()).start(item, itemlist)
else:
selection = ServerWindow('Servers.xml', config.get_runtime_path()).start(item, itemlist)
if selection != -1:
if selection != -1 and runDirectly:
from platformcode.launcher import run
run(selection)
else:
return selection

View File

@@ -805,15 +805,17 @@ def select_server(item):
seleccion = 1
else:
# otherwise it shows the selection window
seleccion = platformtools.dialog_select(config.get_localized_string(70192), ["Auto"] + [s.title for s in play_items])
seleccion = platformtools.serverWindow(item, [Item(title='Auto', thumbnail=get_thumb('downloads.png'), action='auto')] + play_items, False)
# seleccion = platformtools.dialog_select(config.get_localized_string(70192), ["Auto"] + [s.serverName for s in play_items])
if seleccion >= 1:
update_json(item.path, {
"downloadServer": {"url": play_items[seleccion - 1].url, "server": play_items[seleccion - 1].server}})
return play_items[seleccion - 1]
elif seleccion == 0:
update_json(item.path, {"downloadServer": {}})
return 'Auto'
if seleccion != -1: # not canceled
if seleccion.action != 'auto':
update_json(item.path, {
"downloadServer": {"url": seleccion.url, "server": seleccion.server}})
return seleccion
else:
update_json(item.path, {"downloadServer": {}})
return 'Auto'
# platformtools.itemlist_refresh()
@@ -1067,13 +1069,14 @@ def save_download_movie(item):
else:
# from core.support import dbg;dbg()
play_item = select_server(item)
if type(play_item) == str and play_item == 'Auto':
start_download(item)
else:
play_item = item.clone(**play_item.__dict__)
play_item.contentAction = play_item.action
play_item.infoLabels = item.infoLabels
start_download(play_item)
if play_item:
if type(play_item) == str and play_item == 'Auto':
start_download(item)
else:
play_item = item.clone(**play_item.__dict__)
play_item.contentAction = play_item.action
play_item.infoLabels = item.infoLabels
start_download(play_item)
def save_download_tvshow(item):