I've given up on the flashy (GUI) music players. XMMS, Beep-Media-Player, Rhythmbox, Munie... Frikk em! It's time to go terminal (CLI) with the MusicPlayerDaemon and MusicPlayerClient/NCurseMCP. MPD and MPC/NCMPC is simple enough to install and use to play music (with a _cool_ 22MHz of CPU and 6MB of RAM usage) on one local machine, yet the usage still feels a bit clumsy. In comes a few scripts and hacks snipped from musicpd.org/forum.
First off, I didn't write any of these scripts. Most are licenced GNU GPL, and the other are simple here for archive. See appended URL for credits and sources. Make sure you have MPC installed (aptitude -P install mpc)
mg (mpc grep)
From: http://www.musicpd.org/forum/index.php?topic=773.0
What it does is search through mpd's database, by filename, for whatever you give it. You don't have to quote anything either. mg also takes what you searched for and puts it into ~/.mg-lookup, which is used later to good effect. Example: mg Behind Blue Eyes
#!/bin/bash mpc search filename "$*" | tee ~/.mg-lookup
ma (mpc add)
From: http://www.musicpd.org/forum/index.php?topic=773.0
This one has two modes of operation. If you just run it on command line without any arguments it will take all of the files found by the last 'mg' call (this is where ~/.mg-lookup comes in handy) and adds to the playlist. You can also use 'ma' with arguments. In that case, it will search through mpc's database just like mg would, except it will immediately add anything it finds to the playlist. This is useful if you're sure of what the search will return and want to cut out the middleman.
#!/bin/bash if [ "$1" = "" ]; then cat ~/.mg-lookup | mpc add else mpc search filename "$*" | mpc add fi
mpg (mpc playlist grep)
From: http://www.musicpd.org/forum/index.php?topic=773.0
This will simply grep the current playlist for all arguments given to it.
[coolcode lang="bash" download="mpg"]#!/bin/bash
mpc playlist | grep -i "$*"[/coolcode]
This is the BEST hack on this page... the mpc playlist is dull, no more! Simply get this script and run playlistbuilder and have your playlist filled with _simular_ songs. Oh, I've slightly modified this, added some instructions and changed up the playlist build. Still... The guy/gal who made this is WONDERFUL! Thanks. :-)
## ABOUT PLAYLISTBUILDER # http://mpd.wikia.com/wiki/Client:Playlistbuilder # # Get the artist of the current song, look up some similar artists, # search your mpd-music for these artists and add 10 random songs of them to the playlist # # playlistbuilder # # Look up your music for artists similar to the Arctic Monkeys and the Kaiser Chiefs # and add 5 similar songs each # # playlistbuilder -i 5 "arctic monkeys" "kaiser chiefs" # # Use the -p (--pretend) switch to do all but the actual appending. # Use the -m (--match) to give an other match-level # (default 90, lower means the artist is less similar but you may got more matches within your music). # Use -s (--silent) to supress non-error output. # With -n (--no-mpd) you can disable the MPD-interaction and only see the list of similar artists.
class Array def random # implement a sort of random-choice self[rand(self.length)] end end
class MPD def self.new_connection host = ( ENV['MPD_HOST'] or 'localhost' ) port = ( ENV['MPD_PORT'] or 6600 ) mpd = self.new host, port try = 0 begin puts "connecting to #{host}:#{port}..." if $options.verbose mpd.connect rescue RuntimeError try += 1 unless try > 3 $stderr.puts "connection failed on #{try}. attempt, retrying..." retry else $stderr.puts "unable to connect" exit 1 end end return mpd end end #class MPD
class Options attr_reader :verbose, :use_mpd, :pretend, :match, :items, :artists def initialize args @verbose = true @use_mpd = true @pretend = false @match = 50 @items = 20 @artists = [] until args.empty? t = args.shift @verbose = false if t == "-s" or t == "--silent" @use_mpd = false if t == "-n" or t == "--no-mpd" @pretend = true if t == "-p" or t == "--pretend" @match = args.shift.to_i if t == "-m" or t == "--match" @items = args.shift.to_i if t == "-i" or t == "--items" @artists.push t unless t[0].chr == "-" if t == "-h" or t == "--help" or t == "-?" puts "some help would be realy nice..." exit 0 end #help end end end #class Options
if $options.artists.empty? and mpd song = mpd.current_song
unless song $stderr.puts "currently not playing, please give an artist as argument" exit 1 end
#puts "#{song.artist} - #{song.title}" $options.artists.push song.artist end
$options.artists.each do |artist_name | # quick and dirty :-/ artist = Scrobbler::Artist.new artist_name
# getting similar artists can take a little time similar = artist.similar.select {|a| a.match.to_f > $options.match} similar_artists = similar.collect {|a| a.name}
if $options.verbose puts "Similar Artists for #{artist_name}:" puts similar_artists end
# continues with the next artist if no mpd invocation is planed next unless $options.use_mpd
# reconnect if we lost meanwhile the connection mpd.connect unless mpd.connected?
songs_by_artist = Hash.new
similar_artists.each do |a| songs = mpd.find "artist", a songs_by_artist[a] = songs unless songs.empty? end
#puts songs_by_artist.to_yaml
if songs_by_artist.empty? puts "no similar artists found in your music-db" exit 0 end
songs_to_add = Array.new # we have to get a new artist array because it can happen # that no songs a found for a similar_artist artists = songs_by_artist.keys
$options.items.times do artist = artists.random song = songs_by_artist[artist].random songs_to_add.push song end
#puts songs_to_add.to_yaml
# reconnect if we lost meanwhile the connection mpd.connect unless mpd.connected?
songs_to_add.each do |song| puts "adding #{song.artist} - #{song.title}" if $options.verbose mpd.add song.file unless $options.pretend end end # each artist
Music Player Command(1) Music Player Command(1)
NAME
mpc - Program for controlling Music Player Daemon (MPD)
SYNOPSIS
mpc []
DESCRIPTION
mpc is a client for MPD, the Music Player Daemon. mpc connects to a MPD
running on a machine on the local network and controls MPD according to
commands and arguments passed to it. If no arguments are passed, cur?
rent status is given.
OPTIONS
--format
Configure the format of song display for status and the
playlist. The metadata delimeters are "%name%", "%artist%",
"%album%", "%title%", "%track%", "%time%", and "%file%". The []
operator is used to group output such that if no metadata
delimeters are found or matched between ’[’ and ’]’, then none
of the characters between ’[’ and ’]’ are output. ’&’ and ’|’
are logical operators for and and or. ’#’ is used to escape
characters. Some useful examples for format are: "%file%" and
"[
<?php artist% - ]%title ?>
|
<?php file ?>
"
--no-status
Prevents the current song status from being printed on comple?
tion of some of the commands.
COMMANDS
add
Adds a song from the music database to the playlist. Can also
read input from pipes. Use "mpc ls | mpc add" to add all files
to the playlist.
clear Empties playlist.
crop Remove all songs except for the currently playing song.
crossfade []
Gets and sets the current amount of crossfading between songs (0
disables crossfading).
del
Removes a song from the playlist. Can also read input from
pipes.
disable