1
0
Fork 0

show station name in rofi

This commit is contained in:
Massaki Archambault 2018-11-08 13:36:16 -05:00
parent 7fbce2960b
commit ffb87c7928
1 changed files with 16 additions and 3 deletions

View File

@ -5,6 +5,9 @@ from subprocess import Popen, PIPE, check_output, check_call
import yaml import yaml
station_name_file = '/run/user/%s/rofi-radio-name' % os.getuid()
def mpv_ipc(*args): def mpv_ipc(*args):
try: try:
j = json.loads(check_output(['mpv-ipc'] + list(args))) j = json.loads(check_output(['mpv-ipc'] + list(args)))
@ -14,15 +17,21 @@ def mpv_ipc(*args):
pass pass
return '' return ''
with open(os.path.expanduser("~/.local/share/rofi-radio/playlists.yaml")) as y: with open(os.path.expanduser("~/.local/share/rofi-radio/playlists.yaml")) as f:
stations = yaml.load(y) stations = yaml.load(f)
rofi_command = ['rofi', '-i', '-selected-row', '0', '-dmenu', '-p', 'mpv'] rofi_command = ['rofi', '-i', '-selected-row', '0', '-dmenu', '-p', 'mpv']
current_song = mpv_ipc('get_property_string', 'media-title') current_song = mpv_ipc('get_property_string', 'media-title')
if current_song: if current_song:
rofi_command += ['-mesg', current_song] try:
with open(station_name_file) as f:
station_name = f.readline()
except:
station_name = ''
rofi_command += ['-mesg', station_name]
commands = b"Play/Pause\nStop\nShuffle\nNext\nPrevious" commands = b"Play/Pause\nStop\nShuffle\nNext\nPrevious"
else: else:
commands = bytes('\n'.join([s["name"] for s in stations]), 'utf8') commands = bytes('\n'.join([s["name"] for s in stations]), 'utf8')
@ -45,6 +54,7 @@ else:
if s: if s:
# Load the selected playlist # Load the selected playlist
loc = s[0]["loc"] loc = s[0]["loc"]
station_name = s[0]["name"]
if loc.startswith('http') or loc.startswith('ytdl'): if loc.startswith('http') or loc.startswith('ytdl'):
# Load the url # Load the url
mpv_ipc('loadfile', loc) mpv_ipc('loadfile', loc)
@ -52,6 +62,9 @@ else:
# Load the file # Load the file
workdir = mpv_ipc('get_property_string', 'working-directory') workdir = mpv_ipc('get_property_string', 'working-directory')
mpv_ipc('loadfile', os.path.expanduser(loc)) mpv_ipc('loadfile', os.path.expanduser(loc))
station_name = loc
with open(station_name_file, 'w') as f:
f.write(station_name)
else: else:
# Try to load the user input # Try to load the user input
mpv_ipc('loadfile', choice) mpv_ipc('loadfile', choice)