diff --git a/conjurer_musician/conjurer_musician.py b/conjurer_musician/conjurer_musician.py index 815c738..4b8b815 100644 --- a/conjurer_musician/conjurer_musician.py +++ b/conjurer_musician/conjurer_musician.py @@ -278,14 +278,24 @@ def remove_characters(string, character): @app.route("/stream", methods=["GET"]) def stream_music(): """ - 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`. + The function `stream_music` is a route handler for the "/stream" endpoint. + It returns a JSON response containing a key "music_file_list" with the value of the variable `music_file_list`. + + :return: A JSON response containing a key "music_file_list" with the value of the variable `music_file_list`. """ return send_from_directory("/tmp/hls", "stream.m3u8") @app.route('/') def stream(file_name): + """ + Stream the specified file from the video directory. + + Args: + file_name (str): The name of the file to be streamed. + + Returns: + Response: The response containing the streamed file. + """ video_dir = '/tmp/hls' return send_from_directory(video_dir, file_name) @@ -293,9 +303,10 @@ def stream(file_name): @app.route("/stream_mp3", methods=["GET"]) def stream_music_mp3(): """ - 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`. + The function `stream_music_mp3` is a route handler for the "/stream_mp3" endpoint. + It redirects the user to the URL "http://www.example.com" with a status code of 302. + + :return: A redirect response to "http://www.example.com" with a status code of 302. """ return redirect("http://www.example.com", code=302) @@ -303,9 +314,9 @@ def stream_music_mp3(): @app.route("/clear_pr_pls", methods=["GET"]) def clear_pr_pls(): """ - 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`. + The function `clear_pr_pls` clears the contents of the priority queue playlist file. + + :return: A JSON response indicating the success of the operation. """ with open( "/home/pi/Conjurer/priority_queue.playlist", "w", encoding="utf-8" @@ -350,13 +361,13 @@ def update_music_list(): @app.route("/get_music", methods=["POST"]) def look_for_playlist(): """ - The function `update_music_list` receives a POST request with a JSON payload, logs the received + The function `look_for_playlist` 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. + + :return: 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) @@ -374,13 +385,13 @@ def look_for_playlist(): @app.route("/add_to_priority", methods=["POST"]) def add_to_priority(): """ - The function `update_music_list` receives a POST request with a JSON payload, logs the received + The function `add_to_priority` 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. + + :return: 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) @@ -407,8 +418,18 @@ def flask_debug(): def waitress_run(): """ - The `waitress_run` function serves the `app` on host "0.0.0.0" + The `waitress_run` function serves the `app` on host HOST_ADDRESS and port 5000 using the Waitress WSGI server. + + This function starts the Waitress server and listens for incoming requests + on the specified host and port. It uses the `serve` function from the Waitress + library to handle the serving process. + + Parameters: + None + + Returns: + None """ serve(app, host=HOST_ADDRESS, port=PORT_ADDRESS)