# Youtube to mpd
2022-06-06T14:57:30Z

Below a script taking a youtube url as argument. The audio is extracted, then added to the mpd library, inserted in the playlist then played.

```
#!/bin/sh
# download sound from youtube, convert to $format,
# then insert and play in mpd

format="flac"

MUSDIR=$(awk '/music_directory/ {sub("^\"","",$2);sub("\"$","",$2); print $2}' $HOME/.mpdconf)

cd ${MUSDIR}
yt-dlp --no-playlist -x \
       --audio-format $format \
       -c "${1}" \
       -o "%(title)s.%(ext)s" \
       --exec "mpc --wait update && mpc insert \"%(title)s.%(ext)s\" && mpc next"
```