Search code examples
bashshellcurlyoutubeyoutube-dl

How to read the name of song in terminal after user input and download mp3 from youtube


I try to use this code and pass a parameter in comand line to a file with script,but it's not working, its only read what i input and dont download mp3. How can I first enter the name of song in the comand line, then take this name to script and download mp3 song from youtube video? Maybe dont use parameters, only use read comand, and after pass name song in script and download mp3 from youtube video.

curl -s "${1} ${2}" | grep '<span class="title video-title "' | cut -d\> -f2 | cut -d\< -f1
curl -s "${1} ${2}"  | grep "watch?" | cut -d\" -f4| while read video;
do youtube-dl -x --audio-format mp3 "http://www.youtube.com$video"/home/viacheslav/IdeaProjects/untitled/untitled/script
done

Solution

  • Use the ytsearch: keyword to search on YouTube:

    read -p 'Song name: ' SONG
    youtube-dl -x --audio-format mp3 "ytsearch:$SONG"