Skip to content
Karl Dahlke edited this page Feb 12, 2017 · 12 revisions

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 probably convert it to your favorite format, such as mp3, using ffmpeg, or simply play it directly using mpv.

ffmpeg -i foobar.3gpp 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 {
    A
    1s/^.*?href=//
    s/>$//
    !cclive "'."
    bw
    ^
}

#  if you just want to listen to the youtube video
function+ytl {
    A
    1s/^.*?href=//
    s/>$//
# assumes the bash script ytl is in your command path
    !ytl "'."
    bw
    ^
}

#  second link, same as the first
function+ytl2 {
    A
    4s/^.*?href=//
    s/>$//
    !ytl "'."
    bw
    ^
}

#  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!
if cclive "$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