# Accessing youtube videos with edbrowse. Command line tools such as cclive can download most youtube videos, though not all videos. If the video is copyright protected, cclive returns an error. Search for something on youtube, then note the url of the page. Pass this as an argument to cclive. This will download the video as a file, in one of several formats. From here you can convert it to your favorite format, such as mp3, using ffmpeg, or simply play it directly using mpv. ``` ffmpeg -i foobar.webm foobar.mp3 ``` Play the resulting mp3 file with mpg123. This is a recurring theme: download the file, convert it to mp3, and use mpg123, which has nice features like pause, fast forward, rewind, jump to index 1 through 0, etc. Here are some edbrowse functions to locate, and then download a youtube video. # youtube search, look for something on youtube function+yts { b http://www.youtube.com/results?search_query=~0 } If a link looks like what you want, don't go to it, run this script to download the video. If the download is successful you can listen to it, or keep it for your archive. # youtube extract function. function+yte { db0 H- ebvar+ A 1s/^.*?href=//f s/>$//f !cclive '. bw ^ } # if you just want to listen to the youtube video function+ytl { db0 H- ebvar+ A 1s/^.*?href=//f s/>$//f !mpv --really-quiet '. bw ^ } # second link, same as the first function+ytl2 { db0 H- ebvar+ A 4s/^.*?href=//f s/>$//f !mpv --really-quiet '. bw ^ } If you don't have mpv, or it just doesn't work on a particular video, put this ytl script in your bin and call it instead of mpv above. This is not the best approach because it downloads the entire video, then plays it, and in listen mode you don't really need to do that. # youtube listen script in your PATH # go to your edbrowse temp directory cd /tmp/.edbrowse/`id -u` # assumes there are no mp4 files or webm files in this directory! # Use either cclive or youtube-dl if youtube-dl "$1" then if [ -f *.mp4 ] then mpv --really-quiet *.mp4 rm *.mp4 fi if [ -f *.webm ] then mpv --really-quiet *.webm rm *.webm fi fi If you have edbrowse 3.6.3 or above, then you don't need any ytl functions or scripts at all. use the urlmatch feature to establish certain youtube pages as streams, and play them with mpv. Your plugin might look like this. plugin { type = audio/x-pn-realaudio desc = streaming audio stream protocol = rtsp,pnm,sdp,pls suffix = rm,ra,ram,ogg,m3u,m3u8,mp4 urlmatch = youtube.com/watch?|youtube.com/embed/ content = audio/x-scpls,application/pls+xml program = /usr/bin/mpv --really-quiet --load-unsafe-playlists %i }