Skip to content

Commit

Permalink
v0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nossebro committed Oct 30, 2021
1 parent 36a2e35 commit a3c9069
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.0.2 - Random selection

* Add possibility to randomly select a mp3 file to play

## 0.0.1 - Primary Release

* First public release
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Play sound effects depending on Twitch (Channel Points) Reward IDs. Requires [Tw
1. Install the script in SLCB. (Please make sure you have configured the correct [32-bit Python 2.7.13](https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi) Lib-directory).
2. Insert the API_Key.js by right-clicking the script in SLCB.
3. Reload all scripts, so the new API_Key.js file gets picked up.
4. Place mp3 files in the `sounds` subfolder, and name them `<reward-id>.mp3`.
4. Place mp3 files in the `sounds` subfolder, and name them `<reward-id>.mp3`, or create a `<reward-id>` subfolder and place mp3 files inside for a random selection each time the reward is redeemed.
16 changes: 14 additions & 2 deletions TwitchRewardSoundEffects_StreamlabsSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import codecs
import json
import random
clr.AddReference("websocket-sharp.dll")
from WebSocketSharp import WebSocket

Expand All @@ -17,7 +18,7 @@
ScriptName = "TwitchRewardSoundEffects"
Website = "https://github.com/nossebro/TwitchRewardSoundEffects"
Creator = "nossebro"
Version = "0.0.1"
Version = "0.0.2"
Description = "Play sound effects depending on Twitch (Channel Points) Reward IDs"

#---------------------------------------
Expand Down Expand Up @@ -254,9 +255,20 @@ def LocalSocketEvent(ws, data):
LocalSocketIsConnected = True
Logger.info(event["data"]["message"])
elif event["event"] == "TWITCH_REWARD_V1":
fdir = os.path.join(os.path.dirname(__file__), "sounds", "{0}".format(event["data"]["reward_id"]))
fname = os.path.join(os.path.dirname(__file__), "sounds", "{0}.mp3".format(event["data"]["reward_id"]))
Logger.debug("Looking for file: {0}".format(fname))
Logger.debug("Looking for file or folder: {0}".format(fname))
if os.path.isdir(fdir):
for x in os.listdir(fdir):
Logger.debug(x)
if x.lower().endswith(".mp3"):
Logger.debug("Yes!!!")
Logger.debug(os.path.join(fdir, x))
Logger.debug(os.path.isfile(os.path.join(fdir, x)))
fname = os.path.join(fdir, random.choice([x for x in os.listdir(fdir) if x.lower().endswith(".mp3") and os.path.isfile(os.path.join(fdir, x))]))
Logger.debug("filename: {}".format(fname))
if os.path.isfile(fname):
Logger.debug("Found file: {0}".format(fname))
Parent.PlaySound(fname, 1.0)
else:
Logger.warning("Unhandled event: {0}: {1}".format(event["event"], event["data"]))

0 comments on commit a3c9069

Please sign in to comment.