Last active
August 29, 2015 14:23
-
-
Save zuloo/b06244f45c2ae0f055a6 to your computer and use it in GitHub Desktop.
play Youtube audio with mpd [ use as external browser in w3m or links ]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add a helpfull function to search youtube in w3m | |
tube (){ w3m "https://youtube.com/results?search_query=`echo $* | sed 's/[ ]/+/g'`" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
clear | |
# choose if we should load link in firefox or use youtube-dl | |
read -p "use (m)pc or graphical (b)rowser to open link? [m] :" -n 1 CHOICE | |
[[ "$CHOICE" == "b" ]] && { /usr/bin/sensible-browser $1 2> /dev/null >&1 & } && exit 0 | |
# install with: pip install --user youtube-dl | |
TUBE=$HOME/.local/bin/youtube-dl | |
# get all Formats here and search for m4a, return format codes | |
FORMAT=`$TUBE -F $1 | grep 'm4a' | cut -c -3` | |
# choose either 141 [256 kbit/s m4a] of 140 [ | |
FORMAT=$( [[ $FORMAT =~ 141 ]] && echo 141 || echo `[[ $FORMAT =~ 140 ]] && echo 140` ) | |
# if no suitable format given just die | |
if [ "$FORMAT" == "" ]; then | |
# or use mpg123 or some other soundfile, i like these two from KDE | |
echo "ERROR: no suitable audio only format found" | |
ogg123 /usr/share/sounds/KDE-Im-Contact-Out.ogg 2> /dev/null >&2 & | |
exit 1 | |
fi | |
clear | |
# decide if we flush the list and excusively play that song | |
read -p "(a)ppend to playlist, or (f)lush playlist before? [a]: " -n 1 CHOICE | |
[[ "$CHOICE" == "f" ]] && mpc clear > /dev/null | |
# add link to right format to playlist | |
mpc add `$TUBE -f$FORMAT -g $1` > /dev/null | |
# because my statusbar wants a nice title to display instead of the huge link | |
echo "[YouTube] `$TUBE -e $1`" > /run/user/1000/mpd-youtube-title.nfo | |
# play | |
mpc play > /dev/null | |
# or use mpg123 or some other soundfile, i like these two from KDE | |
ogg123 /usr/share/sounds/KDE-Im-Contact-In.ogg 2> /dev/null >&2 & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you will have to specify tubelink.sh as external browser in your w3m / links options