mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-16 06:42:10 +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:
@@ -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():
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user