Music tracker

This commit is contained in:
2024-08-01 17:35:54 +02:00
parent 2c9c86990c
commit 5d51e99c70
2 changed files with 52 additions and 4 deletions
+17
View File
@@ -13,6 +13,13 @@ IN_COMM_Q = Queue()
awaiting_q = [] awaiting_q = []
incoming_q = Queue() incoming_q = Queue()
app = Flask(__name__) app = Flask(__name__)
prepped_tracks = {
"requests" : "",
"hits" : "",
"all": "",
"prio":"",
"jingles":""
}
class QueryControl: class QueryControl:
""" """
This class `QueryControl` is used to manage queries with information about the author, UUID, This class `QueryControl` is used to manage queries with information about the author, UUID,
@@ -30,6 +37,16 @@ class QueryControl:
) )
self.replies = [] self.replies = []
@app.route("/prepped_tracks", methods=["POST"])
def log_radio_tracks():
app.logger.info(request)
record = json.loads(request.data)
app.logger.info(record)
app.logger.info("DATA RECEIVED")
incoming_q.put(record)
return jsonify("SUCCESS")
@app.route("/conjurer", methods=["POST"]) @app.route("/conjurer", methods=["POST"])
def answer_external_command(): def answer_external_command():
""" """
+34 -3
View File
@@ -8,6 +8,7 @@ import json
import logging import logging
import os import os
import re import re
import requests
import threading import threading
import time import time
from datetime import datetime from datetime import datetime
@@ -18,6 +19,8 @@ from sys import platform
from flask import Flask, jsonify, redirect, request, send_from_directory, render_template from flask import Flask, jsonify, redirect, request, send_from_directory, render_template
from waitress import serve from waitress import serve
MAIN_BOT_ADDRESS = "http://192.168.1.191:5000"
MUSIC_TRACKER = "/prepped_tracks"
HOST_ADDRESS = "192.168.1.15" HOST_ADDRESS = "192.168.1.15"
PORT_ADDRESS = 5000 PORT_ADDRESS = 5000
if platform in ("linux", "linux2"): if platform in ("linux", "linux2"):
@@ -28,6 +31,7 @@ if platform in ("linux", "linux2"):
NETRC_FILE = "/home/mtuszowski/.netrc" NETRC_FILE = "/home/mtuszowski/.netrc"
LOGSTORE = "/home/mtuszowski/conjurer/logs/" LOGSTORE = "/home/mtuszowski/conjurer/logs/"
ENCODING = "utf-8" ENCODING = "utf-8"
RADIOLOG_PATH = '/home/pi/Conjurer/radio_log.log'
else: else:
LOGFILE = "/home/pi/Conjurer/discord_mus_service.log" LOGFILE = "/home/pi/Conjurer/discord_mus_service.log"
@@ -36,6 +40,7 @@ if platform in ("linux", "linux2"):
ENCODING = "utf-8" ENCODING = "utf-8"
MUSIC_FOLDER = "/home/pi/RetroPie/mp3/" MUSIC_FOLDER = "/home/pi/RetroPie/mp3/"
PRIORITY_FOLDER = "/home/pi/RetroPie/mp3/Magiczne i chuj/" PRIORITY_FOLDER = "/home/pi/RetroPie/mp3/Magiczne i chuj/"
RADIOLOG_PATH = '/home/pi/Conjurer/radio_log.log'
music_file_list = [] music_file_list = []
@@ -96,11 +101,10 @@ def scan_tracks():
#Set the filename and open the file #Set the filename and open the file
logger = logging.getLogger("conjurer_musician") logger = logging.getLogger("conjurer_musician")
filename = '/home/pi/Conjurer/radio_log.log' file = open(RADIOLOG_PATH,'r')
file = open(filename,'r')
#Find the size of the file and move to the end #Find the size of the file and move to the end
st_results = os.stat(filename) st_results = os.stat(RADIOLOG_PATH)
st_size = st_results[6] st_size = st_results[6]
file.seek(st_size) file.seek(st_size)
@@ -112,7 +116,34 @@ def scan_tracks():
file.seek(where) file.seek(where)
else: else:
if re.match(".*Prepared.*",line): if re.match(".*Prepared.*",line):
if re.match("*.jingles*.", line):
logger.info("jingles")
logger.info(line) # already has newline logger.info(line) # already has newline
result = ["jingles", line]
elif re.match("*.priority*.", line):
logger.info("priority")
logger.info(line) # already has newline
result = ["priority", line]
elif re.match("*.hit*.", line):
logger.info("priority")
logger.info(line) # already has newline
result = ["hit", line]
elif re.match("*.all_playlist*.", line):
logger.info("all")
logger.info(line) # already has newline
result = ["all", line]
elif re.match("*.request*.", line):
logger.info("requests")
logger.info(line) # already has newline
result = ["requests", line]
result = requests.post(
f"{MAIN_BOT_ADDRESS}{MUSIC_TRACKER}",
json=result,
timeout=360)
logger.info("SENT")
logger.info(result.status_code)
logger.info("SEND CONFIRMED")
time.sleep(1)
time.sleep(0.1) time.sleep(0.1)