mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 13:34:40 +00:00
Fixes
This commit is contained in:
@@ -7,8 +7,8 @@ API endpoints.
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import requests
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime
|
||||
@@ -16,7 +16,16 @@ from logging import handlers
|
||||
from pathlib import Path
|
||||
from platform import uname
|
||||
from sys import platform
|
||||
from flask import Flask, jsonify, redirect, request, send_from_directory, render_template
|
||||
|
||||
import requests
|
||||
from flask import (
|
||||
Flask,
|
||||
jsonify,
|
||||
redirect,
|
||||
render_template,
|
||||
request,
|
||||
send_from_directory,
|
||||
)
|
||||
from waitress import serve
|
||||
|
||||
MAIN_BOT_ADDRESS = "http://192.168.1.191:5000"
|
||||
@@ -31,8 +40,8 @@ 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'
|
||||
PERSISTENCE_PATH = '/home/pi/Conjurer/persistence.log'
|
||||
RADIOLOG_PATH = "/home/pi/Conjurer/radio_log.log"
|
||||
PERSISTENCE_PATH = "/home/pi/Conjurer/persistence.log"
|
||||
|
||||
else:
|
||||
LOGFILE = "/home/pi/Conjurer/discord_mus_service.log"
|
||||
@@ -41,13 +50,14 @@ 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'
|
||||
PERSISTENCE_PATH = '/home/pi/Conjurer/persistence.log'
|
||||
|
||||
RADIOLOG_PATH = "/home/pi/Conjurer/radio_log.log"
|
||||
PERSISTENCE_PATH = "/home/pi/Conjurer/persistence.log"
|
||||
|
||||
random.seed()
|
||||
music_file_list = []
|
||||
priority_list = []
|
||||
|
||||
|
||||
def rescan():
|
||||
"""
|
||||
The `rescan` function logs a message, scans for mp3 files in a specified folder,
|
||||
@@ -69,8 +79,8 @@ def rescan():
|
||||
priority_list.append(temp_music_file)
|
||||
|
||||
with open(
|
||||
"/home/pi/Conjurer/all_playlist.playlist", "w", encoding="utf-8"
|
||||
) as w_file:
|
||||
"/home/pi/Conjurer/all_playlist.playlist", "w", encoding="utf-8"
|
||||
) as w_file:
|
||||
try:
|
||||
for item in music_file_list:
|
||||
w_file.write(item)
|
||||
@@ -100,11 +110,11 @@ def thread_rescan():
|
||||
|
||||
|
||||
def scan_tracks():
|
||||
#Set the filename and open the file
|
||||
# Set the filename and open the file
|
||||
logger = logging.getLogger("conjurer_musician")
|
||||
|
||||
file = open(RADIOLOG_PATH,'r')
|
||||
#Find the size of the file and move to the end
|
||||
file = open(RADIOLOG_PATH, "r")
|
||||
# Find the size of the file and move to the end
|
||||
st_results = os.stat(RADIOLOG_PATH)
|
||||
st_size = st_results[6]
|
||||
file.seek(st_size)
|
||||
@@ -121,14 +131,13 @@ def scan_tracks():
|
||||
st_results1 = os.stat(PERSISTENCE_PATH)
|
||||
st_size1 = st_results1[6]
|
||||
time.sleep(0.1)
|
||||
file1 = open(PERSISTENCE_PATH, 'r')
|
||||
file1 = open(PERSISTENCE_PATH, "r")
|
||||
lines = file1.readlines()
|
||||
result = ["next", lines[2]]
|
||||
file1.close()
|
||||
returned = requests.post(
|
||||
f"{MAIN_BOT_ADDRESS}{MUSIC_TRACKER}",
|
||||
json=result,
|
||||
timeout=360)
|
||||
f"{MAIN_BOT_ADDRESS}{MUSIC_TRACKER}", json=result, timeout=360
|
||||
)
|
||||
logger.info("SENT")
|
||||
logger.info(returned.status_code)
|
||||
logger.info("SEND CONFIRMED")
|
||||
@@ -139,33 +148,32 @@ def scan_tracks():
|
||||
time.sleep(1)
|
||||
file.seek(where)
|
||||
else:
|
||||
if re.match(".*Prepared.*",line):
|
||||
if re.match(".*Prepared.*", line):
|
||||
result = None
|
||||
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
|
||||
logger.info(line) # already has newline
|
||||
result = ["priority", line]
|
||||
elif re.match(".*hit.*", line):
|
||||
logger.info("hit")
|
||||
logger.info(line) # already has newline
|
||||
logger.info(line) # already has newline
|
||||
result = ["hit", line]
|
||||
elif re.match(".*all_playlist.*", line):
|
||||
logger.info("all")
|
||||
logger.info(line) # already has newline
|
||||
logger.info(line) # already has newline
|
||||
result = ["all", line]
|
||||
elif re.match(".*request.*", line):
|
||||
logger.info("requests")
|
||||
logger.info(line) # already has newline
|
||||
logger.info(line) # already has newline
|
||||
result = ["requests", line]
|
||||
if result:
|
||||
returned = requests.post(
|
||||
f"{MAIN_BOT_ADDRESS}{MUSIC_TRACKER}",
|
||||
json=result,
|
||||
timeout=360)
|
||||
f"{MAIN_BOT_ADDRESS}{MUSIC_TRACKER}", json=result, timeout=360
|
||||
)
|
||||
logger.info("SENT")
|
||||
logger.info(returned.status_code)
|
||||
logger.info("SEND CONFIRMED")
|
||||
@@ -330,9 +338,10 @@ def stream_music():
|
||||
: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")
|
||||
# return send_from_directory("/tmp/hls", "stream.m3u8")
|
||||
return render_template("/home/pi/Conjurer/stream.html")
|
||||
|
||||
|
||||
@app.route("/<string:file_name>")
|
||||
def stream(file_name):
|
||||
"""
|
||||
@@ -348,6 +357,7 @@ def stream(file_name):
|
||||
video_dir = "/tmp/hls"
|
||||
return send_from_directory(video_dir, file_name)
|
||||
|
||||
|
||||
@app.route("/stream_mp3", methods=["GET"])
|
||||
def stream_music_mp3():
|
||||
"""
|
||||
@@ -367,8 +377,10 @@ def clear_pr_pls():
|
||||
:return: A JSON response indicating the success of the operation.
|
||||
"""
|
||||
app.logger.info("CLEARING PLAYLIST")
|
||||
with open('/home/pi/Conjurer/priority_queue.playlist', 'w', encoding='utf-8') as cleared_pl:
|
||||
cleared_pl.write('')
|
||||
with open(
|
||||
"/home/pi/Conjurer/priority_queue.playlist", "w", encoding="utf-8"
|
||||
) as cleared_pl:
|
||||
cleared_pl.write("")
|
||||
|
||||
return_data = jsonify(isError=False, message="Success", statusCode=200, data=[])
|
||||
return return_data, 200
|
||||
@@ -438,21 +450,20 @@ def add_request():
|
||||
app.logger.info(record)
|
||||
app.logger.info(record["lista_slow"])
|
||||
app.logger.info(record["UUID"])
|
||||
return_data = wyszukaj(
|
||||
record["lista_slow"], 0, app.logger, False
|
||||
)
|
||||
return_data = wyszukaj(record["lista_slow"], 0, app.logger, False)
|
||||
|
||||
with open(
|
||||
"/home/pi/Conjurer/request.playlist", "a", encoding="utf-8"
|
||||
) as s_file:
|
||||
with open("/home/pi/Conjurer/request.playlist", "a", encoding="utf-8") as s_file:
|
||||
for item in return_data:
|
||||
s_file.write(item[1] + "\n")
|
||||
return_data = (
|
||||
jsonify(isError=False, message="Success", statusCode=200, data={"status": "OK"}),
|
||||
jsonify(
|
||||
isError=False, message="Success", statusCode=200, data={"status": "OK"}
|
||||
),
|
||||
200,
|
||||
)
|
||||
return return_data
|
||||
|
||||
|
||||
@app.route("/create_priority_playlist", methods=["POST"])
|
||||
def create_priority_playlist():
|
||||
"""
|
||||
@@ -474,13 +485,14 @@ def create_priority_playlist():
|
||||
return_data = wyszukaj(
|
||||
record["lista_slow"], record["dlugosc_plejlisty"], app.logger, False
|
||||
)
|
||||
with open(
|
||||
"/home/pi/Conjurer/request.playlist", "a", encoding="utf-8"
|
||||
) as s_file:
|
||||
return_data = random.shuffle(return_data)
|
||||
with open("/home/pi/Conjurer/request.playlist", "a", encoding="utf-8") as s_file:
|
||||
for item in return_data:
|
||||
s_file.write(item[1] + "\n")
|
||||
return_data = (
|
||||
jsonify(isError=False, message="Success", statusCode=200, data={"status": "OK"}),
|
||||
jsonify(
|
||||
isError=False, message="Success", statusCode=200, data={"status": "OK"}
|
||||
),
|
||||
200,
|
||||
)
|
||||
return return_data
|
||||
@@ -513,7 +525,9 @@ def add_to_priority():
|
||||
for item in return_data:
|
||||
s_file.write(item[1] + "\n")
|
||||
return_data = (
|
||||
jsonify(isError=False, message="Success", statusCode=200, data={"status": "OK"}),
|
||||
jsonify(
|
||||
isError=False, message="Success", statusCode=200, data={"status": "OK"}
|
||||
),
|
||||
200,
|
||||
)
|
||||
return return_data
|
||||
|
||||
Reference in New Issue
Block a user