Track name broadcast att 1

This commit is contained in:
2024-07-29 14:20:11 +02:00
parent b87cf7f4d8
commit 2c9c86990c
+31 -3
View File
@@ -6,6 +6,7 @@ API endpoints.
"""
import json
import logging
import os
import re
import threading
import time
@@ -45,7 +46,8 @@ 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")
logger = logging.getLogger("conjurer_musician")
logger.info("Rescan triggered")
for mp3_item in Path.glob(Path(MUSIC_FOLDER), "**/*.mp3"):
temp_music_file = mp3_item.as_posix()
@@ -82,13 +84,38 @@ def thread_rescan():
The `thread_rescan` function periodically triggers a rescan operation after a specified time
interval.
"""
logging.info("Starting filesystemupdater")
logger = logging.getLogger("conjurer_musician")
logger.info("Starting filesystemupdater")
while True:
time.sleep(60 * 60 * 24)
logging.info("Rescan triggered")
logger.info("Rescan triggered")
rescan()
def scan_tracks():
#Set the filename and open the file
logger = logging.getLogger("conjurer_musician")
filename = '/home/pi/Conjurer/radio_log.log'
file = open(filename,'r')
#Find the size of the file and move to the end
st_results = os.stat(filename)
st_size = st_results[6]
file.seek(st_size)
while 1:
where = file.tell()
line = file.readline()
if not line:
time.sleep(1)
file.seek(where)
else:
if re.match(".*Prepared.*",line):
logger.info(line) # already has newline
time.sleep(0.1)
app = Flask(__name__)
@@ -485,6 +512,7 @@ if __name__ == "__main__":
# threads.append(threading.Thread(target=flask_debug))
threads.append(threading.Thread(target=waitress_run))
threads.append(threading.Thread(target=thread_rescan))
threads.append(threading.Thread(target=scan_tracks))
for worker in threads:
worker.start()