2020-05-29 16:54:35 +00:00
|
|
|
#!/usr/bin/env python3
|
2020-04-22 09:27:09 +00:00
|
|
|
import logging
|
|
|
|
import sys
|
2020-05-19 16:30:18 +00:00
|
|
|
import subprocess
|
2020-05-05 08:27:48 +00:00
|
|
|
from os import path
|
2020-08-12 14:33:29 +00:00
|
|
|
import json
|
2020-09-08 17:55:36 +00:00
|
|
|
|
2020-09-07 09:50:28 +00:00
|
|
|
import requests
|
2020-09-07 10:47:42 +00:00
|
|
|
from urllib.request import urlopen
|
2020-09-08 17:55:36 +00:00
|
|
|
from datetime import datetime
|
2020-04-07 22:19:27 +00:00
|
|
|
|
2020-08-12 14:33:29 +00:00
|
|
|
from flask import Flask, render_template, request, session, redirect, copy_current_request_context
|
2020-04-10 14:12:21 +00:00
|
|
|
from flask_socketio import SocketIO, emit
|
2020-06-14 21:06:32 +00:00
|
|
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-09-07 09:50:28 +00:00
|
|
|
from deemix import __version__ as deemixVersion
|
2020-08-16 08:42:49 +00:00
|
|
|
from app import deemix
|
2020-04-12 19:22:06 +00:00
|
|
|
from deemix.api.deezer import Deezer
|
2020-08-16 08:42:49 +00:00
|
|
|
from deemix.app.messageinterface import MessageInterface
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-05-06 09:58:25 +00:00
|
|
|
# Workaround for MIME type error in certain Windows installs
|
|
|
|
# https://github.com/pallets/flask/issues/1045#issuecomment-42202749
|
|
|
|
import mimetypes
|
|
|
|
mimetypes.add_type('text/css', '.css')
|
|
|
|
mimetypes.add_type('text/javascript', '.js')
|
2020-04-07 22:19:27 +00:00
|
|
|
|
2020-05-21 20:57:48 +00:00
|
|
|
# Makes engineio accept more packets from client, needed for long URL lists in addToQueue requests
|
|
|
|
# https://github.com/miguelgrinberg/python-engineio/issues/142#issuecomment-545807047
|
|
|
|
from engineio.payload import Payload
|
|
|
|
Payload.max_decode_packets = 500
|
|
|
|
|
2020-08-16 08:42:49 +00:00
|
|
|
app = None
|
2020-08-21 18:27:23 +00:00
|
|
|
gui = None
|
2020-08-24 10:25:31 +00:00
|
|
|
arl = None
|
2020-08-16 08:42:49 +00:00
|
|
|
|
2020-04-08 16:43:35 +00:00
|
|
|
class CustomFlask(Flask):
|
2020-04-22 09:27:09 +00:00
|
|
|
jinja_options = Flask.jinja_options.copy()
|
|
|
|
jinja_options.update(dict(
|
|
|
|
block_start_string='$$',
|
|
|
|
block_end_string='$$',
|
|
|
|
variable_start_string='$',
|
|
|
|
variable_end_string='$',
|
|
|
|
comment_start_string='$#',
|
|
|
|
comment_end_string='#$',
|
|
|
|
))
|
2020-04-08 16:43:35 +00:00
|
|
|
|
2020-05-07 12:24:44 +00:00
|
|
|
def resource_path(relative_path):
|
|
|
|
""" Get absolute path to resource, works for dev and for PyInstaller """
|
|
|
|
try:
|
|
|
|
# PyInstaller creates a temp folder and stores path in _MEIPASS
|
|
|
|
base_path = sys._MEIPASS
|
|
|
|
except Exception:
|
2020-05-29 16:55:22 +00:00
|
|
|
base_path = path.dirname(path.abspath(path.realpath(__file__)))
|
2020-04-15 12:49:40 +00:00
|
|
|
|
2020-05-07 12:24:44 +00:00
|
|
|
return path.join(base_path, relative_path)
|
|
|
|
|
2020-05-25 10:58:41 +00:00
|
|
|
gui_dir = resource_path(path.join('webui', 'public'))
|
2020-09-08 11:40:48 +00:00
|
|
|
if not path.exists(gui_dir):
|
|
|
|
gui_dir = resource_path('webui')
|
|
|
|
if not path.isfile(path.join(gui_dir, 'index.html')):
|
|
|
|
sys.exit("WebUI not found, please download and add a WebUI")
|
2020-09-08 11:00:04 +00:00
|
|
|
server = CustomFlask(__name__, static_folder=gui_dir, template_folder=gui_dir, static_url_path="")
|
2020-04-07 22:19:27 +00:00
|
|
|
server.config['SEND_FILE_MAX_AGE_DEFAULT'] = 1 # disable caching
|
2020-09-14 14:56:55 +00:00
|
|
|
socketio = SocketIO(server)
|
2020-06-14 21:06:32 +00:00
|
|
|
server.wsgi_app = ProxyFix(server.wsgi_app, x_for=1, x_proto=1)
|
2020-04-10 14:12:21 +00:00
|
|
|
|
2020-04-15 12:49:40 +00:00
|
|
|
class SocketInterface(MessageInterface):
|
2020-04-22 09:27:09 +00:00
|
|
|
def send(self, message, value=None):
|
|
|
|
if value:
|
|
|
|
socketio.emit(message, value)
|
|
|
|
else:
|
|
|
|
socketio.emit(message)
|
|
|
|
|
2020-04-15 12:49:40 +00:00
|
|
|
|
|
|
|
socket_interface = SocketInterface()
|
2020-08-12 14:33:29 +00:00
|
|
|
loginWindow = False
|
2020-04-15 12:49:40 +00:00
|
|
|
|
2020-04-10 14:12:21 +00:00
|
|
|
serverLog = logging.getLogger('werkzeug')
|
|
|
|
serverLog.disabled = True
|
2020-05-08 16:06:43 +00:00
|
|
|
logging.getLogger('socketio').setLevel(logging.ERROR)
|
|
|
|
logging.getLogger('engineio').setLevel(logging.ERROR)
|
|
|
|
#server.logger.disabled = True
|
2020-04-07 22:19:27 +00:00
|
|
|
|
2020-05-17 19:26:49 +00:00
|
|
|
firstConnection = True
|
2020-09-07 09:50:28 +00:00
|
|
|
|
2020-09-08 17:55:36 +00:00
|
|
|
currentVersion = None
|
|
|
|
latestVersion = None
|
2020-09-07 09:50:28 +00:00
|
|
|
updateAvailable = False
|
|
|
|
|
2020-09-08 17:55:36 +00:00
|
|
|
def compare_versions(currentVersion, latestVersion):
|
2020-09-10 22:50:23 +00:00
|
|
|
if not latestVersion or not currentVersion:
|
|
|
|
return False
|
2020-09-08 17:55:36 +00:00
|
|
|
(currentDate, currentCommit) = tuple(currentVersion.split('-'))
|
|
|
|
(latestDate, latestCommit) = tuple(latestVersion.split('-'))
|
|
|
|
currentDate = currentDate.split('.')
|
|
|
|
latestDate = latestDate.split('.')
|
|
|
|
current = datetime(int(currentDate[0]), int(currentDate[1]), int(currentDate[2]))
|
|
|
|
latest = datetime(int(latestDate[0]), int(latestDate[1]), int(latestDate[2]))
|
|
|
|
if latest > current:
|
|
|
|
return True
|
|
|
|
elif latest == current:
|
|
|
|
return latestCommit != currentCommit
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2020-09-07 09:50:28 +00:00
|
|
|
def check_for_updates():
|
2020-09-08 17:55:36 +00:00
|
|
|
global currentVersion, latestVersion, updateAvailable
|
|
|
|
commitFile = resource_path('version.txt')
|
|
|
|
if path.isfile(commitFile):
|
2020-09-07 09:50:28 +00:00
|
|
|
print("Checking for updates...")
|
2020-09-08 17:55:36 +00:00
|
|
|
with open(commitFile, 'r') as f:
|
|
|
|
currentVersion = f.read().strip()
|
|
|
|
try:
|
2020-09-10 23:03:54 +00:00
|
|
|
latestVersion = requests.get("https://deemix.app/pyweb/latest")
|
|
|
|
latestVersion.raise_for_status()
|
|
|
|
latestVersion = latestVersion.text.strip()
|
2020-09-08 17:55:36 +00:00
|
|
|
except:
|
|
|
|
latestVersion = None
|
|
|
|
if currentVersion and latestVersion:
|
|
|
|
updateAvailable = compare_versions(currentVersion, latestVersion)
|
2020-09-07 09:50:28 +00:00
|
|
|
if updateAvailable:
|
2020-09-08 18:47:11 +00:00
|
|
|
print("Update available! Commit: "+latestVersion)
|
2020-09-07 09:50:28 +00:00
|
|
|
else:
|
|
|
|
print("You're running the latest version")
|
2020-04-13 17:22:34 +00:00
|
|
|
|
2020-04-07 22:19:27 +00:00
|
|
|
@server.route('/')
|
|
|
|
def landing():
|
2020-04-22 09:27:09 +00:00
|
|
|
return render_template('index.html')
|
|
|
|
|
2020-07-27 21:52:53 +00:00
|
|
|
@server.errorhandler(404)
|
|
|
|
def not_found_handler(e):
|
|
|
|
return redirect("/")
|
2020-04-07 22:19:27 +00:00
|
|
|
|
2020-04-11 14:24:53 +00:00
|
|
|
@server.route('/shutdown')
|
|
|
|
def closing():
|
2020-04-22 09:27:09 +00:00
|
|
|
app.shutdown(interface=socket_interface)
|
2020-05-15 13:42:47 +00:00
|
|
|
socketio.stop()
|
2020-08-16 08:42:49 +00:00
|
|
|
return 'Server Closed'
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-05-05 08:27:48 +00:00
|
|
|
serverwide_arl = "--serverwide-arl" in sys.argv
|
2020-05-05 14:15:16 +00:00
|
|
|
if serverwide_arl:
|
|
|
|
print("Server-wide ARL enabled.")
|
2020-04-11 14:24:53 +00:00
|
|
|
|
2020-04-12 19:22:06 +00:00
|
|
|
@socketio.on('connect')
|
|
|
|
def on_connect():
|
2020-04-22 09:27:09 +00:00
|
|
|
session['dz'] = Deezer()
|
2020-08-16 08:42:49 +00:00
|
|
|
settings = app.getSettings()
|
2020-04-22 09:27:09 +00:00
|
|
|
spotifyCredentials = app.getSpotifyCredentials()
|
2020-08-16 08:42:49 +00:00
|
|
|
defaultSettings = app.getDefaultSettings()
|
2020-05-03 14:21:37 +00:00
|
|
|
emit('init_settings', (settings, spotifyCredentials, defaultSettings))
|
2020-09-07 09:50:28 +00:00
|
|
|
emit('init_update',
|
2020-09-08 18:47:11 +00:00
|
|
|
{'currentCommit': currentVersion,
|
|
|
|
'latestCommit': latestVersion,
|
2020-09-07 09:50:28 +00:00
|
|
|
'updateAvailable': updateAvailable,
|
|
|
|
'deemixVersion': deemixVersion}
|
|
|
|
)
|
2020-05-05 08:27:48 +00:00
|
|
|
|
2020-08-24 10:25:31 +00:00
|
|
|
if serverwide_arl:
|
|
|
|
login(arl)
|
|
|
|
else:
|
|
|
|
emit('init_autologin')
|
2020-05-05 08:27:48 +00:00
|
|
|
|
2020-05-17 19:26:49 +00:00
|
|
|
queue, queueComplete, queueList, currentItem = app.initDownloadQueue()
|
2020-08-16 08:42:49 +00:00
|
|
|
if len(queueList.keys()):
|
|
|
|
emit('init_downloadQueue',{
|
|
|
|
'queue': queue,
|
|
|
|
'queueComplete': queueComplete,
|
|
|
|
'queueList': queueList,
|
|
|
|
'currentItem': currentItem
|
|
|
|
})
|
2020-04-29 08:36:30 +00:00
|
|
|
emit('init_home', session['dz'].get_charts())
|
2020-05-03 13:52:42 +00:00
|
|
|
emit('init_charts', app.get_charts(session['dz']))
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-08-22 20:25:01 +00:00
|
|
|
@socketio.on('get_home_data')
|
|
|
|
def get_home_data():
|
2020-08-22 20:41:51 +00:00
|
|
|
emit('init_home', app.get_home(session['dz']))
|
2020-08-22 20:25:01 +00:00
|
|
|
|
|
|
|
@socketio.on('get_charts_data')
|
|
|
|
def get_charts_data():
|
|
|
|
emit('init_charts', app.get_charts(session['dz']))
|
2020-04-11 19:55:12 +00:00
|
|
|
|
|
|
|
@socketio.on('login')
|
2020-05-30 17:32:05 +00:00
|
|
|
def login(arl, force=False, child=0):
|
2020-05-17 19:26:49 +00:00
|
|
|
global firstConnection
|
2020-05-30 19:01:26 +00:00
|
|
|
if child == None:
|
|
|
|
child = 0
|
2020-05-31 10:12:45 +00:00
|
|
|
arl = arl.strip()
|
2020-07-29 14:30:31 +00:00
|
|
|
emit('logging_in')
|
2020-04-22 09:27:09 +00:00
|
|
|
if not session['dz'].logged_in:
|
2020-05-30 19:01:26 +00:00
|
|
|
result = session['dz'].login_via_arl(arl, int(child))
|
2020-04-22 09:27:09 +00:00
|
|
|
else:
|
|
|
|
if force:
|
|
|
|
session['dz'] = Deezer()
|
2020-05-30 19:01:26 +00:00
|
|
|
result = session['dz'].login_via_arl(arl, int(child))
|
2020-04-22 09:27:09 +00:00
|
|
|
if result == 1:
|
|
|
|
result = 3
|
|
|
|
else:
|
|
|
|
result = 2
|
2020-05-09 12:25:24 +00:00
|
|
|
emit('logged_in', {'status': result, 'arl': arl, 'user': session['dz'].user})
|
2020-05-17 19:26:49 +00:00
|
|
|
if firstConnection and result in [1, 3]:
|
|
|
|
firstConnection = False
|
2020-08-16 08:42:49 +00:00
|
|
|
app.restoreDownloadQueue(session['dz'], socket_interface)
|
2020-05-31 10:27:33 +00:00
|
|
|
if result != 0:
|
|
|
|
emit('familyAccounts', session['dz'].childs)
|
|
|
|
emit('init_favorites', app.getUserFavorites(session['dz']))
|
2020-05-17 19:26:49 +00:00
|
|
|
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-05-30 17:32:05 +00:00
|
|
|
@socketio.on('changeAccount')
|
|
|
|
def changeAccount(child):
|
2020-05-30 19:01:26 +00:00
|
|
|
emit('accountChanged', session['dz'].change_account(int(child)))
|
2020-05-30 17:32:05 +00:00
|
|
|
emit('init_favorites', app.getUserFavorites(session['dz']))
|
|
|
|
|
2020-05-13 18:28:20 +00:00
|
|
|
|
2020-04-12 22:14:34 +00:00
|
|
|
@socketio.on('logout')
|
|
|
|
def logout():
|
2020-04-22 09:27:09 +00:00
|
|
|
status = 0
|
|
|
|
if session['dz'].logged_in:
|
|
|
|
session['dz'] = Deezer()
|
|
|
|
status = 0
|
|
|
|
else:
|
|
|
|
status = 1
|
|
|
|
emit('logged_out', status)
|
|
|
|
|
2020-04-12 22:14:34 +00:00
|
|
|
|
2020-04-10 14:12:21 +00:00
|
|
|
@socketio.on('mainSearch')
|
|
|
|
def mainSearch(data):
|
2020-05-14 17:15:47 +00:00
|
|
|
if data['term'].strip() != "":
|
|
|
|
emit('mainSearch', app.mainSearch(session['dz'], data['term']))
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-04-09 14:06:33 +00:00
|
|
|
|
2020-04-10 14:12:21 +00:00
|
|
|
@socketio.on('search')
|
|
|
|
def search(data):
|
2020-05-14 17:15:47 +00:00
|
|
|
if data['term'].strip() != "":
|
|
|
|
result = app.search(session['dz'], data['term'], data['type'], data['start'], data['nb'])
|
|
|
|
result['type'] = data['type']
|
|
|
|
emit('search', result)
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-04-08 21:52:08 +00:00
|
|
|
|
2020-08-16 10:34:04 +00:00
|
|
|
@socketio.on('queueRestored')
|
|
|
|
def queueRestored():
|
|
|
|
app.queueRestored(session['dz'], socket_interface)
|
|
|
|
|
|
|
|
|
2020-04-10 14:12:21 +00:00
|
|
|
@socketio.on('addToQueue')
|
|
|
|
def addToQueue(data):
|
2020-08-16 08:42:49 +00:00
|
|
|
result = app.addToQueue(session['dz'], data['url'], data['bitrate'], interface=socket_interface)
|
2020-04-22 09:27:09 +00:00
|
|
|
if result == "Not logged in":
|
2020-07-29 20:25:22 +00:00
|
|
|
emit('loginNeededToDownload')
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-04-08 21:52:08 +00:00
|
|
|
|
2020-04-11 13:43:59 +00:00
|
|
|
@socketio.on('removeFromQueue')
|
|
|
|
def removeFromQueue(uuid):
|
2020-08-16 08:42:49 +00:00
|
|
|
app.removeFromQueue(uuid, interface=socket_interface)
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-04-11 13:43:59 +00:00
|
|
|
|
2020-04-14 14:48:13 +00:00
|
|
|
@socketio.on('removeFinishedDownloads')
|
|
|
|
def removeFinishedDownloads():
|
2020-08-16 08:42:49 +00:00
|
|
|
app.removeFinishedDownloads(interface=socket_interface)
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-04-14 14:48:13 +00:00
|
|
|
|
|
|
|
@socketio.on('cancelAllDownloads')
|
|
|
|
def cancelAllDownloads():
|
2020-08-16 08:42:49 +00:00
|
|
|
app.cancelAllDownloads(interface=socket_interface)
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-04-14 14:48:13 +00:00
|
|
|
|
2020-04-14 17:58:54 +00:00
|
|
|
@socketio.on('saveSettings')
|
2020-05-05 13:08:04 +00:00
|
|
|
def saveSettings(settings, spotifyCredentials, spotifyUser):
|
2020-08-16 08:42:49 +00:00
|
|
|
app.saveSettings(settings)
|
2020-04-22 09:27:09 +00:00
|
|
|
app.setSpotifyCredentials(spotifyCredentials)
|
|
|
|
socketio.emit('updateSettings', (settings, spotifyCredentials))
|
2020-05-05 13:08:04 +00:00
|
|
|
if spotifyUser != False:
|
|
|
|
emit('updated_userSpotifyPlaylists', app.updateUserSpotifyPlaylists(spotifyUser))
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-04-07 22:19:27 +00:00
|
|
|
|
2020-04-17 17:39:51 +00:00
|
|
|
@socketio.on('getTracklist')
|
|
|
|
def getTracklist(data):
|
2020-04-22 09:27:09 +00:00
|
|
|
if data['type'] == 'artist':
|
|
|
|
artistAPI = session['dz'].get_artist(data['id'])
|
2020-08-04 13:14:10 +00:00
|
|
|
artistAPI['releases'] = session['dz'].get_artist_discography_gw(data['id'], 100)
|
2020-04-22 09:27:09 +00:00
|
|
|
emit('show_artist', artistAPI)
|
2020-05-05 13:08:04 +00:00
|
|
|
elif data['type'] == 'spotifyplaylist':
|
|
|
|
playlistAPI = app.getSpotifyPlaylistTracklist(data['id'])
|
|
|
|
for i in range(len(playlistAPI['tracks'])):
|
|
|
|
playlistAPI['tracks'][i] = playlistAPI['tracks'][i]['track']
|
|
|
|
playlistAPI['tracks'][i]['selected'] = False
|
|
|
|
emit('show_spotifyplaylist', playlistAPI)
|
2020-04-22 09:27:09 +00:00
|
|
|
else:
|
|
|
|
releaseAPI = getattr(session['dz'], 'get_' + data['type'])(data['id'])
|
|
|
|
releaseTracksAPI = getattr(session['dz'], 'get_' + data['type'] + '_tracks')(data['id'])['data']
|
|
|
|
tracks = []
|
|
|
|
showdiscs = False
|
|
|
|
if data['type'] == 'album' and len(releaseTracksAPI) and releaseTracksAPI[-1]['disk_number'] != 1:
|
|
|
|
current_disk = 0
|
|
|
|
showdiscs = True
|
|
|
|
for track in releaseTracksAPI:
|
|
|
|
if showdiscs and int(track['disk_number']) != current_disk:
|
|
|
|
current_disk = int(track['disk_number'])
|
|
|
|
tracks.append({'type': 'disc_separator', 'number': current_disk})
|
|
|
|
track['selected'] = False
|
|
|
|
tracks.append(track)
|
|
|
|
releaseAPI['tracks'] = tracks
|
|
|
|
emit('show_' + data['type'], releaseAPI)
|
|
|
|
|
2020-04-26 12:27:54 +00:00
|
|
|
@socketio.on('analyzeLink')
|
|
|
|
def analyzeLink(link):
|
2020-09-07 10:47:42 +00:00
|
|
|
if 'deezer.page.link' in link:
|
|
|
|
link = urlopen(link).url
|
2020-04-26 12:27:54 +00:00
|
|
|
(type, data) = app.analyzeLink(session['dz'], link)
|
2020-06-03 17:03:37 +00:00
|
|
|
if len(data):
|
|
|
|
emit('analyze_'+type, data)
|
|
|
|
else:
|
|
|
|
emit('analyze_notSupported')
|
2020-04-17 17:39:51 +00:00
|
|
|
|
2020-05-03 13:52:42 +00:00
|
|
|
@socketio.on('getChartTracks')
|
|
|
|
def getChartTracks(id):
|
|
|
|
emit('setChartTracks', session['dz'].get_playlist_tracks(id)['data'])
|
|
|
|
|
2020-06-10 16:46:08 +00:00
|
|
|
@socketio.on('update_userFavorites')
|
|
|
|
def update_userFavorites():
|
|
|
|
emit('updated_userFavorites', app.getUserFavorites(session['dz']))
|
|
|
|
|
2020-05-05 13:08:04 +00:00
|
|
|
@socketio.on('update_userSpotifyPlaylists')
|
|
|
|
def update_userSpotifyPlaylists(spotifyUser):
|
|
|
|
if spotifyUser != False:
|
|
|
|
emit('updated_userSpotifyPlaylists', app.updateUserSpotifyPlaylists(spotifyUser))
|
|
|
|
|
|
|
|
@socketio.on('update_userPlaylists')
|
|
|
|
def update_userPlaylists():
|
|
|
|
emit('updated_userPlaylists', app.updateUserPlaylists(session['dz']))
|
|
|
|
|
|
|
|
@socketio.on('update_userAlbums')
|
|
|
|
def update_userAlbums():
|
|
|
|
emit('updated_userAlbums', app.updateUserAlbums(session['dz']))
|
|
|
|
|
|
|
|
@socketio.on('update_userArtists')
|
|
|
|
def update_userArtists():
|
|
|
|
emit('updated_userArtists', app.updateUserArtists(session['dz']))
|
|
|
|
|
|
|
|
@socketio.on('update_userTracks')
|
|
|
|
def update_userTracks():
|
|
|
|
emit('updated_userTracks', app.updateUserTracks(session['dz']))
|
|
|
|
|
2020-05-19 16:30:18 +00:00
|
|
|
@socketio.on('openDownloadsFolder')
|
|
|
|
def openDownloadsFolder():
|
|
|
|
folder = app.getDownloadFolder()
|
|
|
|
if sys.platform == 'darwin':
|
|
|
|
subprocess.check_call(['open', folder])
|
|
|
|
elif sys.platform == 'linux':
|
|
|
|
subprocess.check_call(['xdg-open', folder])
|
|
|
|
elif sys.platform == 'win32':
|
|
|
|
subprocess.check_call(['explorer', folder])
|
|
|
|
|
2020-08-05 14:14:39 +00:00
|
|
|
@socketio.on('selectDownloadFolder')
|
|
|
|
def selectDownloadFolder():
|
2020-08-21 18:27:23 +00:00
|
|
|
if gui:
|
2020-08-21 20:33:30 +00:00
|
|
|
gui.selectDownloadFolder_trigger.emit()
|
|
|
|
gui._selectDownloadFolder_semaphore.acquire()
|
|
|
|
result = gui.downloadFolder
|
2020-08-05 14:14:39 +00:00
|
|
|
if result:
|
|
|
|
emit('downloadFolderSelected', result)
|
2020-08-21 18:27:23 +00:00
|
|
|
else:
|
|
|
|
print("Can't open folder selection, you're not running the gui")
|
2020-08-05 14:14:39 +00:00
|
|
|
|
2020-08-12 14:33:29 +00:00
|
|
|
@socketio.on('applogin')
|
|
|
|
def applogin():
|
2020-08-21 20:33:30 +00:00
|
|
|
if gui:
|
2020-08-21 22:26:32 +00:00
|
|
|
if not session['dz'].logged_in:
|
|
|
|
gui.appLogin_trigger.emit()
|
|
|
|
gui._appLogin_semaphore.acquire()
|
|
|
|
if gui.arl:
|
|
|
|
emit('applogin_arl', gui.arl)
|
|
|
|
gui.arl = None
|
2020-08-21 20:33:30 +00:00
|
|
|
else:
|
2020-08-21 22:26:32 +00:00
|
|
|
emit('logged_in', {'status': 2, 'user': session['dz'].user})
|
2020-08-21 20:33:30 +00:00
|
|
|
else:
|
|
|
|
print("Can't open login page, you're not running the gui")
|
2020-08-12 14:33:29 +00:00
|
|
|
|
2020-08-21 18:27:23 +00:00
|
|
|
def run_server(port, host="127.0.0.1", portable=None, mainWindow=None):
|
2020-08-24 10:25:31 +00:00
|
|
|
global app, gui, arl
|
2020-08-16 08:42:49 +00:00
|
|
|
app = deemix(portable)
|
2020-08-21 18:27:23 +00:00
|
|
|
gui = mainWindow
|
2020-08-24 10:25:31 +00:00
|
|
|
if serverwide_arl:
|
|
|
|
arl = app.getConfigArl()
|
2020-09-07 09:50:28 +00:00
|
|
|
check_for_updates()
|
2020-06-05 07:58:59 +00:00
|
|
|
print("Starting server at http://" + host + ":" + str(port))
|
2020-06-03 10:59:43 +00:00
|
|
|
socketio.run(server, host=host, port=port)
|
2020-04-22 09:27:09 +00:00
|
|
|
|
2020-04-07 22:19:27 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-06-11 12:44:30 +00:00
|
|
|
port = 6595
|
2020-06-12 09:30:03 +00:00
|
|
|
host = "127.0.0.1"
|
|
|
|
portable = None
|
2020-04-22 09:27:09 +00:00
|
|
|
if len(sys.argv) >= 2:
|
2020-05-05 13:36:05 +00:00
|
|
|
try:
|
|
|
|
port = int(sys.argv[1])
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2020-05-26 10:22:32 +00:00
|
|
|
if '--portable' in sys.argv:
|
|
|
|
portable = path.join(path.dirname(path.realpath(__file__)), 'config')
|
2020-06-03 10:59:43 +00:00
|
|
|
if '--host' in sys.argv:
|
|
|
|
host = str(sys.argv[sys.argv.index("--host")+1])
|
|
|
|
run_server(port, host, portable)
|