File [scripts/random_mpd_tracks.sh]
1 |
#!/bin/bash |
2 |
if [ $# -eq 0 ]; then |
3 |
echo "usage $0 host" |
4 |
exit 1 |
5 |
fi |
6 |
# Define the path and any password options for MPD |
7 |
MY_MPC="/usr/bin/mpc -h $1" |
8 |
while [ 1 ]; do |
9 |
# Check if the server is up and running |
10 |
ping -c 2 -W 1 $1 2>&;1>/dev/null |
11 |
if [ $? -eq 0 ]; then |
12 |
echo "$1 is alive..." |
13 |
# Check if MPD is up and running |
14 |
$MY_MPC status |
15 |
if [ $? -eq 0 ]; then |
16 |
echo "MPD is running..." |
17 |
# We're alive, so let's play |
18 |
# First let's see how many tracks are in the playlist |
19 |
number_of_tracks=`$MY_MPC playlist | wc -l` |
20 |
# If we have less than 2 tracks playing, add random(s) |
21 |
# Why 2? Well it ensures no break in the music |
22 |
if [ $number_of_tracks -lt 2 ]; then |
23 |
echo "Adding tracks..." |
24 |
# How many tracks needed? |
25 |
number_to_add=`expr 2 - $number_of_tracks` |
26 |
random_tracks=`cat /tmp/random_mpd_tracks.txt | shuf -n $number_to_add` |
27 |
# Add it to the play list |
28 |
$MY_MPC add $random_tracks |
29 |
fi |
30 |
# Set up the playing style |
31 |
$MY_MPC -q single off |
32 |
$MY_MPC -q random off |
33 |
$MY_MPC -q repeat off |
34 |
$MY_MPC -q consume on |
35 |
# Press "play" :-) |
36 |
$MY_MPC -q play |
37 |
fi |
38 |
fi |
39 |
sleep 10 |
40 |
done |
Computing Power
- Acer Aspire R3700
- Acknowledgements
- BOINC
- Desktop PC
- Eee PC 4G (701)
- Eee PC 901
- Gigabit Network
- Inspiron 14 5485 Laptop
- Kids PC 1
- Kids PC 2
- Media PC
- Mini-ITX PC
- My Useful Scripts
- Nano ITX PC
- Nook Simple Touch
- Processing Power
- Raspberry Pi
- Sharp Zaurus SL-C3200
- Storage Capacity
- The Server
- What Is Firmware
Galleries
(* updated in last 14 days)