2019-02-28 14:35:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
2019-02-28 15:00:58 +00:00
|
|
|
declare -A streamalias
|
|
|
|
|
2019-02-28 14:35:41 +00:00
|
|
|
source ${HOME}/bin/script_framework.sh
|
|
|
|
|
2019-02-28 15:00:58 +00:00
|
|
|
[ -f ${HOME}/.config/mpc-yt.cfg ] && source ${HOME}/.config/mpc-yt.cfg
|
|
|
|
|
2019-02-28 14:35:41 +00:00
|
|
|
ydl=$(which youtube-dl)
|
|
|
|
yurl=${1:-}
|
|
|
|
|
|
|
|
[ -n "${ydl}" ] || fail "Missing youtube-dl command"
|
|
|
|
[ -n "${yurl}" ] || fail "Missing YouTube URL"
|
|
|
|
|
2019-02-28 15:00:58 +00:00
|
|
|
[ -n "${streamalias[${yurl}]:-}" ] && {
|
|
|
|
info "Found alias \"${yurl}\", continuing with configured URL \"${streamalias[${yurl}]}\""
|
|
|
|
yurl=${streamalias[${yurl}]}
|
|
|
|
}
|
|
|
|
|
2019-02-28 14:35:41 +00:00
|
|
|
step "Fetching video information..."
|
|
|
|
title=$(${ydl} -e ${yurl})
|
|
|
|
playlist=$(${ydl} -g ${yurl})
|
|
|
|
|
2019-02-28 14:42:56 +00:00
|
|
|
success "Found \"${title}\""
|
|
|
|
|
2019-02-28 14:35:41 +00:00
|
|
|
step "Writing playlist..."
|
|
|
|
cat -s <<EOF >${HOME}/.config/mpd/playlists/mpc-yt.m3u
|
|
|
|
#EXTM3U
|
|
|
|
#EXTINF:0,${title}
|
|
|
|
${playlist}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
step "Loading playlist and starting playback..."
|
|
|
|
mpc clear
|
|
|
|
mpc load mpc-yt
|
|
|
|
mpc play
|