Closed mansman12 closed 1 year ago
Hey @mansman12, as part of #32 logging was added, so it's certainly possible to write to a file. Currently there's no way to specify just write the file name, nor the file. I'm working on some new actions atm, but will add this to the backlog.
Hey @mansman12, I'm triaging issues, and sadly I'm going to mark this as "Not planned" for now. Should this change in the future, I will update this ticket. My apologies.
@GeekyEggo no worries, I've written a solution below for anyone interested to be able to do this via local code (written in Python). Hopefully you might find this useful if you ever want to revisit this issue!
Make a file called 'core.py' and put the following code in it:
import utilities
import config
class MusicBot: def init(self): pass
def init(self):
self.loop_for_music()
def loop_for_music(self):
# Get last modified date
last_mod = utilities.get_file_last_modified(config.sounddeck_log_file_path)
# Set display text file to show nothing playing
utilities.set_text_file(config.music_text_file_path,'Nothing Playing')
while True:
# Check current modified date
cur_mod = utilities.get_file_last_modified(config.sounddeck_log_file_path)
# If changed:
if last_mod != cur_mod:
# Get song file path
cur_song_file_path = utilities.get_sounddeck_log_last_played(config.sounddeck_log_file_path)
# Get song title
cur_artist_title = utilities.get_song_artist_title(cur_song_file_path)
# Update display text file
utilities.set_text_file(config.music_text_file_path, cur_artist_title)
# Update last modified date
last_mod = cur_mod
def main(): music_bot = MusicBot() music_bot.init()
if name == 'main': main()
2. Make a file called 'utilities.py' and put the following code in it:
import datetime import os import music_tag import re
sounddeck_playing_regex = r'[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]+ [TRACE] SoundDeck.Core.Playback.IAudioPlayer: Playing \"([A-Za-z0-9.\:\ -]+)\"'
def set_text_file(file_path_name, text):
file = open(file_path_name, 'w')
file.write(text)
file.close()
def get_file_last_modified(file_path_name):
out_unix = os.path.getmtime(file_path_name)
out_greg = datetime.datetime.fromtimestamp(out_unix)
return out_greg
def get_sounddeck_log_last_played(file_path_name): file = open(file_path_name, 'r') text = file.read() matches = re.findall(sounddeck_playing_regex, text) last_match = matches[-1]
return last_match
def get_file_name(file_path_name): file_name = os.path.basename(file_path_name) file_name_list = file_name.split('.')
return file_name_list[0]
def get_song_artist_title(file_path_name): file = music_tag.load_file(file_path_name) artist = str(file['artist']) title = str(file['title']) artist_title = title + ' - ' + artist
return artist_title
3. And finally make a file called 'config.py' and put the following code in it, then update [PATH_TO_TEXT_FILE_TO_UPDATE.txt] and [FIRSTNAME_LASTNAME]:
music_text_file_path = [PATH_TO_TEXT_FILE_TO_UPDATE.txt] sounddeck_log_file_path = 'C:\Users\[FIRSTNAME_LASTNAME]\AppData\Roaming\Elgato\StreamDeck\Plugins\com.geekyeggo.sounddeck.sdPlugin\logs\SoundDeck.log'
4. Run 'core.py', you'll find that when it initially runs, the text file output is set to 'Nothing Playing'. When you start playing audio through SoundDeck, the method will pick up the file and output the title and artist to the specified text file.
As a streamer it would be useful to have the currently playing audio file output the title and artist to a textfile which could then be picked up a program like OBS to display on stream.
Is that something that is possible?