mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
Installer
This commit is contained in:
@@ -203,6 +203,14 @@ class MusicFileList(object):
|
||||
"""
|
||||
return self.music_file_list
|
||||
def update_file_list(self,item):
|
||||
"""
|
||||
The `update_file_list` function appends an item to a music file list and sends a POST request with
|
||||
the item data to a file service address.
|
||||
|
||||
:param item: The `item` parameter in the `update_file_list` method is the file that you want to add
|
||||
to the `music_file_list` attribute of the class instance. It is then sent as a JSON payload in a
|
||||
POST request to a file service address along with the endpoint `SEND_MP3`
|
||||
"""
|
||||
self.music_file_list.append(item)
|
||||
post_data = {"item" : str(item)}
|
||||
requests.post(f'{FILE_SERVICE_ADDRESS}{SEND_MP3}', json=post_data, timeout = 360)
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
# trunk-ignore-all(pylint/C0301)
|
||||
"""
|
||||
The function `cut_my_life_into_pieces` reads a source file, splits its content based on a file size
|
||||
limit, and writes the parts to separate output files in a specified folder.
|
||||
|
||||
:param lines: The `lines` parameter in the `smart_write` function is a string that contains the text
|
||||
content that you want to write to a file. It represents the actual content that will be written to
|
||||
the file
|
||||
:param file: The code you provided defines two functions: `smart_write` and
|
||||
`cut_my_life_into_pieces`. The `smart_write` function encodes input lines to UTF-8, writes them to a
|
||||
file, and returns the size of the encoded bytes. The `cut_my_life_into_pieces` function reads
|
||||
:return: The functions provided in the code snippet do not explicitly return any values. However,
|
||||
the `smart_write` function returns the size of the encoded bytes of the input `lines` in bytes. The
|
||||
`cut_my_life_into_pieces` function does not have a return statement, so it does not explicitly
|
||||
return any value.
|
||||
"""
|
||||
|
||||
FILE_SIZE_LIMIT = 100000 * 1024
|
||||
SOURCE = "/mnt/n/scimag_2020-05-30.sql/scimag_2020-05-30.sql"
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
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
|
||||
@@ -8,6 +13,9 @@ import logging
|
||||
from flask import Flask, jsonify, request
|
||||
from waitress import serve
|
||||
|
||||
|
||||
HOST_ADDRESS = "192.168.1.15"
|
||||
PORT_ADDRESS = 5000
|
||||
if platform in ("linux", "linux2"):
|
||||
SEPARATOR_FILE_PATH = "/"
|
||||
if "microsoft-standard" in uname().release:
|
||||
@@ -35,6 +43,10 @@ if platform in ("linux", "linux2"):
|
||||
|
||||
music_file_list = []
|
||||
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()
|
||||
@@ -43,6 +55,10 @@ def rescan():
|
||||
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)
|
||||
@@ -53,11 +69,25 @@ 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})
|
||||
|
||||
|
||||
@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"])
|
||||
@@ -68,10 +98,19 @@ def update_music_list():
|
||||
return return_data
|
||||
|
||||
def flask_debug():
|
||||
app.run(debug=True, use_reloader=False, host='0.0.0.0', port=5000)
|
||||
"""
|
||||
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():
|
||||
serve(app, host="0.0.0.0", port=5000)
|
||||
"""
|
||||
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__":
|
||||
logger = logging.getLogger('conjurer_musician')
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
python3 -m venv /home/pi/Conjurer-service/conjurer/file_webservice
|
||||
source ./bin/activate
|
||||
./bin/python3 -m pip install --upgrade pip
|
||||
./bin/python3 -m pip install -r requirements_musician.txt
|
||||
deactivate
|
||||
|
||||
sudo cp ./conjurer_musician.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl start conjurer_musician.service
|
||||
sudo systemctl enable conjurer_musician.service
|
||||
@@ -0,0 +1,2 @@
|
||||
flask
|
||||
waitress
|
||||
@@ -2,8 +2,11 @@
|
||||
python3 -m venv /home/pi/Conjurer/env
|
||||
source ./env/bin/activate
|
||||
./env/bin/python3 -m pip install --upgrade pip
|
||||
./env/bin/python3 -m pip install -r requirements.txt
|
||||
./env/bin/python3 -m pip install -r requirements_bot.txt
|
||||
sed -i -e 's/os.rename/shutil.copy/g' ./env/lib/python3.11/site-packages/spotify_dl/youtube.py
|
||||
sed -i '1i\import shutil' ./env/lib/python3.11/site-packages/spotify_dl/youtube.py
|
||||
deactivate
|
||||
sudo systemctl restart conjurer.service
|
||||
sudo cp ./conjurer.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl start conjurer_musician.service
|
||||
sudo systemctl enable conjurer_musician.service
|
||||
Reference in New Issue
Block a user