asdasdasd

:)

asa

asdasda

aa

:)

asa

aa

:)

:)

sa

as

aa

aa

aa

aaa

as

11

aa

11

xxx

dd

ds

aa

a1

aa

Test

Suppress

Move

Installer

aaa

Serwis

`12`

aa

xd

asasa

xd

aa

asa

aaa

:)

Hejka

a

xd

aa

aaas

555

aaa

asa

aa

11

aaa

aaa

as

sa

async

asda

00

123

123

aa

as

ss

as

a

sa

aa

1

RES

T

Hejko

aa

11

AA

test

Test
This commit is contained in:
2024-03-29 20:19:21 +01:00
committed by migatu
parent 211c45891e
commit 6c9f01971a
14 changed files with 3047 additions and 21 deletions
+75 -15
View File
@@ -1,11 +1,21 @@
"""
The provided Python script sets up a Flask web server to manage a list of music files, with
functions for rescanning the music folder, updating the music list, and serving the music list via
API endpoints.
"""
import json
from pathlib import Path
from platform import uname
import threading
import time
from sys import platform
import logging
from flask import Flask, jsonify, request
from waitress import serve
MUSIC_FOLDER = ""
HOST_ADDRESS = "192.168.1.15"
PORT_ADDRESS = 5000
if platform in ("linux", "linux2"):
SEPARATOR_FILE_PATH = "/"
if "microsoft-standard" in uname().release:
@@ -30,24 +40,54 @@ if platform in ("linux", "linux2"):
GRAPHICS_PATH = "/home/pi/RetroPie/Conjurer_graphics/"
DIR_PATH_SADOX = "/home/pi/RetroPie/Fansadox/"
music_file_list = []
for mp3_item in Path.glob(Path(MUSIC_FOLDER), "**/*.mp3"):
temp_music_file = mp3_item.as_posix()
if platform == "win32":
temp_music_file = temp_music_file.replace("/", "\\")
music_file_list.append(temp_music_file)
def rescan():
"""
The `rescan` function logs a message, scans for mp3 files in a specified folder,
and adds them to a list of music files.
"""
logging.info("Rescan triggered")
for mp3_item in Path.glob(Path(MUSIC_FOLDER), "**/*.mp3"):
temp_music_file = mp3_item.as_posix()
if platform == "win32":
temp_music_file = temp_music_file.replace("/", "\\")
music_file_list.append(temp_music_file)
def thread_rescan():
"""
The `thread_rescan` function periodically triggers a rescan operation after a specified time
interval.
"""
logging.info("Starting filesystemupdater")
while True:
time.sleep(60*60*24)
logging.info("Rescan triggered")
rescan()
app = Flask(__name__)
@app.route("/mp3", methods=["GET"])
def get_music_list():
"""
The function `get_music_list` returns a JSON object containing a list of music files.
:return: A JSON response containing a key "music_file_list" with the value of the variable
`music_file_list`.
"""
return jsonify({"music_file_list": music_file_list})
# TODO: Przyjecie informacji o zmianie i dodanie pliku saute
@app.route("/update_mp3", methods=["POST"])
def update_music_list():
"""
The function `update_music_list` receives a POST request with a JSON payload, logs the received
item, adds it to a music file list, and returns a success message along with the updated record.
:return: The function `update_music_list` is returning a tuple containing a JSON response and a
status code. The JSON response includes keys `isError`, `message`, `statusCode`, and `data`,
with values indicating the success of the operation and the data that was
received and added to the `music_file_list`.
The status code returned is 200, indicating a successful response.
"""
record = json.loads(request.data)
app.logger.info(record["item"])
music_file_list.append(record["item"])
@@ -57,14 +97,34 @@ def update_music_list():
)
return return_data
def flask_debug():
"""
The `flask_debug` function starts a Flask application in debug mode without using the reloader.
Do not use for production for fucks sake.
"""
# trunk-ignore(bandit/B201)
app.run(debug=True, use_reloader=False, host=HOST_ADDRESS, port=PORT_ADDRESS)
def waitress_run():
"""
The `waitress_run` function serves the `app` on host "0.0.0.0"
and port 5000 using the Waitress WSGI server.
"""
serve(app, host=HOST_ADDRESS, port=PORT_ADDRESS)
if __name__ == "__main__":
#app.run(debug=True, host="0.0.0.0")
from waitress import serve
serve(app, host="0.0.0.0", port=5000)
logger = logging.getLogger('conjurer_musician')
logger.setLevel(logging.DEBUG)
rescan()
threads = []
threads.append(threading.Thread(target=waitress_run))
threads.append(threading.Thread(target=thread_rescan))
#threads.append(threading.Thread(target=flask_debug))
# TODO: Reskan co 24h
for worker in threads:
worker.start()
# TODO: Informacja o zmianie i update
for worker in threads:
worker.join()
# TODO: Move download Youtube i Spotify tutaj (bedzie potrzebny wtedy rest w obie strony)
#TODO: Inne pliki - sadox, dokumenty naukowe itp.