mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
Tag: 1.14
Intermediate commits (oldest → newest): - Music trackin upgrade - fx - Fx - Metadata - 1 - Fix - Fixing time mismatch - Port fix - fx - fx
This commit is contained in:
@@ -2389,7 +2389,7 @@ async def wyszukaj_linki_do_dokumentow(ctx):
|
||||
username = ctx.message.author.nick
|
||||
else:
|
||||
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)
|
||||
await ctx.send(
|
||||
f"No dobra poszło. Zapamiętaj proszę {query_uuid} - to identyfikator twojego zapytania. Jesteś {queue_size} w kolejce."
|
||||
@@ -2484,7 +2484,7 @@ async def wyszukaj_linki_do_dokumentow_deep(ctx):
|
||||
username = ctx.message.author.nick
|
||||
else:
|
||||
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)
|
||||
await ctx.send(
|
||||
f"Wypij wypi {query_uuid} - to identyfikator twojego zapytania. Jesteś {queue_size} w kolejce niestety kolejka obowiazuje zawsze."
|
||||
@@ -2543,7 +2543,7 @@ async def co_na_plejliscie_wariacie(ctx):
|
||||
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()} \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()}")
|
||||
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
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -2,14 +2,20 @@ import logging
|
||||
import threading
|
||||
import json
|
||||
import time
|
||||
import re
|
||||
from urllib import request as urequest
|
||||
|
||||
from queue import Queue, Empty
|
||||
from flask import Flask, jsonify, request
|
||||
from waitress import serve
|
||||
|
||||
HOST_ADDRESS = "192.168.1.191"
|
||||
PORT_ADDRESS = 5000
|
||||
ICECAST_ADDRESS = "http://192.168.1.15:8000"
|
||||
OUT_COMM_Q = Queue()
|
||||
IN_COMM_Q = Queue()
|
||||
SRCHTITLE = re.compile(br'StreamTitle=\\*(?P<title>[^;]*);').search
|
||||
|
||||
awaiting_q = []
|
||||
incoming_q = Queue()
|
||||
app = Flask(__name__)
|
||||
@@ -19,7 +25,9 @@ PREPPED_TRACKS = {
|
||||
"all": "",
|
||||
"priority":"",
|
||||
"jingles":"",
|
||||
"now_playing":""
|
||||
"now_playing":"",
|
||||
"next": "",
|
||||
"meta" : ""
|
||||
}
|
||||
logger = logging.getLogger("discord")
|
||||
|
||||
@@ -42,13 +50,20 @@ class QueryControl:
|
||||
|
||||
@app.route("/prepped_tracks", methods=["POST"])
|
||||
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)
|
||||
logger.info(record)
|
||||
app.logger.info(record)
|
||||
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]
|
||||
logger.info("DATA RECEIVED")
|
||||
app.logger.info("DATA RECEIVED")
|
||||
return jsonify("SUCCESS")
|
||||
|
||||
|
||||
@@ -147,6 +162,28 @@ def scan_incoming():
|
||||
except Empty:
|
||||
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 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():
|
||||
"""
|
||||
|
||||
@@ -123,7 +123,7 @@ def scan_tracks():
|
||||
time.sleep(0.1)
|
||||
file1 = open(PERSISTENCE_PATH, 'r')
|
||||
lines = file1.readlines()
|
||||
result = ["now_playing", lines[2]]
|
||||
result = ["next", lines[2]]
|
||||
file1.close()
|
||||
returned = requests.post(
|
||||
f"{MAIN_BOT_ADDRESS}{MUSIC_TRACKER}",
|
||||
@@ -568,10 +568,13 @@ if __name__ == "__main__":
|
||||
# threads.append(threading.Thread(target=flask_debug))
|
||||
threads.append(threading.Thread(target=waitress_run))
|
||||
threads.append(threading.Thread(target=thread_rescan))
|
||||
threads.append(threading.Thread(target=scan_tracks))
|
||||
|
||||
for worker in threads:
|
||||
worker.start()
|
||||
|
||||
time.sleep(60)
|
||||
threads.append(threading.Thread(target=scan_tracks))
|
||||
threads[2].start()
|
||||
|
||||
for worker in threads:
|
||||
worker.join()
|
||||
|
||||
Reference in New Issue
Block a user