hmbrg.xyz

Listen to audio collection via dmenu & mpv

Table Of Contents:

Sometimes I want to listen to a certain music track and enjoy it. For this case I’ve created a small shell script to be able to access it quickly by using the power of dmenu ̚ .

Workflow

After executing the script, I use a shortcut to launch it, in the first step all directories contained in my Music share are listed. After one of them got selected the contained tracks are displayed. Finally, after selecting an audio file the track will be played via mpv.

There is no playlist function or similar only playing that single selection. To satisfy this need there are plenty of other nice solutions like ncmpcpp which I use to listen to a set of shorter (3-5 minutes) audio files. The solution discussed here is for quick-shot-cherry-picking 😛.

How the magic looks like

The script itself looks as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh

###  -----------------------------------------------------------------
###  Global variables:
###  -----------------------------------------------------------------
DIR=/mnt/omv/media/music
PLAYER=mpv
DMENU='dmenu -i -l 10'

###  -----------------------------------------------------------------
###  Check presence of NAS share otherwise mount it:
###  -----------------------------------------------------------------
[ ! -d $DIR ] && ~/.local/bin/mnt_omv.sh

###  -----------------------------------------------------------------
###  Select the subdirectory from which you want to play the MP3 file:
###  -----------------------------------------------------------------
subdir=$(ls -1 $DIR | $DMENU -p "Select subdir: ")

###  -----------------------------------------------------------------
###  Select MP3 file to play back:
###  -----------------------------------------------------------------
mp3=$(ls -1 $DIR/$subdir/*mp3 | $DMENU -p "MP3 to play back: ")

###  -----------------------------------------------------------------
###  Play back selected MP3 file:
###  -----------------------------------------------------------------
if [ $mp3 ]; then
    $PLAYER "$mp3"
fi

Download location

If you are interested but to lazy to copy and paste you can grab it off my Git repository ̚ .


Tags: dmenu, mp3, shell-scripting

This page was last updated on: 17. November 2021