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