Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
Version 1 release
  • Loading branch information
MythicPalette committed Feb 16, 2024
1 parent 111a9ca commit 94731ea
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
16 changes: 14 additions & 2 deletions KenkuPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(self, json) -> None:
__state_shuffle = False
__state_repeat = "off"
__state_playback_track = None
__state_playback_sounds = []

__tracklist = []
__soundlist = []
Expand Down Expand Up @@ -102,6 +103,7 @@ def query_status():
global __state_shuffle
global __state_repeat
global __state_playback_track
global __state_playback_sounds

try:
# Get the playlist info
Expand All @@ -116,15 +118,22 @@ def query_status():
__soundboards = [Board(sb) for sb in j['soundboards']]
__soundlist = [Sound(s) for s in j['sounds']]

# Get the playback state
# Get the playback state of the playlist tracks
j = json.loads(api(PLAYLIST, QUERY_PLAYBACK, METHOD_GET).text)

__state_playlist_playing = j['playing']
__state_volume = j['volume']
__state_muted = j['muted']
__state_shuffle = j['shuffle']
__state_repeat = j['repeat']
__state_playback_track = j['track']

if 'track' in j:
__state_playback_track = j['track']

# Get the playback state of the soundboard sounds
j = json.loads(api(SOUNDBOARD, QUERY_PLAYBACK, METHOD_GET).text)
__state_playback_sounds = j['sounds']

except:
pass

Expand All @@ -150,6 +159,9 @@ def get_muted() -> bool:
def get_playing_track() -> dict:
return __state_playback_track

def get_playing_sounds() -> dict:
return __state_playback_sounds

def get_board_list(type) -> list:
return __playlists if type.lower() == PLAYLIST else __soundboards

Expand Down
21 changes: 21 additions & 0 deletions TPKenku.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ def query_api():
TPClient.stateUpdate("Kenku_Current_Track_Name", track['title'] if track is not None else "")
TPClient.stateUpdate("Kenku_Current_Track_Id", track['id'] if track is not None else "")

# Get the playing sounds
soundData = Kenku.get_playing_sounds()
sounds = []
for sound in soundData:
sounds.append(sound['id'])

TPClient.stateUpdate("Kenku_Playing_Sounds", ",".join(sounds))


def query_loop():
while not __kill_thread.is_set():
Kenku.query_status()
Expand Down Expand Up @@ -109,6 +118,18 @@ def onAction(data):
id = data['data'][1]['value']
call_api(board.lower(), Kenku.ACTION_PLAY, "PUT", data={"id":id}, wait=True)

elif data['actionId'] == "Kenku_ToggleSound":
soundId = data['data'][0]['value']
sounds = Kenku.get_playing_sounds()
for sound in sounds:
# If the sound is found, stop it.
if sound['id'] == soundId:
call_api(Kenku.SOUNDBOARD, Kenku.ACTION_STOP, Kenku.METHOD_PUT, data={"id":soundId})
return

# The sound was not playing so start it
call_api(Kenku.SOUNDBOARD, Kenku.ACTION_PLAY, "PUT", data={"id":soundId})

elif data['actionId'] == "Kenku_StopSound":
playlistidx = get_index_from_str(data['data'][0]['value'])
soundidx = get_index_from_str(data['data'][1]['value'])
Expand Down
21 changes: 21 additions & 0 deletions entry.tp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@
}
]
},
{
"id": "Kenku_ToggleSound",
"name": "Toggle Sound By Id",
"prefix": "Kenku",
"type": "communicate",
"tryInline": true,
"format": "Toggle {$ToggleSound_SoundId$}",
"data": [
{
"id": "ToggleSound_SoundId",
"type": "text",
"default": ""
}
]
},
{
"id": "Kenku_StopSound",
"name": "Stop Sound",
Expand Down Expand Up @@ -231,6 +246,12 @@
"type": "text",
"desc": "Current Track Id",
"default": ""
},
{
"id": "Kenku_Playing_Sounds",
"type": "text",
"desc": "Playing Sounds",
"default": ""
}
]
}
Expand Down

0 comments on commit 94731ea

Please sign in to comment.