Skip to content

Commit

Permalink
✨ feat: Add libraries API route and integrate library refresh functio…
Browse files Browse the repository at this point in the history
…nality
  • Loading branch information
Impre-visible committed Nov 18, 2024
1 parent a254398 commit 5cadc31
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/chocolate_app/routes/api/index.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from flask import Blueprint


from chocolate_app.routes.api.auth import auth_bp
from chocolate_app.routes.api.watch import watch_bp
from chocolate_app.routes.api.libraries import lib_bp
from chocolate_app.routes.api.profil import profil_bp
from chocolate_app.routes.api.medias import medias_bp
from chocolate_app.routes.api.watch import watch_bp
from chocolate_app.routes.api.settings import settings_bp

api_bp = Blueprint('api', __name__, url_prefix='/api')
Expand All @@ -13,3 +15,4 @@
api_bp.register_blueprint(watch_bp)
api_bp.register_blueprint(settings_bp)
api_bp.register_blueprint(profil_bp)
api_bp.register_blueprint(lib_bp)
45 changes: 45 additions & 0 deletions src/chocolate_app/routes/api/libraries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from flask import Blueprint, request

from chocolate_app import DB, scans
from chocolate_app.tables import Libraries, Users
from chocolate_app.routes.api.auth import token_required
from chocolate_app.utils.utils import generate_response, Codes

lib_bp = Blueprint("profil", __name__, url_prefix="/profil")


@lib_bp.route("/refresh/<lib_id>", methods=["GET", "POST"])
@token_required
def profil(current_user, lib_id):
if not current_user.account_type == "Admin":
return generate_response(Codes.NOT_LOGGED_IN, True)

lib = Libraries.query.filter_by(id=lib_id).first()

if not lib:
return generate_response(Codes.LIBRARY_NOT_FOUND, True)

library = lib.__dict__

type_to_call = {
"series": scans.getSeries,
"consoles": scans.getGames,
"others": scans.getOthersVideos,
"books": scans.getBooks,
"musics": scans.getMusics,
}

scanner = None
if library["type"] == "movies":
scanner = scans.MovieScanner()
scanner.set_library_name(library["name"])
scanner.scan()
elif library["type"] == "tv":
scanner = scans.LiveTVScanner()
scanner.set_library_name(library["name"])
scanner.scan()
else:
scanner = type_to_call[library["type"]]
scanner(library["name"])

return generate_response(Codes.SUCCESS, False, {"message": "Library refreshed"})

0 comments on commit 5cadc31

Please sign in to comment.