Skip to content

Commit

Permalink
cleaned up formatting & style consistency, reworded feedback to be mo…
Browse files Browse the repository at this point in the history
…re descriptive.
  • Loading branch information
VidiotGeek committed Sep 18, 2022
1 parent efe514f commit 67c96a5
Showing 1 changed file with 45 additions and 32 deletions.
77 changes: 45 additions & 32 deletions easy-ytdl.command
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ RED=$'\e[0;31m'
YELLOW=$'\e[0;33m'
BLUE=$'\e[1;34m'
GREEN=$'\e[0;32m'
GREENITALIC=$'\e[3;32m'
CYAN=$'\e[0;36m'
PURPLE=$'\e[0;35m'
YINVERT=$'\e[43;30m'
Expand All @@ -66,62 +67,68 @@ YTBE='youtu.be'
function run_easy_ytdl () {
# Make a save folder on the desktop, because your download folder is probably also cluttered.
SAVE_DIR=$HOME/Desktop/YTDL-Downloads
if ! -d $SAVE_DIR ; then
if [ ! -d $SAVE_DIR ]; then
mkdir $SAVE_DIR && cd $SAVE_DIR
else
cd $SAVE_DIR
fi
clear
printf '\e[3;32m%-6s\a\e[m\n' "============================= Easy YouTube-DL ================================="
printf '%s\n' "Please paste the YouTube URL you would like to download below."
printf '%s\n\n' "Must be \"$RED$YTCOM$NOCOLOR\", not \"$RED$YTBE$NOCOLOR\". The file will be saved to $BLUE$SAVE_DIR$NOCOLOR."
printf '%s' $YELLOW "URL:$NOCOLOR "
printf '%-6s\n' "${GREENITALIC}============================= Easy YouTube-DL =================================${NOCOLOR}"
printf '%s\n' "Please paste the YouTube URL you would like to download at the prompt below."
printf '%s\n' "The link must be to \"$RED$YTCOM$NOCOLOR\", and not \"$RED$YTBE$NOCOLOR\" in order to work."
printf '%s\n\n' "Your file will be saved to $BLUE$SAVE_DIR$NOCOLOR."
printf '%s' "${YELLOW}URL:${NOCOLOR} "
read link_to_download
printf '\n\e[3;32m%-6s\a\e[m\n' "==============================================================================="
youtube-dl "$link_to_download" && printf '\n\n%s\n\n' "$PURPLE You may now close this window$NOCOLOR" && open $SAVE_DIR && exit 0
printf '\n%-6s\n' "${GREENITALIC}===============================================================================${NOCOLOR}"
youtube-dl "$link_to_download" && printf '\n\n%s\n\n' "${PURPLE}You may now close this window.${NOCOLOR}" && open $SAVE_DIR && exit 0
}

# Ask user if they want to download a video now.
# After installation, ask user if they want to download a video now.
function ask_download_video () {
printf '%s\n' "Would you like to download a video now? (yes/no)"
printf '%s\n' "Would you like to download a video now? (yes/no) "
read now_or_later
case $now_or_later in
y|Y|yes|Yes|YES) run_easy_ytdl
;;
*) echo "Goodbye!"
*) printf '%s\n\n' "The next time you run this script, we will jump straight to the download prompt. Goodbye!"
exit 0
;;
esac
}

# Upon successful curl or wget installation, run a checksum to confirm good file download.
# Checksums for homebrew and pip installed executables are not published, that I could find.
function run_checksum () {
printf '\n%s\n\n' "To verify install, compare this$GREEN SHA256 hash$NOCOLOR to the published one at$BLUE https://ytdl-org.github.io/youtube-dl/download.html$NOCOLOR" &&
printf '\n%s\n\n' "To verify install, compare this ${GREEN}SHA256 hash${NOCOLOR} to the published one at ${BLUE}https://ytdl-org.github.io/youtube-dl/download.html${NOCOLOR}" &&
shasum -a 256 /usr/local/bin/youtube-dl &&
printf '\n%s\n' "If the checksums do not match, the download may be incomplete, corrupt, or modified. In which case, we should remove it."
function confirm_sum () {
printf '%s' "Do they match? (yes/no): " && read matched
printf '\n%s\n' "If the checksums do not match, the download may be incomplete, corrupt, or modified. Choosing ${RED}\"NO\"${NOCOLOR} will remove the copy of youtube-dl that we just installed."
function confirm_checksum () {
printf '%s' "Do they match? (yes/no/skip): " && read matched
case $matched in
y|Y|yes|Yes|YES) printf '\n\e[0;32m%s\e[0m\n' "Congratulations! youtube-dl is now installed."
y|Y|yes|Yes|YES) printf '\n%s\n' "${GREEN}Congratulations! youtube-dl is now installed.${NOCOLOR}"
ask_download_video
;;
n|N|no|No|NO) printf '\n%s\n' "Removing youtube-dl" && rm -vi /usr/local/bin/youtube-dl && exit 0
n|N|no|No|NO) printf '\n%s\n' "$(RED)Removing youtube-dl executable\!${NOCOLOR}" && rm -vi /usr/local/bin/youtube-dl && exit 0
;;
s|S|skip|Skip|SKIP) printf '\n%s\n' "${YELLOW}Skipping verification.${NOCOLOR} youtube-dl is now installed."
ask_download_video
;;
*) printf '%s\n' "Look again, if the first and last few characters match, then we are good to go."
confirm_sum
printf '%s\n' "Otherwise if you'd like to skip this step, type \"${YELLOW}skip.${NOCOLOR}\""
confirm_checksum
;;
esac
}
confirm_sum
confirm_checksum
}

# Define all install method functions so they can be called below.

# Possible download methods per https://yt-dl.org.
function install_ytdl_brew () {
# Easiest alternative install method is Homebrew, which we've confirmed is present.
# Although, if the user has Homebrew, they're savvy enough not to need this script...
brew install youtube-dl &&
printf '\n\e[0;32m%s\e[0m\n' "Congratulations! youtube-dl is now installed."
printf '\n%s\n' "${GREEN}Congratulations! youtube-dl is now installed.${NOCOLOR}"
ask_download_video
}

function install_ytdl_curl () {
Expand All @@ -139,10 +146,11 @@ function install_ytdl_wget () {
function install_ytdl_pip () {
# We did not have curl or wget, proceeding with pip as third recommended install method.
sudo pip install --upgrade youtube-dl &&
printf '\n\e[0;32m%s\e[0m\n' "Congratulations! youtube-dl is now installed."
printf '\n%s\n' "${GREEN}Congratulations! youtube-dl is now installed.${NOCOLOR}"
ask_download_video
}

# How should we install youtube-dl?
function test_install_methods () {
if ! command -v brew &> /dev/null; then
# We don't have Homebrew as the easiest install option.
Expand All @@ -152,8 +160,8 @@ if ! command -v brew &> /dev/null; then
# We also can't use wget to install.
if ! command -v pip &> /dev/null ; then
printf '%s\n' "Sorry, we seem to have none of four possible install methods."
printf '%s\n' "Please see additional info at $GREEN https://yt-dl.org/"
exit 0
printf '%s\n' "Please see additional info at ${GREEN}https://yt-dl.org/${NOCOLOR}"
exit 1
else
install_ytdl_pip
fi
Expand All @@ -168,35 +176,39 @@ else
fi
}

# Do we need to install Python?
function test_python () {
if ! command -v python &> /dev/null ; then
# We also don't have python. Prompt for Python install.
echo "Sorry, Python 2.6 or later is a requirement for youtube-dl and this system doesn't have it"
read -p "Do you want to install it from www.python.org and try again? (yes/no): " "get_python"
printf '%s\n' "Sorry, Python 2.6 or later is a requirement for youtube-dl and this system doesn't have it"
printf '%s' "Do you want to manually install it from www.python.org and try this script again? (yes/no): "
read get_python
case $get_python in
y|Y|yes|Yes|YES) open "https://www.python.org/downloads/"
y|Y|yes|Yes|YES) open "https://www.python.org/downloads/" && exit 0
;;
*) exit 0
*) exit 1
;;
esac
else
# We've confirmed Python is present. Can we write to the default install location?
if -w /usr/local/bin ; then
echo "Sorry, youtube-dl could not be found. Would you like to download and install it?"
read -p "(yes/no): " "get_youtube_dl"
printf '%s' "Sorry, youtube-dl could not be found. Would you like to download and install it? (yes/no): "
read get_youtube_dl
case "$get_youtube_dl" in
y|Y|yes|Yes|YES) echo "Proceeding..."
y|Y|yes|Yes|YES) printf '%s\n\n' "Proceeding..."
test_install_methods
;;
*) exit 0
;;
esac
else
echo "Sorry, the user $USER is not able to write to the install location at /usr/local/bin."
printf '%s\n' "Sorry, the user $USER is not able to write to the install location at /usr/local/bin."
printf '%s\n' "Login as an administrator and try again." && exit 1
fi
fi
}

# Do we need to install youtube-dl?
function test_youtube_dl () {
if ! command -v youtube-dl &> /dev/null ; then
# We don't have it. Do we have Python as a requirement?
Expand All @@ -205,4 +217,5 @@ function test_youtube_dl () {
run_easy_ytdl
fi
}

test_youtube_dl

0 comments on commit 67c96a5

Please sign in to comment.