Compare commits

...

27 Commits

Author SHA1 Message Date
gitea 215a36f91e Fx 2024-08-09 17:10:14 +02:00
gitea ecabfc8876 fx 2024-08-09 17:06:01 +02:00
gitea 20f045e92a fx 2024-08-09 17:03:15 +02:00
gitea c90e90ea10 Port fix 2024-08-09 17:02:05 +02:00
gitea fcefaf11ef Fixing time mismatch 2024-08-09 16:59:33 +02:00
gitea 8c6e80d832 Fix 2024-08-09 16:53:17 +02:00
gitea 96b93488c7 1 2024-08-09 16:47:35 +02:00
gitea c31390859f Metadata 2024-08-09 16:43:52 +02:00
gitea 314a77c1f9 Fx 2024-08-05 11:24:13 +02:00
gitea 0345573cb8 fx 2024-08-03 16:38:42 +02:00
gitea 4842ccdc22 Music trackin upgrade 2024-08-03 15:34:56 +02:00
gitea adb0f9b468 fx 2024-08-02 20:27:27 +02:00
gitea ce806c873f Fx 2024-08-02 20:19:21 +02:00
gitea a54a6686c2 fx 2024-08-02 20:02:02 +02:00
gitea d226d99236 bgfx 2024-08-02 19:57:56 +02:00
gitea a827c5e429 Fix tracker 2024-08-02 19:22:25 +02:00
gitea 71d8e03933 fx 2024-08-02 12:32:44 +02:00
gitea 803ad01a83 bgfx 2024-08-02 12:12:12 +02:00
gitea 81d5fcfb8f Now playing 2024-08-02 12:10:55 +02:00
gitea 4d79c51e20 Fx frmt 2024-08-02 12:07:17 +02:00
gitea f320b20850 fx frmt 2024-08-02 12:02:21 +02:00
gitea c39900e15f Fx frmt 2024-08-02 12:01:05 +02:00
gitea c728396205 tst fx 2024-08-02 11:58:51 +02:00
gitea 0f7e5d4a25 Fix 2024-08-02 11:53:03 +02:00
gitea ce91aec6ff Fix 2024-08-02 11:50:54 +02:00
gitea 759c06aa50 Buffx 2024-08-02 11:47:13 +02:00
gitea 1ebd58b8ac UPdate for music tracker 2024-08-02 11:43:38 +02:00
3 changed files with 108 additions and 22 deletions
+25 -5
View File
@@ -47,6 +47,7 @@ from communication_subroutine import (
OUT_COMM_Q, OUT_COMM_Q,
QueryControl, QueryControl,
comm_subroutine, comm_subroutine,
PREPPED_TRACKS,
) )
from spotify_dl import spotify from spotify_dl import spotify
from spotify_dl import youtube as youtube_download from spotify_dl import youtube as youtube_download
@@ -2388,7 +2389,7 @@ async def wyszukaj_linki_do_dokumentow(ctx):
username = ctx.message.author.nick username = ctx.message.author.nick
else: else:
username = ctx.message.author.name username = ctx.message.author.name
query_object = QueryControl(username, query_uuid, query, logger, ctx) query_object = QueryControl(username, query_uuid, query, ctx)
OUT_COMM_Q.put(query_object) OUT_COMM_Q.put(query_object)
await ctx.send( await ctx.send(
f"No dobra poszło. Zapamiętaj proszę {query_uuid} - to identyfikator twojego zapytania. Jesteś {queue_size} w kolejce." f"No dobra poszło. Zapamiętaj proszę {query_uuid} - to identyfikator twojego zapytania. Jesteś {queue_size} w kolejce."
@@ -2483,7 +2484,7 @@ async def wyszukaj_linki_do_dokumentow_deep(ctx):
username = ctx.message.author.nick username = ctx.message.author.nick
else: else:
username = ctx.message.author.name username = ctx.message.author.name
query_object = QueryControl(username, query_uuid, query, logger, ctx) query_object = QueryControl(username, query_uuid, query, ctx)
OUT_COMM_Q.put(query_object) OUT_COMM_Q.put(query_object)
await ctx.send( await ctx.send(
f"Wypij wypi {query_uuid} - to identyfikator twojego zapytania. Jesteś {queue_size} w kolejce niestety kolejka obowiazuje zawsze." f"Wypij wypi {query_uuid} - to identyfikator twojego zapytania. Jesteś {queue_size} w kolejce niestety kolejka obowiazuje zawsze."
@@ -2520,10 +2521,29 @@ async def krecimy_pornola(ctx):
sciezka, files = await get_file(ctx, "Pornol", item_yt) sciezka, files = await get_file(ctx, "Pornol", item_yt)
if files: if files:
logger.info("Pornol udany") logger.info("Pornol udany")
ctx.send(f"Jest w tajnym archiwum pod adresem{sciezka})") await ctx.send(f"Jest w tajnym archiwum pod adresem{sciezka})")
else: else:
ctx.reply("Jak ładnie szefa poprosisz.") await ctx.reply("Jak ładnie szefa poprosisz.")
@client.hybrid_command(
name="co_na_plejliscie_wariacie",
description="Wyswietl kawalki ktore sa na pocztku list radia",
guild=discord.Object(id=664789470779932693),
)
async def co_na_plejliscie_wariacie(ctx):
"""
Download a music number from youtube.
:param ctx: ctx stands for "context" and is a parameter commonly used in Discord.py commands. It
represents the context in which the command was invoked, including information such as the message,
the channel, the server, and the user who invoked the command. It allows the command to interact
with the Discord API and
"""
await ctx.send("Dej mnie chwilkę")
async with ctx.typing():
logger.info("plejlista")
logger.info(PREPPED_TRACKS)
await ctx.send(f"Didżej Hammer i jego sztuczna inteligencja (||he he||) prezentują: \n- obecnie grany jest {(PREPPED_TRACKS['now_playing']).rstrip()} (wg metadanych: {PREPPED_TRACKS['meta']}) \n- następny będzie{(PREPPED_TRACKS['next']).rstrip()} \n- na liście priorytetowej {(PREPPED_TRACKS['priority']).rstrip()} \n- na liście hitów obecnie czeka kawałek {(PREPPED_TRACKS['hit']).rstrip()} \n- na liście wszystkich kawałków {(PREPPED_TRACKS['all']).rstrip()} \n- najświeższym zamówieniem od słuchaczy jest {(PREPPED_TRACKS['requests']).rstrip()} \nZ kolei jingiel to: {(PREPPED_TRACKS['jingles']).rstrip()}")
# *================================== Run # *================================== Run
if __name__ == "__main__": if __name__ == "__main__":
@@ -2531,7 +2551,7 @@ if __name__ == "__main__":
threads = [] threads = []
logger.info("Starting discord bot: Creating threads") logger.info("Starting discord bot: Creating threads")
threads.append(threading.Thread(target=client.run, args=(TOKEN,))) threads.append(threading.Thread(target=client.run, args=(TOKEN,)))
threads.append(threading.Thread(target=comm_subroutine, args=(logger,))) threads.append(threading.Thread(target=comm_subroutine))
logger.info("Starting discord bot: Starting threads") logger.info("Starting discord bot: Starting threads")
WRK_CNT = 0 WRK_CNT = 0
for worker in threads: for worker in threads:
+50 -11
View File
@@ -2,24 +2,34 @@ import logging
import threading import threading
import json import json
import time import time
import re
from urllib import request as urequest
from queue import Queue, Empty from queue import Queue, Empty
from flask import Flask, jsonify, request from flask import Flask, jsonify, request
from waitress import serve from waitress import serve
HOST_ADDRESS = "192.168.1.191" HOST_ADDRESS = "192.168.1.191"
PORT_ADDRESS = 5000 PORT_ADDRESS = 5000
ICECAST_ADDRESS = "http://192.168.1.15:8000"
OUT_COMM_Q = Queue() OUT_COMM_Q = Queue()
IN_COMM_Q = Queue() IN_COMM_Q = Queue()
SRCHTITLE = re.compile(br'StreamTitle=\\*(?P<title>[^;]*);').search
awaiting_q = [] awaiting_q = []
incoming_q = Queue() incoming_q = Queue()
app = Flask(__name__) app = Flask(__name__)
prepped_tracks = { PREPPED_TRACKS = {
"requests" : "", "requests" : "",
"hits" : "", "hit" : "",
"all": "", "all": "",
"prio":"", "priority":"",
"jingles":"" "jingles":"",
"now_playing":"",
"next": "",
"meta" : ""
} }
logger = logging.getLogger("discord")
class QueryControl: class QueryControl:
""" """
@@ -40,12 +50,20 @@ class QueryControl:
@app.route("/prepped_tracks", methods=["POST"]) @app.route("/prepped_tracks", methods=["POST"])
def log_radio_tracks(): def log_radio_tracks():
logger = logging.getLogger("discord") app.logger = logging.getLogger("discord")
logger.info(request) app.logger.info(request)
record = json.loads(request.data) record = json.loads(request.data)
logger.info(record) app.logger.info(record)
logger.info("DATA RECEIVED") if "next" in record[0]:
metadata = id3(ICECAST_ADDRESS)
PREPPED_TRACKS["now_playing"] = PREPPED_TRACKS["next"]
if metadata:
PREPPED_TRACKS["meta"] = metadata["name"] + " - " + metadata["title"] + "(" + metadata["genre"] + ")"
else:
PREPPED_TRACKS["meta"] = "Nie znaju"
PREPPED_TRACKS[record[0]] = record[1]
app.logger.info("DATA RECEIVED")
return jsonify("SUCCESS") return jsonify("SUCCESS")
@@ -144,8 +162,30 @@ def scan_incoming():
except Empty: except Empty:
time.sleep(1) time.sleep(1)
def get_stream_title(tag:bytes) -> str:
title = ''
if m := SRCHTITLE(tag):
#decode, strip, unescape and remove surrounding quotes (may not even be the same type of quote)
title = m.group('title').decode('utf-8').strip().replace('\\', '')[1:-1]
return title
def comm_subroutine(logger): def id3(url:str) -> dict:
request = urequest.Request(url, headers={'Icy-MetaData': 1})
with urequest.urlopen(request) as resp:
metaint = int(resp.headers.get('icy-metaint', '-1'))
if metaint<0:
return False
resp.read(metaint) #this isn't seekable so, arbitrarily read to the point we want
tagdata = dict(
site_url = resp.headers.get('icy-url' ) ,
name = resp.headers.get('icy-name' ).title(),
genre = resp.headers.get('icy-genre').title(),
title = get_stream_title(resp.read(255)) )
return tagdata
def comm_subroutine():
""" """
The `comm_subroutine` function starts multiple threads to run different tasks concurrently. The `comm_subroutine` function starts multiple threads to run different tasks concurrently.
@@ -169,5 +209,4 @@ def comm_subroutine(logger):
worker.join() worker.join()
if __name__ == "__main__": if __name__ == "__main__":
logging_client = logging.getLogger(__name__) comm_subroutine()
comm_subroutine(logging_client)
+33 -6
View File
@@ -32,6 +32,7 @@ if platform in ("linux", "linux2"):
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'
else: else:
LOGFILE = "/home/pi/Conjurer/discord_mus_service.log" LOGFILE = "/home/pi/Conjurer/discord_mus_service.log"
@@ -41,6 +42,7 @@ if platform in ("linux", "linux2"):
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'
music_file_list = [] music_file_list = []
@@ -102,13 +104,35 @@ def scan_tracks():
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)
st_results1 = os.stat(PERSISTENCE_PATH)
prev_st_size1 = st_results[6]
while 1: while 1:
st_results1 = os.stat(PERSISTENCE_PATH)
st_size1 = st_results1[6]
if prev_st_size1 != st_size1:
while prev_st_size1 != st_size1:
prev_st_size1 = st_size1
st_results1 = os.stat(PERSISTENCE_PATH)
st_size1 = st_results1[6]
time.sleep(0.1)
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)
logger.info("SENT")
logger.info(returned.status_code)
logger.info("SEND CONFIRMED")
where = file.tell() where = file.tell()
line = file.readline() line = file.readline()
if not line: if not line:
@@ -126,7 +150,7 @@ def scan_tracks():
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("priority") 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):
@@ -142,9 +166,9 @@ def scan_tracks():
f"{MAIN_BOT_ADDRESS}{MUSIC_TRACKER}", f"{MAIN_BOT_ADDRESS}{MUSIC_TRACKER}",
json=result, json=result,
timeout=360) 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")
time.sleep(0.1) time.sleep(0.1)
@@ -544,10 +568,13 @@ if __name__ == "__main__":
# threads.append(threading.Thread(target=flask_debug)) # threads.append(threading.Thread(target=flask_debug))
threads.append(threading.Thread(target=waitress_run)) threads.append(threading.Thread(target=waitress_run))
threads.append(threading.Thread(target=thread_rescan)) threads.append(threading.Thread(target=thread_rescan))
threads.append(threading.Thread(target=scan_tracks))
for worker in threads: for worker in threads:
worker.start() worker.start()
time.sleep(60)
threads.append(threading.Thread(target=scan_tracks))
threads[2].start()
for worker in threads: for worker in threads:
worker.join() worker.join()