implemented next and prev, added pkill command for i3blocks on toggle
This commit is contained in:
parent
e7f3cf6170
commit
675e7c10ab
|
@ -8,12 +8,13 @@ from mpd import MPDClient
|
||||||
import mpd_playback
|
import mpd_playback
|
||||||
import mpd_state
|
import mpd_state
|
||||||
|
|
||||||
|
signal_id = 11
|
||||||
cover_art_temp = '/tmp/mpd_cover_art_temp.jpg'
|
cover_art_temp = '/tmp/mpd_cover_art_temp.jpg'
|
||||||
|
|
||||||
arguments = sys.argv
|
arguments = sys.argv
|
||||||
|
|
||||||
if len(arguments) == 1:
|
if len(arguments) == 1:
|
||||||
mpc_command = None
|
mpc_command = 'state'
|
||||||
elif len(arguments) == 2:
|
elif len(arguments) == 2:
|
||||||
mpc_command = arguments[1]
|
mpc_command = arguments[1]
|
||||||
|
|
||||||
|
@ -28,13 +29,18 @@ def main():
|
||||||
return
|
return
|
||||||
# follow mpc_command
|
# follow mpc_command
|
||||||
if mpc_command == 'toggle':
|
if mpc_command == 'toggle':
|
||||||
mpd_playback.toggle(client)
|
mpd_playback.toggle(client, signal_id)
|
||||||
# show status
|
elif mpc_command == 'next':
|
||||||
mpd_state.get_state(client, cover_art_temp)
|
mpd_playback.play_next(client)
|
||||||
|
elif mpc_command == 'prev':
|
||||||
|
mpd_playback.play_prev(client)
|
||||||
|
elif mpc_command == 'state':
|
||||||
|
mpd_state.get_state(client, cover_art_temp)
|
||||||
# close connection
|
# close connection
|
||||||
client.close()
|
client.close()
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
|
|
||||||
|
|
||||||
|
# lunch from here
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
import subprocess
|
||||||
|
|
||||||
def fade(way, current_vol, client):
|
def fade(way, current_vol, client):
|
||||||
""" gracefull fading """
|
""" gracefull fading """
|
||||||
|
@ -13,7 +14,7 @@ def fade(way, current_vol, client):
|
||||||
sleep(0.03)
|
sleep(0.03)
|
||||||
|
|
||||||
|
|
||||||
def toggle(client):
|
def toggle(client, signal_id):
|
||||||
""" toggles play status """
|
""" toggles play status """
|
||||||
# setup
|
# setup
|
||||||
client_status = client.status()
|
client_status = client.status()
|
||||||
|
@ -26,4 +27,26 @@ def toggle(client):
|
||||||
client.setvol(0)
|
client.setvol(0)
|
||||||
client.play()
|
client.play()
|
||||||
fade('in', current_vol, client)
|
fade('in', current_vol, client)
|
||||||
|
# call pkill to refresh status bar
|
||||||
|
subprocess.call(["pkill", "-RTMIN+" + str(signal_id), "i3blocks"])
|
||||||
|
|
||||||
|
|
||||||
|
def play_next(client):
|
||||||
|
""" skip to next in playlist """
|
||||||
|
client_status = client.status()
|
||||||
|
current_vol = int(client_status['volume'])
|
||||||
|
fade('out', current_vol, client)
|
||||||
|
client.pause()
|
||||||
|
client.setvol(current_vol)
|
||||||
|
client.next()
|
||||||
|
|
||||||
|
|
||||||
|
def play_prev(client):
|
||||||
|
""" skip to previous in playlist """
|
||||||
|
client_status = client.status()
|
||||||
|
current_vol = int(client_status['volume'])
|
||||||
|
fade('out', current_vol, client)
|
||||||
|
client.pause()
|
||||||
|
client.setvol(current_vol)
|
||||||
|
client.previous()
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ def get_state(client, cover_art_temp):
|
||||||
print_state(artist, album, song_title, mpd_status)
|
print_state(artist, album, song_title, mpd_status)
|
||||||
# send message
|
# send message
|
||||||
title = icon + '\t' + artist
|
title = icon + '\t' + artist
|
||||||
message = album + "-" + song_title
|
message = album + " - " + song_title
|
||||||
subprocess.call(['notify-send', title, message, '-i', cover_art_temp])
|
subprocess.call(['notify-send', title, message, '-i', cover_art_temp])
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue