misc / tRIP - beginnings/work in progress
This commit is contained in:
@@ -3,6 +3,7 @@ import traceback
|
||||
import time
|
||||
import datetime
|
||||
import os
|
||||
import random
|
||||
from uuid import uuid4 as uuid
|
||||
from typing import Union, Optional, Iterable
|
||||
from aiohttp import ClientSession, ClientTimeout
|
||||
@@ -59,11 +60,13 @@ class RadioUtil:
|
||||
# # "hip hop",
|
||||
# "metalcore",
|
||||
# "deathcore",
|
||||
# # "edm",
|
||||
# "edm",
|
||||
# "electronic",
|
||||
# "hard rock",
|
||||
# "rock",
|
||||
# # "ska",
|
||||
# "post-hardcore",
|
||||
# "post hardcore",
|
||||
# # "hard rock",
|
||||
# # "rock",
|
||||
# # # "ska",
|
||||
# # "post punk",
|
||||
# # "post-punk",
|
||||
# # "pop punk",
|
||||
@@ -96,9 +99,11 @@ class RadioUtil:
|
||||
self.webhooks: dict = {
|
||||
"gpt": {
|
||||
"hook": self.constants.GPT_WEBHOOK,
|
||||
"lastRun": None,
|
||||
},
|
||||
"sfm": {
|
||||
"hook": self.constants.SFM_WEBHOOK,
|
||||
"lastRun": None,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -358,8 +363,8 @@ class RadioUtil:
|
||||
query: str = (
|
||||
"SELECT genre FROM artist_genre WHERE artist LIKE ? COLLATE NOCASE"
|
||||
)
|
||||
params: tuple[str] = (f"%%{artist}%%",)
|
||||
with sqlite3.connect(self.artist_genre_db_path, timeout=2) as _db:
|
||||
params: tuple[str] = (artist,)
|
||||
with sqlite3.connect(self.playback_db_path, timeout=2) as _db:
|
||||
_db.row_factory = sqlite3.Row
|
||||
_cursor = _db.execute(query, params)
|
||||
res = _cursor.fetchone()
|
||||
@@ -386,6 +391,8 @@ class RadioUtil:
|
||||
_playlist = await self.redis_client.json().get(playlist_redis_key)
|
||||
if playlist not in self.active_playlist.keys():
|
||||
self.active_playlist[playlist] = []
|
||||
if not playlist == "rock":
|
||||
random.shuffle(_playlist) # Temp/for Cocteau Twins
|
||||
self.active_playlist[playlist] = [
|
||||
{
|
||||
"uuid": str(uuid().hex),
|
||||
@@ -542,7 +549,7 @@ class RadioUtil:
|
||||
text: Optional[str] = await request.text()
|
||||
return isinstance(text, str) and text.startswith("OK")
|
||||
except Exception as e:
|
||||
logging.debug("Skip failed: %s", str(e))
|
||||
logging.critical("Skip failed: %s", str(e))
|
||||
|
||||
return False # failsafe
|
||||
|
||||
@@ -572,7 +579,10 @@ class RadioUtil:
|
||||
None
|
||||
"""
|
||||
try:
|
||||
return None # disabled temporarily (needs rate limiting)
|
||||
"""TEMP - ONLY MAIN"""
|
||||
if not station == "main":
|
||||
return
|
||||
return # Temp disable global
|
||||
# First, send track info
|
||||
"""
|
||||
TODO:
|
||||
@@ -630,42 +640,18 @@ class RadioUtil:
|
||||
],
|
||||
}
|
||||
|
||||
sfm_hook: str = self.webhooks["sfm"].get("hook")
|
||||
async with ClientSession() as session:
|
||||
async with await session.post(
|
||||
sfm_hook,
|
||||
json=hook_data,
|
||||
timeout=ClientTimeout(connect=5, sock_read=5),
|
||||
headers={
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
},
|
||||
) as request:
|
||||
request.raise_for_status()
|
||||
now: float = time.time()
|
||||
_sfm: dict = self.webhooks["sfm"]
|
||||
if _sfm:
|
||||
sfm_hook: str = _sfm.get("hook", "")
|
||||
sfm_hook_lastRun: Optional[float] = _sfm.get("lastRun", 0.0)
|
||||
|
||||
# Next, AI feedback (for main stream only)
|
||||
|
||||
if station == "main":
|
||||
ai_response: Optional[str] = await self.get_ai_song_info(
|
||||
track["artist"], track["song"]
|
||||
)
|
||||
if not ai_response:
|
||||
return
|
||||
|
||||
hook_data = {
|
||||
"username": "GPT",
|
||||
"embeds": [
|
||||
{
|
||||
"title": "AI Feedback",
|
||||
"color": 0x35D0FF,
|
||||
"description": ai_response.strip(),
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
ai_hook: str = self.webhooks["gpt"].get("hook")
|
||||
if sfm_hook_lastRun and ((now - sfm_hook_lastRun) < 5):
|
||||
logging.info("SFM Webhook: Throttled!")
|
||||
return
|
||||
async with ClientSession() as session:
|
||||
async with await session.post(
|
||||
ai_hook,
|
||||
sfm_hook,
|
||||
json=hook_data,
|
||||
timeout=ClientTimeout(connect=5, sock_read=5),
|
||||
headers={
|
||||
@@ -673,6 +659,41 @@ class RadioUtil:
|
||||
},
|
||||
) as request:
|
||||
request.raise_for_status()
|
||||
|
||||
# Next, AI feedback (for main stream only)
|
||||
"""
|
||||
TEMP. DISABLED
|
||||
"""
|
||||
|
||||
# if station == "main":
|
||||
# ai_response: Optional[str] = await self.get_ai_song_info(
|
||||
# track["artist"], track["song"]
|
||||
# )
|
||||
# if not ai_response:
|
||||
# return
|
||||
|
||||
# hook_data = {
|
||||
# "username": "GPT",
|
||||
# "embeds": [
|
||||
# {
|
||||
# "title": "AI Feedback",
|
||||
# "color": 0x35D0FF,
|
||||
# "description": ai_response.strip(),
|
||||
# }
|
||||
# ],
|
||||
# }
|
||||
|
||||
# ai_hook: str = self.webhooks["gpt"].get("hook")
|
||||
# async with ClientSession() as session:
|
||||
# async with await session.post(
|
||||
# ai_hook,
|
||||
# json=hook_data,
|
||||
# timeout=ClientTimeout(connect=5, sock_read=5),
|
||||
# headers={
|
||||
# "content-type": "application/json; charset=utf-8",
|
||||
# },
|
||||
# ) as request:
|
||||
# request.raise_for_status()
|
||||
except Exception as e:
|
||||
logging.info("Webhook error occurred: %s", str(e))
|
||||
traceback.print_exc()
|
||||
|
Reference in New Issue
Block a user