Managing music on linux using mpc/mpc

426 views
Skip to first unread message

Dilawar Singh

unread,
Dec 19, 2013, 4:08:19 PM12/19/13
to wncc...@googlegroups.com
Music player daemon
-------------------

Music Player Daemon (MPD) is a lightweight application. It hardly takes any cpu.
Moreover it runs in background and does not clutter and workspace. If you dont
use mouse frequently or wants to avoid it (programmers use keyboard), then mpd
is for you. It is one of those applications which does one job at a time and
does it really well (well, if you get is working once which is not very hard).

The job of MPD is to read/decode audio files available in its music directory on
demand (one can specify it in config file) and create sound. It them make
sound available to user using ALSA (or some other) soundcard driver. How to
setup MPD is explained nicely on arch-linux wiki (gentoo wiki should also have
something) otherwise there is some help always available on
http://unix.stackexchange.com or http://superuser.stackexchange.com. Here is my
config file stored as ~/.mpd/mpdconf. All of my music is kept in/download to
~/Bhandar/Music .

A minimal example for mpdconf file which works on my system.


music_directory "~/Bhandar/Music/"
playlist_directory "~/.mpd/playlists"
db_file "~/.mpd/tag_cache"
log_file "~/.mpd/mpd.log"
pid_file "~/.mpd/pid"
state_file "~/.mpd/state"
bind_to_address "127.0.0.1"
port "6600"
log_level "default"
save_absolute_paths_in_playlists "yes"
metadata_to_use "artist,album,title,track,name,genre,date,composer,performer,disc"
follow_inside_symlinks "yes"
password "gabbar@read,add,control,admin"
default_permissions "read,add,control"
input {
plugin "curl"
}
audio_output {
type "alsa"
name "My ALSA Device"
}

On ubuntu, if you install mpd, a file is automatically created in /etc/mpd.conf.
You can edit this file also. You have to create some paths before you can
continue, if you create a config file like mine.

$ mkdir -p ~/.mpd/playlists
$ touch ~/.mpd/playlists

Now type mpd in terminal, if it starts without any messages then we are good to
go. Sometimes, you might get this warning.

Failed to bind to '127.0.0.1:6600': Address already in use

This means mpd is already running. Check the running process

$ ps -e | grep mpd
14073 ? 00:00:28 mpd

Terminate it,

$ sudo pkill mpd
or
$ sudo kill -9 14073
check again.
$ ps -e | grep mpd

This time we should have an empty line. Run mpd again. If there is a problem,
then time to ask people or debug by yourself.


Music player client (MPC)
------------------------

Now we need a client to send commands to mpd. MPC is a command line tool (perl
scripts) while gmpc is a gui-based client. Mind you, mpd does not have those
advance features of rythmbox and bashee. If you like to use amplifier and other
fancy feature to enhance the sound, there is no point reading further.

The very first thing we need to do, it to update database.

$ mpd -h gabbar@localhost update
Updating DB (#1) ...

Password 'gabbar' was given in conf file. Without it, we will not have access to
update the database. Check what password you have given and see the results.
This much we need to do only once.

Creating playlists and playing them
----------------------------------

`mpc help` command will show you how to search for songs and add them to
playlist. I woluld suggest to learn it the hard way. I have written few scripts
to make my life slightly easier (short term memory losses). Script [1] does
search for a given word in an of songs and add them all matched songs.

$./mpc_search_add.sh "bhimsen joshi"

It will add songs having 'bhimsen joshi' in their metadata, if they are not
already added. Another common problem is to play the fav song quickly. There is
script [3] for this also. For instance if I want to listen to "Yellow, Cold
play" then I do the following.

$./mpc_play "yellow"
[INFO] Searching for yellow
[INFO] No song found for your query.

Ok, yellow is not found that means it is not added to playlist. Use script 2 to
add "Coldplay" to playlist. Menwhile, lets play a song which I am pretty sure of
having in my playlist: 'Seene main jalan'. It will play the first match.

#./mpc_play "seene"
[INFO] A matching song is found in playlist at 1911
www.downloadming.com -
[playing] #1911/1911 0:00/4:30 (0%)
volume:100% repeat: on random: on single: off consume: off

Depending on size of playlist, this might take 1-3 seconds.

Next, previous, play/pause and volume
------------------------------------

MPC comes with standard command to do them `mpc next`, `mpc previous`, `mpc
toggle` etc etc. Each windown manager allows key mapping. Map these commands to
some key combination. I use Alt+Ctlr+<some character> for user defined commands.

Deleting currently playing song or adding it to favs
---------------------------------------------------

A lot of songs gets downloaded and once in a while suddenly some random guy
starting singing about somebodys butt and breasts. Who wants such sort of
non-sense in ones playlist :-p. Sometimes a great songs appears and you wish to
add it to your a folder. Script [2] does both of these functions. This acts on
currently playing song. If you path to music_dir is different than mine, then
you have to change the paths accordingly.

To delete currently playing song

$./manage_mpc.sh -d

To add the song to a folder of gem

$./manage_mpc.sh -a

You can bind these two commands to some keys. The important thing is that these
scripts must be executable (chmod +x scipt_name) and available in system path
(copy them to /usr/local/bin ).

Script [4] provides color-support in terminal which is needed for other scripts
to work. It should be in the same folder as other scripts. One can use it for
other purposes. Everyone loves colors.

[1] https://raw.github.com/dilawar/Scripts/master/mpc_search_add.sh
[2] https://raw.github.com/dilawar/Scripts/master/manage_mpc.sh
[3] https://raw.github.com/dilawar/Scripts/master/manage_play.sh
[4] https://raw.github.com/dilawar/Scripts/master/colors.sh


--
Dilawar
NCBS Bangalore

Sushant Hiray

unread,
Dec 20, 2013, 7:44:22 AM12/20/13
to wncc...@googlegroups.com
Thanks Dilawar,
This works like a charm. :)

Just a minor correction:
In the MPC section:
Instead of     $ mpd -h gabbar@localhost update
it should be:  $ mpc -h gabbar@localhost update

and the [3] link should be: https://raw.github.com/dilawar/Scripts/master/mpc_play.sh




--
--
The website for the club is http://stab-iitb.org/wncc
To post to this group, send email to wncc...@googlegroups.com

--- You received this message because you are subscribed to the Google Groups "Web and Coding Club IIT Bombay" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wncc_iitb+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Dilawar Singh

unread,
Dec 20, 2013, 8:30:02 PM12/20/13
to wncc...@googlegroups.com
Thanks. I'll put the article on stab-wiki.

- Dilawar
--
Dilawar
NCBS Bangalore

Kunal Tyagi

unread,
Dec 21, 2013, 11:27:05 AM12/21/13
to wncc...@googlegroups.com
Talking of CLI, microdc2 is very usefull for accessing DC++ also using cli. if used with tilda or guake,it is easy and more accessible than a GUI.

Thanks 
                                              
Kunal Tyagi  | Software Subdivision   | AUV-IITB  | IIT Bombay

This e-mail was generated using only recycled electrons.. No virtual trees were cut to send this message to you.

Dilawar Singh

unread,
Dec 21, 2013, 1:18:41 PM12/21/13
to wncc...@googlegroups.com
You can use this fork of microdc2 (https://github.com/dilawar/microdc2). This
does not print those annoying 'user status' in main screen. Also one can specify
the type of file to search

microdc2> search "walt disney" $$vi

$$vi -> video, $$au -> audio, $$ex -> executable, $$doc -> document, etc.

It only connects to only one hub. I guess thats a bug. Thought of extending it
using cython but could not find time.

--
Dilawar
EE, IIT Bombay
Reply all
Reply to author
Forward
0 new messages