-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpc.jamendo.add
executable file
·73 lines (64 loc) · 1.56 KB
/
mpc.jamendo.add
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# by marbu, 2008, 2013
BASE_URL="http://www.jamendo.com/"
ALBUM_URL="${BASE_URL}get/track/id/album/audio/play/"
TRACK_URL="${BASE_URL}get/track/id/track/audio/play/"
show_help() {
NAME=$(basename $0)
echo -e "$NAME -- simple MPD interface for jamendo.com\n"
echo "Usage: $NAME [-p] [-c codec] jamendo_url"
echo -e "\nOptions:"
echo " -p play immediatelly (append to current playlist)"
echo " -c codec to use (mp3 or ogg)"
echo " -d debug mode"
echo " -h this message"
}
log()
{
echo $1 >> $HOME/local/var/mpc-jamendo-add.log
}
mpd_add()
{
URL="$1"
ENC="mp31"
case $CODEC in
ogg|ogg1) ENC="ogg1";; # lowfi OGG (q-1)
ogg2) ENC="ogg2";; # lowfi OGG q4
mp3) ENC="mp31";; # lowfi MP3 (96kbits) (default for streaming)
esac
if [[ "$URL" =~ ^${BASE_URL}.*/a([0-9]+)/?.*$ ]]; then
PLAYLIST_URL=${ALBUM_URL}${BASH_REMATCH[1]}${ENC:+&aue=$ENC}
elif [[ "$URL" =~ ^${BASE_URL}.*track/([0-9]+)/?.*$ ]]; then
PLAYLIST_URL=${TRACK_URL}${BASH_REMATCH[1]}${ENC:+&aue=$ENC}
else
echo "wrong URL: $URL" >&2
exit 1
fi
if [[ $DEBUG ]]; then
echo $PLAYLIST_URL
else
log "$PLAYLIST_URL"
[[ $PLAY ]] && POS_OLD=$(mpc playlist | wc -l)
wget -O - "$PLAYLIST_URL" | tee ~/local/var/jamendo.last.m3u \
| sed '/^#/d' | mpc add
[[ $PLAY ]] && mpc play $(($POS_OLD+1))
fi
}
#
# main
#
if [[ $# = 0 ]]; then
show_help
exit
fi
while getopts "dpc:h" OPT; do
case $OPT in
d) DEBUG=echo;;
p) PLAY=1;;
c) CODEC=$OPTARG;;
h) show_help;
exit;;
esac
done
shift $(($OPTIND-1))
mpd_add $1