forked from superjamie/snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpyt
30 lines (26 loc) · 769 Bytes
/
mpyt
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
#!/bin/bash
# script to take a youtube video url and add it to the running mpd
# requires: mpc, mpd, youtube-dl
if [[ "$#" -lt "1" ]] || [[ "$(echo "$1" | egrep -c "^https?\:\/\/")" == "0" ]]
then
ME="$(basename "$0")"
echo " $ME: adds a youtube url to mpd playlist"
echo " Usage: $ME [youtube-url]"
exit 1
fi
# http://www.genyoutube.net/formats-resolution-youtube-videos.html
for fmt in {139..141}
do
AUDIOURL=$(youtube-dl -f "$fmt" -g "$1" 2>/dev/null)
if [[ "$?" == "0" ]]; then break; fi
done
# check we actually found a URL
if [[ "$(echo "$AUDIOURL" | egrep -c "^https?\:\/\/")" -gt "0" ]]
then
#echo "AUDIOURL: $AUDIOURL"
mpc add "$AUDIOURL"
mpc play
else
echo "[ERROR] Couldn't find audio stream for $1"
exit 1
fi