[multimedia] Add just-play-something.sh
MPC/MPD script to start playing "just something".
This commit is contained in:
parent
cea79af10f
commit
42284c9f9f
|
@ -1,3 +1,39 @@
|
|||
# just-play-something.sh #
|
||||
|
||||
As its name indicates, the main goal of just-play-something.sh is to put
|
||||
some music on. Just anything. What the name doesn't indicate is that the
|
||||
music is played by MPD.
|
||||
|
||||
Its use case is to be binded to a physical button of my router (which is
|
||||
also my music box), so that I don't have to start a device with an MPD
|
||||
client to start music (this is especially useful when I first wake up in
|
||||
the morning). Therefore, it is written with portability in mind and
|
||||
doesn't use any utility that might not be present on embedded systems.
|
||||
Here are the required dependencies (beside MPD itself and its
|
||||
command-like client, mpc):
|
||||
- time
|
||||
- ps
|
||||
- date
|
||||
- md5sum
|
||||
- sed
|
||||
|
||||
What this script will do for you:
|
||||
- first of all, if the MPD daemon looks down, it will be restarted;
|
||||
then,
|
||||
- if there are songs in the playlist but the playback is paused, it will
|
||||
unpause;
|
||||
- if there are songs in the playlist but the playback is stopped, it
|
||||
will start playing the playlist from the begining;
|
||||
- if there are no songs in the playlist, it will add a random album from
|
||||
your library and play it;
|
||||
- if music is already playing, it will be paused.
|
||||
|
||||
Tip: you can bind a short button press to just-play-something, and a
|
||||
long press (or another button) to mpc clear && just-play-something, so
|
||||
that if you don't like what is currently in the playlist, you can force
|
||||
playing a random album with a long press.
|
||||
|
||||
|
||||
# metflac-field2field.sh #
|
||||
|
||||
[Français ci-dessous.]
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# just-play-something.sh, Copyright © 2013 Matteo Cypriani
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
#
|
||||
# This script's goal is to put some music on on your MPD server, with
|
||||
# some additional features: restart the server if it doesn't respond,
|
||||
# add a random album to the playlist if it's empty, and pause the music
|
||||
# if something is playing already.
|
||||
|
||||
#set -x
|
||||
|
||||
TIME="/usr/bin/time 2>&1"
|
||||
|
||||
# Returns a random number between 1 and its first argument
|
||||
random()
|
||||
{
|
||||
MAX=$1
|
||||
RAND=0`(echo $$ ; /usr/bin/time ps 2>&1 ; date) | md5sum | sed 's/[a-z]//g' | sed -r 's/(.{8}).*/\1/'`
|
||||
expr $RAND % $MAX + 1
|
||||
}
|
||||
|
||||
# If we can't reach the server, restart it
|
||||
if ! mpc >/dev/null 2>&1 ; then
|
||||
/etc/init.d/mpd restart
|
||||
fi
|
||||
|
||||
# If the playlist is empty, add a random album to the playlist
|
||||
if [ "$(mpc playlist 2>/devlnull)" = "" ] ; then
|
||||
NB_ALBUMS=`mpc list Album | wc -l`
|
||||
RAND_ALBUM_NUM=`random $NB_ALBUMS`
|
||||
RANDOM_ALBUM=`mpc list Album | sed -n ${RAND_ALBUM_NUM}p`
|
||||
mpc findadd Album "$RANDOM_ALBUM"
|
||||
fi
|
||||
|
||||
# Start playing or toggle pause
|
||||
mpc toggle >/dev/null 2>&1
|
Loading…
Reference in New Issue