Quantcast
Channel: MOC - music on console - General discussion
Viewing all articles
Browse latest Browse all 92

Selecting track(s) with a rofi-MOC script

$
0
0

Hi everybody. This is my first post ever.
Context. MOC is the default player for my local music folder. It runs on external USB output whenever available. Fast, painless and non-intrusive. However, browsing/searching gets tricky when it comes to the external library (more than a thousand of folders/albums in there). Here come "locate" looking at a dedicated database, and "rofi/dmenu" (multi-select enable) for selecting track(s) and adding selection to MOC playlist.
I'm fine with what I could build around that, playing with a short rofi-locate script by "Gotbletu". It runs safe but not without some flaw. Namely when selecting multiple tracks, mocp -ya would throw "Error: Can't stat /path/to/file" on some entry, usually the first one. No consequence as far as I can see other than playlist occasionally either stopping when reaching that flle or the one next to it, or skipping it; and/or mocp displaying relative path and filename instead of tags.
Thanks in advance to whoever could tell me what I am doing wrong, what makes MOC fail to retrieve pathfile? And how to fix it?

-------
#!/bin/bash
# Source: <https://github.com/gotbletu/shownotes/blob/master/rofi_locate.md>
# rofi/dmenu & locate required; MOC server running on USB audio output; rofi adds selected track(s) to playlist.
# Make sure MOC server can be run; must be running before selection; clear playlist if needed:
if [[ ! "$(grep USB /proc/asound/cards)" ]]; then
echo "No USB output."
exit
else
if [[ ! -z $(pgrep mocp) ]]; then
echo "MOC already running!"
elif [[ ! -z "$(grep RUNNING /proc/asound/card1/*p/*/status)" ]]; then
echo "No Way: output is busy"
exit
else
echo "Running MOC"
mocp -S && mocp -c
fi
fi
# Select track(s) in external library:
cd /full/path/to/external/library
playlist="$(locate -d $HOME/.external.db -r "\w+\.\|flac\|mp3\|m4a$" | cut -c25- | rofi -width 100 -dmenu -i -multi-select -p " ♪ ")"
# Prevent MOC from fooling if selection cancelled:
if [[ "$playlist" ]]; then
mocp -ya "$playlist"
else
exit
fi
# Start playing if needed:
if [[ ! "$(mocp -i Q | grep STOP)" ]]; then
mocp -p
echo "Playing new playlist"
else
echo "Added to playlist"
fi
-------


Viewing all articles
Browse latest Browse all 92

Trending Articles