playlist file support
This commit is contained in:
parent
8c3112dda1
commit
7fbce2960b
|
@ -1,11 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import json
|
import json
|
||||||
import yaml
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
from subprocess import Popen, PIPE, check_output, check_call
|
from subprocess import Popen, PIPE, check_output, check_call
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
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)))
|
||||||
|
@ -15,7 +14,7 @@ def mpv_ipc(*args):
|
||||||
pass
|
pass
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
with open(os.path.expanduser("~/.local/share/playlists.yaml")) as y:
|
with open(os.path.expanduser("~/.local/share/rofi-radio/playlists.yaml")) as y:
|
||||||
stations = yaml.load(y)
|
stations = yaml.load(y)
|
||||||
|
|
||||||
rofi_command = ['rofi', '-i', '-selected-row', '0', '-dmenu', '-p', 'mpv']
|
rofi_command = ['rofi', '-i', '-selected-row', '0', '-dmenu', '-p', 'mpv']
|
||||||
|
@ -23,7 +22,7 @@ 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]
|
rofi_command += ['-mesg', current_song]
|
||||||
commands = b"Play/Pause\nStop\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')
|
||||||
|
|
||||||
|
@ -35,12 +34,29 @@ if current_song:
|
||||||
mpv_ipc('cycle', 'pause')
|
mpv_ipc('cycle', 'pause')
|
||||||
elif choice == "Stop":
|
elif choice == "Stop":
|
||||||
mpv_ipc('stop')
|
mpv_ipc('stop')
|
||||||
|
elif choice == "Shuffle":
|
||||||
|
mpv_ipc('playlist-shuffle')
|
||||||
|
elif choice == "Next":
|
||||||
|
mpv_ipc('playlist-next')
|
||||||
|
elif choice == "Previous":
|
||||||
|
mpv_ipc('playlist-prev')
|
||||||
else:
|
else:
|
||||||
s = [s for s in stations if s["name"] == choice]
|
s = [s for s in stations if s["name"] == choice]
|
||||||
if s:
|
if s:
|
||||||
mpv_ipc('loadfile', s[0]["loc"])
|
# Load the selected playlist
|
||||||
mpv_ipc('set_property_string', 'pause', 'no')
|
loc = s[0]["loc"]
|
||||||
|
if loc.startswith('http') or loc.startswith('ytdl'):
|
||||||
|
# Load the url
|
||||||
|
mpv_ipc('loadfile', loc)
|
||||||
|
else:
|
||||||
|
# Load the file
|
||||||
|
workdir = mpv_ipc('get_property_string', 'working-directory')
|
||||||
|
mpv_ipc('loadfile', os.path.expanduser(loc))
|
||||||
|
else:
|
||||||
|
# Try to load the user input
|
||||||
|
mpv_ipc('loadfile', choice)
|
||||||
|
mpv_ipc('set_property_string', 'pause', 'no')
|
||||||
|
|
||||||
|
|
||||||
# force update of i3status
|
# force update of i3status
|
||||||
check_call('killall', '-USR1', 'i3status')
|
check_call(['killall', '-USR1', 'i3status'])
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Description=mpv - a media player
|
Description=mpv - a media player
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/bin/mpv --idle --input-ipc-server /tmp/mpv.sock
|
ExecStart=/usr/bin/mpv --idle --really-quiet --no-video --input-ipc-server /tmp/mpv.sock
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=default.target
|
WantedBy=default.target
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
- name: Nectarine
|
|
||||||
loc: http://nectarine.ers35.net:8000/necta192.mp3
|
|
||||||
- name: TheBase
|
|
||||||
loc: http://radio.thebase.sc:8000/stream
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
- name: Nectarine
|
||||||
|
loc: http://nectarine.ers35.net:8000/necta192.mp3
|
||||||
|
- name: TheBase
|
||||||
|
loc: http://radio.thebase.sc:8000/stream
|
||||||
|
- name: CJPX 99.5 Radio-Classique Montréal
|
||||||
|
loc: http://stream.statsradio.com:8030/stream
|
||||||
|
- name: CBF 95.1 ICI Radio-Canada Première Montréal
|
||||||
|
loc: http://2qmtl0.akacast.akamaistream.net/7/953/177387/v1/rc.akacast.akamaistream.net/2QMTL0
|
||||||
|
|
Loading…
Reference in New Issue