diff --git a/supysonic/api/__init__.py b/supysonic/api/__init__.py index 880ef65..ccee972 100644 --- a/supysonic/api/__init__.py +++ b/supysonic/api/__init__.py @@ -116,4 +116,4 @@ from .playlists import * from .jukebox import * from .radio import * from .unsupported import * -from .scan import * \ No newline at end of file +from .scan import * diff --git a/supysonic/api/exceptions.py b/supysonic/api/exceptions.py old mode 100644 new mode 100755 index 0354f83..6a1a80e --- a/supysonic/api/exceptions.py +++ b/supysonic/api/exceptions.py @@ -122,10 +122,3 @@ class AggregateException(SubsonicAPIException): ) # rv.status_code = self.code return rv - -class DaemonUnavailable(SubsonicAPIException): - code = 404 - api_code = 80 - message = ( - "Supysonic Daemon not running on this server." - ) \ No newline at end of file diff --git a/supysonic/api/scan.py b/supysonic/api/scan.py old mode 100644 new mode 100755 index 55eb585..30a2191 --- a/supysonic/api/scan.py +++ b/supysonic/api/scan.py @@ -1,33 +1,42 @@ - from . import api -from functools import wraps from flask import request from flask import current_app from .user import admin_only -from .exceptions import Forbidden,DaemonUnavailable,ServerError -from ..db import Folder +from .exceptions import ServerError from ..daemon.client import DaemonClient -from ..daemon.exceptions import DaemonUnavailableError -from ..managers.folder import FolderManager + @api.route("/startScan.view", methods=["GET", "POST"]) @admin_only def startScan(): try: - DaemonClient(current_app.config["DAEMON"]["socket"]).scan() - except ValueError as e: - ServerError(str(e)) - except DaemonUnavailableError: - raise DaemonUnavailable() - return getScanStatus() + daeomonclient = DaemonClient(current_app.config["DAEMON"]["socket"]) + daeomonclient.scan() + scanned = daeomonclient.get_scanning_progress() + except Exception as e: + raise ServerError(str(e)) + return request.formatter( + "scanStatus", + dict( + scanning="true" if scanned is not None else "false", + count=scanned if scanned is not None else 0, + ), + ) + @api.route("/getScanStatus.view", methods=["GET", "POST"]) @admin_only def getScanStatus(): try: - scanned=DaemonClient(current_app.config["DAEMON"]["socket"]).get_scanning_progress() - except DaemonUnavailableError: - raise DaemonUnavailable() - return request.formatter("scanStatus", - dict(scanning='true' if scanned is not None else 'false', - count= scanned if scanned is not None else 0)) \ No newline at end of file + scanned = DaemonClient( + current_app.config["DAEMON"]["socket"] + ).get_scanning_progress() + except Exception as e: + raise ServerError(str(e)) + return request.formatter( + "scanStatus", + dict( + scanning="true" if scanned is not None else "false", + count=scanned if scanned is not None else 0, + ), + )