diff --git a/VERSION b/VERSION index 17e51c3..d917d3e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.1 +0.1.2 diff --git a/server.py b/server.py index 010299d..1721050 100755 --- a/server.py +++ b/server.py @@ -62,6 +62,16 @@ class WatchHistory(Base): ) +class SavedQueue(Base): + __tablename__ = "saved_queue" + sqid = Column(Integer, primary_key=True, autoincrement=True) + video_url = Column(String(255), nullable=False) + created_date = Column(DateTime, nullable=False, server_default=func.now()) + created_by = Column( + String(100), nullable=False, server_default="mpv-youtube-queue-server" + ) + + # Ensure tables exist Base.metadata.create_all(engine) @@ -87,6 +97,36 @@ def send_to_mpv(command): return False +@app.route("/save_queue", methods=["POST"]) +def save_queue(): + data = request.get_json() + if data is None or "urls" not in data: + logging.error("Invalid JSON data") + return jsonify(message="Invalid JSON data"), 400 + logging.debug(f"Received data: {data}") + urls = data.get("urls") + logging.debug("Truncating saved queue") + session.query(SavedQueue).delete() + for url in urls: + logging.debug(f"Adding {url} to the saved queue") + new_entry = SavedQueue(video_url=url) + try: + session.add(new_entry) + except exc.SQLAlchemyError as e: + logging.error(f"Failed to insert data into database: {e}") + return jsonify(message="Failed to add data to database"), 500 + session.commit() + return jsonify(message="Data added to saved queue"), 200 + + +@app.route("/load_queue", methods=["GET"]) +def load_queue(): + logging.debug("Loading saved queue") + urls = [entry.video_url for entry in session.query(SavedQueue).all()] + logging.debug(f"Loaded {len(urls)} URLs from the saved queue") + return jsonify(urls), 200 + + @app.route("/add_video", methods=["POST"]) def add_video(): data = request.get_json()