mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-16 23:02:10 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 215a36f91e | |||
| ecabfc8876 | |||
| 20f045e92a | |||
| c90e90ea10 | |||
| fcefaf11ef | |||
| 8c6e80d832 | |||
| 96b93488c7 | |||
| c31390859f | |||
| 314a77c1f9 | |||
| 0345573cb8 | |||
| 4842ccdc22 |
@@ -2389,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."
|
||||||
@@ -2484,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."
|
||||||
@@ -2543,7 +2543,7 @@ async def co_na_plejliscie_wariacie(ctx):
|
|||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
logger.info("plejlista")
|
logger.info("plejlista")
|
||||||
logger.info(PREPPED_TRACKS)
|
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
|
# *================================== Run
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -2,14 +2,20 @@ 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__)
|
||||||
@@ -19,7 +25,9 @@ PREPPED_TRACKS = {
|
|||||||
"all": "",
|
"all": "",
|
||||||
"priority":"",
|
"priority":"",
|
||||||
"jingles":"",
|
"jingles":"",
|
||||||
"now_playing":""
|
"now_playing":"",
|
||||||
|
"next": "",
|
||||||
|
"meta" : ""
|
||||||
}
|
}
|
||||||
logger = logging.getLogger("discord")
|
logger = logging.getLogger("discord")
|
||||||
|
|
||||||
@@ -42,13 +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)
|
||||||
|
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]
|
PREPPED_TRACKS[record[0]] = record[1]
|
||||||
logger.info("DATA RECEIVED")
|
app.logger.info("DATA RECEIVED")
|
||||||
return jsonify("SUCCESS")
|
return jsonify("SUCCESS")
|
||||||
|
|
||||||
|
|
||||||
@@ -147,6 +162,28 @@ 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 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():
|
def comm_subroutine():
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ def scan_tracks():
|
|||||||
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 = ["now_playing", 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}",
|
||||||
@@ -568,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()
|
||||||
|
|||||||
Reference in New Issue
Block a user