Added overwriteFile and saveDownloadQueue options

This commit is contained in:
RemixDev 2020-05-17 21:26:49 +02:00
parent 96ce0178b2
commit 44f5ccccc1
2 changed files with 42 additions and 5 deletions

39
app.py
View file

@ -1,8 +1,13 @@
#!/usr/bin/env python3
from deemix.app.queuemanager import addToQueue, removeFromQueue, getQueue, cancelAllDownloads, removeFinishedDownloads
from deemix.app.queuemanager import addToQueue, removeFromQueue, getQueue, cancelAllDownloads, removeFinishedDownloads, restoreQueue, slimQueueItems, resetQueueItems
from deemix.utils.misc import getTypeFromLink, getIDFromLink
from deemix.app.settings import initSettings, getSettings, getDefaultSettings, saveSettings
from deemix.app.spotify import SpotifyHelper
from deemix.utils.localpaths import getConfigFolder
import os.path as path
import json
from os import remove
settings = {}
spotifyHelper = None
@ -19,11 +24,36 @@ def initialize():
def shutdown(interface=None):
getQueue()
if settings['saveDownloadQueue']:
(queue, queueComplete, queueList, currentItem) = getQueue()
if len(queueList) > 0:
queue.insert(0, currentItem)
with open(path.join(getConfigFolder(), 'queue.json'), 'w') as f:
json.dump({
'queue': queue,
'queueComplete': queueComplete,
'queueList': resetQueueItems(queueList, queue)
}, f)
cancelAllDownloads(interface)
if interface:
interface.send("toast", {'msg': "Server is closed."})
def loadDownloadQueue(dz, interface=None):
if path.isfile(path.join(getConfigFolder(), 'queue.json')):
if interface:
interface.send('toast', {'msg': "Restoring download queue", 'icon': 'loading', 'dismiss': False,
'id': 'restoring_queue'})
with open(path.join(getConfigFolder(), 'queue.json'), 'r') as f:
qd = json.load(f)
if interface:
interface.send('init_downloadQueue',
{'queue': qd['queue'], 'queueComplete': qd['queueComplete'], 'queueList': slimQueueItems(qd['queueList'])})
if interface:
interface.send('toast', {'msg': "Download queue restored!", 'icon': 'done', 'dismiss': True,
'id': 'restoring_queue'})
remove(path.join(getConfigFolder(), 'queue.json'))
restoreQueue(qd['queue'], qd['queueComplete'], qd['queueList'], dz, interface)
def get_charts(dz):
global chartsList
if len(chartsList) == 0:
@ -120,8 +150,9 @@ def removeFinishedDownloads_link(interface=None):
removeFinishedDownloads(interface)
def getQueue_link():
return getQueue()
def initDownloadQueue():
(queue, queueComplete, queueList, currentItem) = getQueue()
return (queue, queueComplete, slimQueueItems(queueList), currentItem)
def analyzeLink(dz, link):
type = getTypeFromLink(link)

View file

@ -60,6 +60,7 @@ logging.getLogger('engineio').setLevel(logging.ERROR)
#server.logger.disabled = True
app.initialize()
firstConnection = True
@server.route('/')
@ -92,7 +93,7 @@ def on_connect():
arl = file.readline().rstrip("\n")
login(arl)
queue, queueComplete, queueList, currentItem = app.getQueue_link()
queue, queueComplete, queueList, currentItem = app.initDownloadQueue()
emit('init_downloadQueue',
{'queue': queue, 'queueComplete': queueComplete, 'queueList': queueList, 'currentItem': currentItem})
emit('init_home', session['dz'].get_charts())
@ -101,6 +102,7 @@ def on_connect():
@socketio.on('login')
def login(arl, force=False):
global firstConnection
emit('toast', {'msg': "Logging in...", 'icon': 'loading', 'dismiss': False, 'id': "login-toast"})
if not session['dz'].logged_in:
result = session['dz'].login_via_arl(arl)
@ -114,6 +116,10 @@ def login(arl, force=False):
result = 2
emit('logged_in', {'status': result, 'arl': arl, 'user': session['dz'].user})
emit('init_favorites', app.getUserFavorites(session['dz']))
if firstConnection and result in [1, 3]:
firstConnection = False
app.loadDownloadQueue(session['dz'], socket_interface)
@socketio.on('logout')