mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 00:46:18 +00:00
scan Api implementation
This commit is contained in:
parent
8cef628219
commit
6c89accc86
@ -116,3 +116,4 @@ from .playlists import *
|
||||
from .jukebox import *
|
||||
from .radio import *
|
||||
from .unsupported import *
|
||||
from .scan import *
|
@ -122,3 +122,10 @@ 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."
|
||||
)
|
33
supysonic/api/scan.py
Normal file
33
supysonic/api/scan.py
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
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 ..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()
|
||||
|
||||
@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))
|
Loading…
Reference in New Issue
Block a user