Unhardcode playlist filename on reload command

This commit is contained in:
Luke Hubmayer-Werner 2024-06-20 20:56:18 +09:30
parent ca48a78ee6
commit 91983b446e
1 changed files with 3 additions and 3 deletions

View File

@ -6,7 +6,7 @@ import urllib.request
import json import json
import socket import socket
yt_api_key = 'get your own lol' yt_api_key = 'get your own lol'
filename = '/home/luke/mpv-playlist.m3u' playlist_filename = '/home/luke/mpv-playlist.m3u'
mpv_socket = '/home/luke/socket-mpv' mpv_socket = '/home/luke/socket-mpv'
SI_large_prefixes = { # Extend if necessary SI_large_prefixes = { # Extend if necessary
@ -199,14 +199,14 @@ def process_playlist(filename: str):
if __name__ == '__main__': if __name__ == '__main__':
try: try:
process_playlist(filename) process_playlist(playlist_filename)
except BaseException as e: except BaseException as e:
logging.error('Error processing: {}'.format(e)) logging.error('Error processing: {}'.format(e))
try: try:
logging.info('Reloading playlist on mpv') logging.info('Reloading playlist on mpv')
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock: with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
sock.connect(mpv_socket) sock.connect(mpv_socket)
sock.sendall(b'playlist-clear; loadlist /home/luke/mpv-playlist.m3u append\n') sock.sendall(f'playlist-clear; loadlist "{playlist_filename}" append\n'.encode())
logging.info('mpv playlist reloaded!') logging.info('mpv playlist reloaded!')
except BaseException as e: except BaseException as e:
logging.error('Error reloading playlist: {}'.format(e)) logging.error('Error reloading playlist: {}'.format(e))