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
+35 -4
View File
@@ -8,6 +8,7 @@ import json
import logging
import os
import re
import requests
import threading
import time
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 waitress import serve
MAIN_BOT_ADDRESS = "http://192.168.1.191:5000"
MUSIC_TRACKER = "/prepped_tracks"
HOST_ADDRESS = "192.168.1.15"
PORT_ADDRESS = 5000
if platform in ("linux", "linux2"):
@@ -28,6 +31,7 @@ if platform in ("linux", "linux2"):
NETRC_FILE = "/home/mtuszowski/.netrc"
LOGSTORE = "/home/mtuszowski/conjurer/logs/"
ENCODING = "utf-8"
RADIOLOG_PATH = '/home/pi/Conjurer/radio_log.log'
else:
LOGFILE = "/home/pi/Conjurer/discord_mus_service.log"
@@ -36,6 +40,7 @@ if platform in ("linux", "linux2"):
ENCODING = "utf-8"
MUSIC_FOLDER = "/home/pi/RetroPie/mp3/"
PRIORITY_FOLDER = "/home/pi/RetroPie/mp3/Magiczne i chuj/"
RADIOLOG_PATH = '/home/pi/Conjurer/radio_log.log'
music_file_list = []
@@ -96,11 +101,10 @@ 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')
file = open(RADIOLOG_PATH,'r')
#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]
file.seek(st_size)
@@ -112,7 +116,34 @@ def scan_tracks():
file.seek(where)
else:
if re.match(".*Prepared.*",line):
logger.info(line) # already has newline
if re.match("*.jingles*.", line):
logger.info("jingles")
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)