Downloader: sistemata finestra selezione, fix riproduzione da sezione videoteca e ottimizzazione
This commit is contained in:
+8
-6
@@ -18,6 +18,8 @@ metodos:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
|
|
||||||
|
import xbmc
|
||||||
from future import standard_library
|
from future import standard_library
|
||||||
|
|
||||||
from core.item import Item
|
from core.item import Item
|
||||||
@@ -108,7 +110,7 @@ class Downloader(object):
|
|||||||
try:
|
try:
|
||||||
self.start()
|
self.start()
|
||||||
while self.state == self.states.downloading:
|
while self.state == self.states.downloading:
|
||||||
time.sleep(0.2)
|
xbmc.sleep(200)
|
||||||
line1 = "%s" % (self.filename)
|
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])
|
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)
|
line3 = config.get_localized_string(60202) % (self.remaining_time)
|
||||||
@@ -173,7 +175,7 @@ class Downloader(object):
|
|||||||
downloaded2 = self._start_downloaded
|
downloaded2 = self._start_downloaded
|
||||||
t = time.time()
|
t = time.time()
|
||||||
t2 = time.time()
|
t2 = time.time()
|
||||||
time.sleep(1)
|
xbmc.sleep(1000)
|
||||||
|
|
||||||
while self.state == self.states.downloading:
|
while self.state == self.states.downloading:
|
||||||
self._average_speed = old_div((self.downloaded[0] - self._start_downloaded), (time.time() - self._start_time))
|
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:
|
if time.time() - t > 5:
|
||||||
t = t2
|
t = t2
|
||||||
downloaded = downloaded2
|
|
||||||
t2 = time.time()
|
t2 = time.time()
|
||||||
downloaded2 = self.downloaded[0]
|
downloaded2 = self.downloaded[0]
|
||||||
|
|
||||||
time.sleep(0.5)
|
xbmc.sleep(500)
|
||||||
|
|
||||||
# Internal functions
|
# Internal functions
|
||||||
def __init__(self, url, path, filename=None, headers=[], resume=True, max_connections=10, block_size=2 ** 17,
|
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)
|
logger.info("Thread started: %s" % threading.current_thread().name)
|
||||||
|
|
||||||
while self._state == self.states.downloading:
|
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
|
if not self.pending_parts and not self.download_parts and not self.save_parts: # Download finished
|
||||||
self._state = self.states.completed
|
self._state = self.states.completed
|
||||||
self.file.close()
|
self.file.close()
|
||||||
@@ -483,7 +485,7 @@ class Downloader(object):
|
|||||||
self.download_parts.remove(id)
|
self.download_parts.remove(id)
|
||||||
self.save_parts.add(id)
|
self.save_parts.add(id)
|
||||||
while self._state == self.states.downloading and len(self._buffer) > self._max_connections + self._max_buffer:
|
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):
|
def __set_part_stopped__(self, id):
|
||||||
if self._download_info["parts"][id]["status"] == self.states.downloading:
|
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"])
|
connection = self.__open_connection__(self._download_info["parts"][id]["current"], self._download_info["parts"][id]["end"])
|
||||||
except:
|
except:
|
||||||
self.__set_part__error__(id)
|
self.__set_part__error__(id)
|
||||||
time.sleep(5)
|
xbmc.sleep(5000)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.__set_part__downloading__(id)
|
self.__set_part__downloading__(id)
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ def findvideos(item, itemlist=[]):
|
|||||||
p_dialog.update(100)
|
p_dialog.update(100)
|
||||||
p_dialog.close()
|
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:
|
if itemlist and not serverlist:
|
||||||
platformtools.render_items(itemlist, item)
|
platformtools.render_items(itemlist, item)
|
||||||
|
|||||||
@@ -1810,7 +1810,7 @@ def channelImport(channelId):
|
|||||||
channel = None
|
channel = None
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
def serverWindow(item, itemlist):
|
def serverWindow(item, itemlist, runDirectly=True):
|
||||||
from core import db
|
from core import db
|
||||||
LEFT = 1
|
LEFT = 1
|
||||||
RIGHT = 2
|
RIGHT = 2
|
||||||
@@ -2027,6 +2027,8 @@ def serverWindow(item, itemlist):
|
|||||||
selection = ServerSkinWindow("DialogSelect.xml", config.get_runtime_path()).start(item, itemlist)
|
selection = ServerSkinWindow("DialogSelect.xml", config.get_runtime_path()).start(item, itemlist)
|
||||||
else:
|
else:
|
||||||
selection = ServerWindow('Servers.xml', config.get_runtime_path()).start(item, itemlist)
|
selection = ServerWindow('Servers.xml', config.get_runtime_path()).start(item, itemlist)
|
||||||
if selection != -1:
|
if selection != -1 and runDirectly:
|
||||||
from platformcode.launcher import run
|
from platformcode.launcher import run
|
||||||
run(selection)
|
run(selection)
|
||||||
|
else:
|
||||||
|
return selection
|
||||||
@@ -805,13 +805,15 @@ def select_server(item):
|
|||||||
seleccion = 1
|
seleccion = 1
|
||||||
else:
|
else:
|
||||||
# otherwise it shows the selection window
|
# 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:
|
if seleccion != -1: # not canceled
|
||||||
|
if seleccion.action != 'auto':
|
||||||
update_json(item.path, {
|
update_json(item.path, {
|
||||||
"downloadServer": {"url": play_items[seleccion - 1].url, "server": play_items[seleccion - 1].server}})
|
"downloadServer": {"url": seleccion.url, "server": seleccion.server}})
|
||||||
return play_items[seleccion - 1]
|
return seleccion
|
||||||
elif seleccion == 0:
|
else:
|
||||||
update_json(item.path, {"downloadServer": {}})
|
update_json(item.path, {"downloadServer": {}})
|
||||||
return 'Auto'
|
return 'Auto'
|
||||||
# platformtools.itemlist_refresh()
|
# platformtools.itemlist_refresh()
|
||||||
@@ -1067,6 +1069,7 @@ def save_download_movie(item):
|
|||||||
else:
|
else:
|
||||||
# from core.support import dbg;dbg()
|
# from core.support import dbg;dbg()
|
||||||
play_item = select_server(item)
|
play_item = select_server(item)
|
||||||
|
if play_item:
|
||||||
if type(play_item) == str and play_item == 'Auto':
|
if type(play_item) == str and play_item == 'Auto':
|
||||||
start_download(item)
|
start_download(item)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user