Migliorie varie download

This commit is contained in:
marco
2020-03-28 14:11:55 +01:00
parent 47be8c1e9e
commit f351270c6f
5 changed files with 102 additions and 85 deletions
+16 -14
View File
@@ -106,19 +106,20 @@ class Downloader(object):
def start_dialog(self, title=config.get_localized_string(60200)): def start_dialog(self, title=config.get_localized_string(60200)):
from platformcode import platformtools from platformcode import platformtools
progreso = platformtools.dialog_progress_bg(title, config.get_localized_string(60201)) progreso = platformtools.dialog_progress_bg(title, config.get_localized_string(60201))
self.start() try:
while self.state == self.states.downloading: self.start()
time.sleep(0.1) while self.state == self.states.downloading:
line1 = "%s" % (self.filename) time.sleep(0.2)
line2 = config.get_localized_string(59983) % ( line1 = "%s" % (self.filename)
self.progress, self.downloaded[1], self.downloaded[2], self.size[1], self.size[2], line2 = config.get_localized_string(59983) % (
self.speed[1], self.speed[2], self.connections[0], self.connections[1]) self.downloaded[1], self.downloaded[2], self.size[1], self.size[2],
line3 = config.get_localized_string(60202) % (self.remaining_time) self.speed[1], self.speed[2], self.connections[0], self.connections[1])
line3 = config.get_localized_string(60202) % (self.remaining_time)
progreso.update(int(self.progress), line1, line2 + '\n' + line3) progreso.update(int(self.progress), line1, line2 + line3)
self.__update_json() self.__update_json()
finally:
progreso.close() progreso.close()
def start(self): def start(self):
self.__update_json(started=False) self.__update_json(started=False)
@@ -587,10 +588,11 @@ class Downloader(object):
def __update_json(self, started=True): def __update_json(self, started=True):
item = Item().fromjson(filetools.read(self._json_path)) item = Item().fromjson(filetools.read(self._json_path))
progress = int(self.progress)
if started and item.downloadStatus == 0: # stopped if started and item.downloadStatus == 0: # stopped
logger.info('Download paused') logger.info('Download paused')
self.stop() self.stop()
elif item.downloadProgress != self.progress or not started: elif item.downloadProgress != progress or not started:
params = {"downloadStatus": 4, "downloadComplete": 0, "downloadProgress": self.progress} params = {"downloadStatus": 4, "downloadComplete": 0, "downloadProgress": progress}
item.__dict__.update(params) item.__dict__.update(params)
filetools.write(self._json_path, item.tojson()) filetools.write(self._json_path, item.tojson())
+6 -3
View File
@@ -910,6 +910,7 @@ def download(itemlist, item, typography='', function_level=1, function=''):
contentSerieName=item.contentSerieName if item.contentSerieName else '' contentSerieName=item.contentSerieName if item.contentSerieName else ''
contentTitle=item.contentTitle if item.contentTitle else '' contentTitle=item.contentTitle if item.contentTitle else ''
serverItemlist = [i.tourl() for i in itemlist]
if itemlist and item.contentChannel != 'videolibrary': if itemlist and item.contentChannel != 'videolibrary':
itemlist.append( itemlist.append(
@@ -925,7 +926,8 @@ def download(itemlist, item, typography='', function_level=1, function=''):
from_action=from_action, from_action=from_action,
contentTitle=contentTitle, contentTitle=contentTitle,
path=item.path, path=item.path,
thumbnail=thumb(thumb='downloads.png') thumbnail=thumb(thumb='downloads.png'),
serverItemlist=serverItemlist
)) ))
if from_action == 'episodios': if from_action == 'episodios':
itemlist.append( itemlist.append(
@@ -941,8 +943,9 @@ def download(itemlist, item, typography='', function_level=1, function=''):
from_action=from_action, from_action=from_action,
contentTitle=contentTitle, contentTitle=contentTitle,
download='season', download='season',
thumbnail=thumb(thumb='downloads.png') thumbnail=thumb(thumb='downloads.png'),
)) serverItemlist=serverItemlist
))
return itemlist return itemlist
+2 -2
View File
@@ -551,7 +551,7 @@ msgid "torrent"
msgstr "" msgstr ""
msgctxt "#59983" msgctxt "#59983"
msgid "%.2f%% - %.2f %s of %.2f %s a %.2f %s/s (%d/%d)" msgid "%.2f %s of %.2f %s a %.2f %s/s (%d/%d)"
msgstr "" msgstr ""
msgctxt "#59985" msgctxt "#59985"
@@ -991,7 +991,7 @@ msgid "Download starting..."
msgstr "" msgstr ""
msgctxt "#60202" msgctxt "#60202"
msgid "Remaining time: %s" msgid "R.T : %s"
msgstr "" msgstr ""
msgctxt "#60203" msgctxt "#60203"
+4 -4
View File
@@ -550,8 +550,8 @@ msgid "torrent"
msgstr "torrent" msgstr "torrent"
msgctxt "#59983" msgctxt "#59983"
msgid "%.2f%% - %.2f %s of %.2f %s a %.2f %s/s (%d/%d)" msgid "%.2f %s of %.2f %s a %.2f %s/s (%d/%d)"
msgstr "%.2f%% - %.2f %s di %.2f %s a %.2f %s/s (%d/%d)" msgstr "%.2f %s di %.2f %s a %.2f %s/s (%d/%d)"
msgctxt "#59985" msgctxt "#59985"
msgid "Error in the channel " msgid "Error in the channel "
@@ -990,8 +990,8 @@ msgid "Download starting..."
msgstr "Inizio download..." msgstr "Inizio download..."
msgctxt "#60202" msgctxt "#60202"
msgid "Remaining time: %s" msgid "R.T. : %s"
msgstr "Tempo rimanente: %s" msgstr "T.R. : %s"
msgctxt "#60203" msgctxt "#60203"
msgid "Downloader %s/%s" msgid "Downloader %s/%s"
+74 -62
View File
@@ -167,6 +167,7 @@ def del_dir(item):
def clean_all(item): def clean_all(item):
logger.info() logger.info()
stop_all(item)
for fichero in sorted(filetools.listdir(DOWNLOAD_LIST_PATH)): for fichero in sorted(filetools.listdir(DOWNLOAD_LIST_PATH)):
if fichero.endswith(".json"): if fichero.endswith(".json"):
@@ -175,7 +176,7 @@ def clean_all(item):
item.contentSerieName == download_item.contentSerieName and item.contentChannel == download_item.contentChannel): item.contentSerieName == download_item.contentSerieName and item.contentChannel == download_item.contentChannel):
filetools.remove(filetools.join(DOWNLOAD_LIST_PATH, fichero)) filetools.remove(filetools.join(DOWNLOAD_LIST_PATH, fichero))
xbmc.sleep(100) xbmc.sleep(100)
platformtools.itemlist_refresh() platformtools.itemlist_update(item, True)
def stop_all(item): def stop_all(item):
@@ -187,7 +188,7 @@ def stop_all(item):
if download_item.downloadStatus == 4: if download_item.downloadStatus == 4:
update_json(filetools.join(DOWNLOAD_LIST_PATH, fichero), {"downloadStatus": STATUS_CODES.stoped}) update_json(filetools.join(DOWNLOAD_LIST_PATH, fichero), {"downloadStatus": STATUS_CODES.stoped})
xbmc.sleep(100) xbmc.sleep(100)
platformtools.itemlist_refresh() platformtools.itemlist_update(item, True)
def clean_ready(item): def clean_ready(item):
@@ -200,7 +201,7 @@ def clean_ready(item):
if download_item.downloadStatus == STATUS_CODES.completed: if download_item.downloadStatus == STATUS_CODES.completed:
filetools.remove(filetools.join(DOWNLOAD_LIST_PATH, fichero)) filetools.remove(filetools.join(DOWNLOAD_LIST_PATH, fichero))
platformtools.itemlist_refresh() platformtools.itemlist_update(item, True)
def restart_error(item): def restart_error(item):
@@ -220,15 +221,14 @@ def restart_error(item):
update_json(item.path, update_json(item.path,
{"downloadStatus": STATUS_CODES.stoped, "downloadComplete": 0, "downloadProgress": 0}) {"downloadStatus": STATUS_CODES.stoped, "downloadComplete": 0, "downloadProgress": 0})
platformtools.itemlist_refresh() platformtools.itemlist_update(item, True)
def download_all(item): def download_all(item):
time.sleep(0.5) time.sleep(0.5)
item.action = "download_all_background" item.action = "download_all_background"
xbmc.executebuiltin("RunPlugin(plugin://plugin.video.kod/?" + item.tourl() + ")") xbmc.executebuiltin("RunPlugin(plugin://plugin.video.kod/?" + item.tourl() + ")")
xbmc.sleep(100) platformtools.itemlist_update(item, True)
platformtools.itemlist_refresh()
def download_all_background(item): def download_all_background(item):
@@ -241,7 +241,7 @@ def download_all_background(item):
item.contentSerieName == download_item.contentSerieName and item.contentChannel == download_item.contentChannel): item.contentSerieName == download_item.contentSerieName and item.contentChannel == download_item.contentChannel):
if download_item.downloadStatus in [STATUS_CODES.stoped, STATUS_CODES.canceled]: if download_item.downloadStatus in [STATUS_CODES.stoped, STATUS_CODES.canceled]:
res = start_download(download_item) res = start_download(download_item)
platformtools.itemlist_refresh() # platformtools.itemlist_refresh()
# Si se ha cancelado paramos # Si se ha cancelado paramos
if res == STATUS_CODES.canceled: break if res == STATUS_CODES.canceled: break
@@ -317,11 +317,9 @@ def menu(item):
update_json(item.path, {"downloadStatus": STATUS_CODES.stoped}) update_json(item.path, {"downloadStatus": STATUS_CODES.stoped})
if opciones[seleccion] == op[5]: if opciones[seleccion] == op[5]:
platformtools.play_video(Item(channel="downloads", title=item.downloadFilename, action="play", xbmc.executebuiltin('PlayMedia(' + filetools.join(DOWNLOAD_PATH, item.downloadFilename) + ',resume)')
url=filetools.join(DOWNLOAD_PATH, item.downloadFilename), infoLabels=item.infoLabels))
xbmc.sleep(100) platformtools.itemlist_update(item, True)
platformtools.itemlist_refresh()
def move_to_libray(item): def move_to_libray(item):
@@ -606,7 +604,7 @@ def download_from_server(item):
logger.info(item.tostring()) logger.info(item.tostring())
unsupported_servers = ["torrent"] unsupported_servers = ["torrent"]
progreso = platformtools.dialog_progress(config.get_localized_string(30101), config.get_localized_string(70178) % item.server) progreso = platformtools.dialog_progress_bg(config.get_localized_string(30101), config.get_localized_string(70178) % item.server)
if item.contentChannel == 'community': if item.contentChannel == 'community':
channel = __import__('specials.%s' % item.contentChannel, None, None, ['specials.%s' % item.contentChannel]) channel = __import__('specials.%s' % item.contentChannel, None, None, ['specials.%s' % item.contentChannel])
else: else:
@@ -674,31 +672,35 @@ def download_from_best_server(item):
logger.info("contentAction: %s | contentChannel: %s | url: %s" % (item.contentAction, item.contentChannel, item.url)) logger.info("contentAction: %s | contentChannel: %s | url: %s" % (item.contentAction, item.contentChannel, item.url))
result = {"downloadStatus": STATUS_CODES.error} result = {"downloadStatus": STATUS_CODES.error}
progreso = platformtools.dialog_progress_bg(config.get_localized_string(30101), config.get_localized_string(70179))
try:
if item.serverItemlist:
logger.info('using cached servers')
play_items = [Item().fromurl(i) for i in item.serverItemlist]
else:
if item.contentChannel == 'community':
channel = __import__('specials.%s' % item.contentChannel, None, None, ['specials.%s' % item.contentChannel])
else:
channel = __import__('channels.%s' % item.contentChannel, None, None, ['channels.%s' % item.contentChannel])
progreso = platformtools.dialog_progress(config.get_localized_string(30101), config.get_localized_string(70179)) progreso.update(50, config.get_localized_string(70184), config.get_localized_string(70180) % item.contentChannel)
if item.contentChannel == 'community':
channel = __import__('specials.%s' % item.contentChannel, None, None, ['specials.%s' % item.contentChannel])
else:
channel = __import__('channels.%s' % item.contentChannel, None, None, ['channels.%s' % item.contentChannel])
progreso.update(50, config.get_localized_string(70184), config.get_localized_string(70180) % item.contentChannel) if hasattr(channel, item.contentAction):
play_items = getattr(channel, item.contentAction)(item.clone(action=item.contentAction, channel=item.contentChannel))
else:
play_items = servertools.find_video_items(item.clone(action=item.contentAction, channel=item.contentChannel))
if hasattr(channel, item.contentAction): play_items = [x for x in play_items if x.action == "play" and not "trailer" in x.title.lower()]
play_items = getattr(channel, item.contentAction)(item.clone(action=item.contentAction, channel=item.contentChannel))
else:
play_items = servertools.find_video_items(item.clone(action=item.contentAction, channel=item.contentChannel))
play_items = [x for x in play_items if x.action == "play" and not "trailer" in x.title.lower()] progreso.update(100, config.get_localized_string(70183), config.get_localized_string(70181) % len(play_items))
progreso.update(100, config.get_localized_string(70183), config.get_localized_string(70181) % len(play_items), config.get_localized_string(70182)) # if config.get_setting("server_reorder", "downloads") == 1:
play_items.sort(key=sort_method)
# if config.get_setting("server_reorder", "downloads") == 1: # if progreso.iscanceled():
play_items.sort(key=sort_method) # return {"downloadStatus": STATUS_CODES.canceled}
finally:
if progreso.iscanceled(): progreso.close()
return {"downloadStatus": STATUS_CODES.canceled}
progreso.close()
# Recorremos el listado de servers, hasta encontrar uno que funcione # Recorremos el listado de servers, hasta encontrar uno que funcione
for play_item in play_items: for play_item in play_items:
@@ -708,8 +710,8 @@ def download_from_best_server(item):
result = download_from_server(play_item) result = download_from_server(play_item)
if progreso.iscanceled(): # if progreso.iscanceled():
result["downloadStatus"] = STATUS_CODES.canceled # result["downloadStatus"] = STATUS_CODES.canceled
# Tanto si se cancela la descarga como si se completa dejamos de probar mas opciones # Tanto si se cancela la descarga como si se completa dejamos de probar mas opciones
if result["downloadStatus"] in [STATUS_CODES.canceled, STATUS_CODES.completed]: if result["downloadStatus"] in [STATUS_CODES.canceled, STATUS_CODES.completed]:
@@ -724,22 +726,24 @@ def select_server(item):
"contentAction: %s | contentChannel: %s | url: %s" % (item.contentAction, item.contentChannel, item.url)) "contentAction: %s | contentChannel: %s | url: %s" % (item.contentAction, item.contentChannel, item.url))
progreso = platformtools.dialog_progress(config.get_localized_string(30101), config.get_localized_string(70179)) progreso = platformtools.dialog_progress(config.get_localized_string(30101), config.get_localized_string(70179))
if item.contentChannel == 'community': if item.serverItemlist:
channel = __import__('specials.%s' % item.contentChannel, None, None, ['specials.%s' % item.contentChannel]) logger.info('using cached servers')
play_items = [Item().fromurl(i) for i in item.serverItemlist]
else: else:
channel = __import__('channels.%s' % item.contentChannel, None, None, ['channels.%s' % item.contentChannel]) if item.contentChannel == 'community':
progreso.update(50, config.get_localized_string(70184), config.get_localized_string(70180) % item.contentChannel) channel = __import__('specials.%s' % item.contentChannel, None, None, ['specials.%s' % item.contentChannel])
else:
channel = __import__('channels.%s' % item.contentChannel, None, None, ['channels.%s' % item.contentChannel])
progreso.update(50, config.get_localized_string(70184), config.get_localized_string(70180) % item.contentChannel)
if hasattr(channel, item.contentAction): if hasattr(channel, item.contentAction):
play_items = getattr(channel, item.contentAction)( play_items = getattr(channel, item.contentAction)(
item.clone(action=item.contentAction, channel=item.contentChannel)) item.clone(action=item.contentAction, channel=item.contentChannel))
else: else:
play_items = servertools.find_video_items(item.clone(action=item.contentAction, channel=item.contentChannel)) play_items = servertools.find_video_items(item.clone(action=item.contentAction, channel=item.contentChannel))
play_items = [x for x in play_items if x.action == "play" and not "trailer" in x.title.lower()] play_items = [x for x in play_items if x.action == "play" and not "trailer" in x.title.lower()]
progreso.update(100, config.get_localized_string(70183), config.get_localized_string(70181) % len(play_items))
progreso.update(100, config.get_localized_string(70183), config.get_localized_string(70181) % len(play_items),
config.get_localized_string(70182))
for x, i in enumerate(play_items): for x, i in enumerate(play_items):
if not i.server and hasattr(channel, "play"): if not i.server and hasattr(channel, "play"):
@@ -752,30 +756,25 @@ def select_server(item):
elif seleccion == 0: elif seleccion == 0:
update_json(item.path, {"downloadServer": {}}) update_json(item.path, {"downloadServer": {}})
platformtools.itemlist_refresh() # platformtools.itemlist_update(item, True)
return play_items[seleccion - 1]
def start_download(item): def start_download(item):
logger.info( logger.info(
"contentAction: %s | contentChannel: %s | url: %s" % (item.contentAction, item.contentChannel, item.url)) "contentAction: %s | contentChannel: %s | url: %s" % (item.contentAction, item.contentChannel, item.url))
# Ya tenemnos server, solo falta descargar # Ya tenemnos server, solo falta descargar
if item.contentAction == "play": if item.contentAction == "play":
ret = download_from_server(item) ret = download_from_server(item)
update_json(item.path, ret)
return ret["downloadStatus"]
elif item.downloadServer and item.downloadServer.get("server"): elif item.downloadServer and item.downloadServer.get("server"):
ret = download_from_server( ret = download_from_server(
item.clone(server=item.downloadServer.get("server"), url=item.downloadServer.get("url"), item.clone(server=item.downloadServer.get("server"), url=item.downloadServer.get("url"),
contentAction="play")) contentAction="play"))
update_json(item.path, ret)
return ret["downloadStatus"]
# No tenemos server, necesitamos buscar el mejor # No tenemos server, necesitamos buscar el mejor
else: else:
ret = download_from_best_server(item) ret = download_from_best_server(item)
update_json(item.path, ret) update_json(item.path, ret)
return ret["downloadStatus"] return ret["downloadStatus"]
def get_episodes(item): def get_episodes(item):
@@ -931,7 +930,7 @@ def save_download_movie(item):
logger.info("contentAction: %s | contentChannel: %s | contentTitle: %s" % ( logger.info("contentAction: %s | contentChannel: %s | contentTitle: %s" % (
item.contentAction, item.contentChannel, item.contentTitle)) item.contentAction, item.contentChannel, item.contentTitle))
progreso = platformtools.dialog_progress(config.get_localized_string(30101), config.get_localized_string(70191)) progreso = platformtools.dialog_progress_bg(config.get_localized_string(30101), config.get_localized_string(70191))
set_movie_title(item) set_movie_title(item)
@@ -952,14 +951,18 @@ def save_download_movie(item):
platformtools.dialog_ok(config.get_localized_string(30101), item.contentTitle, platformtools.dialog_ok(config.get_localized_string(30101), item.contentTitle,
config.get_localized_string(30109)) config.get_localized_string(30109))
else: else:
start_download(item) play_item = select_server(item)
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): def save_download_tvshow(item):
logger.info("contentAction: %s | contentChannel: %s | contentType: %s | contentSerieName: %s" % ( logger.info("contentAction: %s | contentChannel: %s | contentType: %s | contentSerieName: %s" % (
item.contentAction, item.contentChannel, item.contentType, item.contentSerieName)) item.contentAction, item.contentChannel, item.contentType, item.contentSerieName))
progreso = platformtools.dialog_progress(config.get_localized_string(30101), config.get_localized_string(70188)) progreso = platformtools.dialog_progress_bg(config.get_localized_string(30101), config.get_localized_string(70188))
item.show = item.fulltitle item.show = item.fulltitle
scraper.find_and_set_infoLabels(item) scraper.find_and_set_infoLabels(item)
@@ -985,11 +988,20 @@ def save_download_tvshow(item):
str(len(episodes)) + config.get_localized_string(30110) + item.contentSerieName, str(len(episodes)) + config.get_localized_string(30110) + item.contentSerieName,
config.get_localized_string(30109)) config.get_localized_string(30109))
else: else:
for i in episodes: if len(episodes) == 1:
i.contentChannel = item.contentChannel play_item = select_server(item)
res = start_download(i) play_item = item.clone(**play_item.__dict__)
if res == STATUS_CODES.canceled: play_item.contentAction = play_item.action
break play_item.infoLabels = item.infoLabels
from core import support
support.dbg()
start_download(play_item)
else:
for i in episodes:
i.contentChannel = item.contentChannel
res = start_download(i)
if res == STATUS_CODES.canceled:
break
def set_movie_title(item): def set_movie_title(item):