Skip to content

Instantly share code, notes, and snippets.

@bluenex
Last active August 29, 2015 14:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bluenex/40496729bc721d7b4be0 to your computer and use it in GitHub Desktop.
Save bluenex/40496729bc721d7b4be0 to your computer and use it in GitHub Desktop.

youtube-dl add-on

This add-on is to:

  • bypass certification checking for youtude-dl (2015.04.26) on OSX (10.10.3)
  • pass through proxy (MU proxy)
  • download the best quality of audio or video
  • save to ~/Music/youtube-dl

note Since the latest update of youtube-dl (2015.08.23) and OSX (10.10.4), there is no need to bypass certificate anymore. The proxy also seems to be fixed (by importing system proxy.. maybe). However, the options will remain until I'm sure to take them out later.

requirements

Only youtube-dl is needed now.

pip install --upgrade youtube-dl

where to place snippet

sudo nano ~/.bash_profile

function

# youtube-dl
# due to certification error, this alias is to bypass

chk-ytdl-dir() {
if [ ! -d ~/Music/youtube-dl ]; then
  mkdir ~/Music/youtube-dl
  echo "created ~/Music/youtube-dl"
fi
}

ytdl() {
  ## checking
  testlen=$1
  if [[ $# -gt 2 ]]; then
    echo "Only 2 arguments are allowed!"
    return 1
  fi
  if [[ ${#testlen} -gt 4 ]]; then
    echo "Maximum length of option is 4.. (-sph or -vph)"
    return 1
  fi
  if [[ $1 == *"s"* && $1 == *"v"* ]]; then
    echo "Could not download both song and video at once!"
    return 1
  fi

  ## downloading
  curdir="$PWD"
  if [[ $1 != *"h"* ]]; then
    chk-ytdl-dir
    cd ~/Music/youtube-dl/
  else
    echo "Download to current path.."
  fi
  if [[ $1 == *"s"* ]]; then
    echo "Downloading song.."
    if [[ $1 == *"p"* ]]; then
      echo "With proxy.."
      youtube-dl -o "%(title)s.%(ext)s" -f "m4a" --proxy "" --no-check-certificate $2
    else
      youtube-dl -o "%(title)s.%(ext)s" -f "m4a" --no-check-certificate $2
    fi
  elif [[ $1 == *"v"* ]]; then
    echo "Downloading video.."
    if [[ $1 == *"p"* ]]; then
      echo "With proxy.."
      youtube-dl -o "%(title)s.%(ext)s" -f "best" --proxy "" --no-check-certificate $2
    else
      youtube-dl -o "%(title)s.%(ext)s" -f "best" --no-check-certificate $2
    fi
  else
    echo "No satisfied parameters filled.."
    echo "Please use -s for song, -v for video, -p if proxy and -h to save to current path."
  fi
  cd $curdir
}

usage

option:

  • -s download song.
  • -v download video.
  • -p if being behind MU proxy.
  • -h download to current path.

youtube link: https://www.youtube.com/watch?v=Iwc81dpA008

ytdl -s https://www.youtube.com/watch?v=Iwc81dpA008
ytdl -sp https://www.youtube.com/watch?v=Iwc81dpA008
ytdl -vh https://www.youtube.com/watch?v=Iwc81dpA008
ytdl -vph https://www.youtube.com/watch?v=Iwc81dpA008

note

  • Cannot download both song and video at once!
  • .m4a is supposed to be best format, but recently is being substituted by .webm. Anyway, I prefer .m4a because it's more widely supported.
  • Converter to .mp3 and .m4a will be included in the future.
@titipata
Copy link

I want to put whole youtube link instead of just Iwc81dpA008. It's a bit harder to use. However, overall are great tho, good work!

@z-zawhtet-a
Copy link

Awesome! Now enjoying with cmus!

@bluenex
Copy link
Author

bluenex commented May 12, 2015

@titipata I didn't realize that there is a built-in feature from youtube-dl itself that works with both full url and only video code. Right now it's fine by using either full link or just video code (Iwc81dpA008).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment