Poor Man's Youtube Downloader

hakerdefo



(11 September 2016) UPDATE BEGINS:

Added support to download videos in 4K and 1080P resolutions.
You can now download entire playlists in 4K -1080P resolutions.
Improved audio only download function. Audio only downloads are much faster now.
Suppressed scary & pointless youtube-dl warnings.

The script has become a bit too big to paste here directly so I'm linking the GitHub repo of pmytd here,
pmytd on GitHub
Please check-out the GitHub repo and update pmytd.

Cheers!!!

(11 September 2016) UPDATE ENDS:





(04 September 2016) UPDATE BEGINS:
A major update! Almost a complete rewrite!
Fixed the youtube-dl update function.
Added dependency check in the script.
Added option to install youtube-dl if it's not available.
Added option to download the video in the best quality skipping the manual selection. Thanks a & Snap!
And many other improvements.
The script has become a bit too big to paste here directly so I'm linking the GitHub repo of pmytd here,
pmytd on GitHub
Please check-out the GitHub repo and update pmytd.
Cheers!!!
(04 September 2016) UPDATE ENDS:





(23 August 2015) UPDATE BEGINS:
Removed overly complicated sudo availability check. Improved update-check part.
So here it is, the latest-greatest version of pmytd.


#!/bin/bash

function ByE (){
clear
echo ""
echo -e '\E[1;31;40m'"It's "'\E[1;32;40m'"funny "'\E[1;33;40m'" how"'\E[1;35;40m'" the"'\E[1;36;40m'" colors"'\E[1;31;40m'" of"'\E[1;32;40m'" the"'\E[1;33;40m'" real"'\E[1;35;40m'" world"'\E[1;36;40m'" only"'\E[1;31;40m'" seem"'\E[1;32;40m'" really"'\E[1;33;40m'" real"
echo -e '\E[1;36;40m'"when "'\E[1;31;40m'"you "'\E[1;32;40m'"viddy "'\E[1;33;40m'"them "'\E[1;35;40m'"on "'\E[1;36;40m'"the "'\E[1;31;40m'"screen."
echo ""
echo -e '\e[0m'"Alex, A Clockwork Orange"
echo ""
sleep 4
clear
exit 0
}

function HelP (){
clear
printf "%s\n" "" "Having problems running PMYTD?" "" "First make sure you have all the required dependencies installed." "You can read more about it in 'Dependencies of PMYTD' option" "in PMYTD MENU." "" "Having problems downloading videos?" "" "Youtube and other video sharing sites continually change their APIs." "So it is advised to keep youtube-dl updated to latest version." "You can check for youtube-dl updates via 'Check for updates' option" "in PMYTD MENU." "If there is a newer version available then please update youtube-dl." "" "For any other queries you can contact me at," "http://hakerdefo.blogspot.com" "" "Press 'q' to return to PMYTD MENU" "" | less
}

function UpdatE (){
clear
ping -q -c 2 yt-dl.org >/dev/null 2>&1 || { clear; echo -e "Can't connect to youtube-dl server! Please try later!" >&2; read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key; MenU; }
ytdllv=$(curl -sL -w "%{url_effective}\\n" "https://yt-dl.org/downloads/latest/" -o /dev/null | cut -c 29- | sed 's/[/]//g')
ytdlcv=$(youtube-dl --version)
if [ "$ytdllv" == "$ytdlcv" ]; then
echo ""
echo -e "Installed version of youtube-dl - $ytdlcv"
echo -e "Available version of youtube-dl - $ytdllv"
echo ""
echo -e "youtube-dl is up-to-date."
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
else
echo ""
echo -e "Installed version of youtube-dl - $ytdlcv"
echo -e "Available version of youtube-dl - $ytdllv"
echo ""
echo -e "youtube-dl update is available."
echo ""
echo -e "Would you like to update youtube-dl?"
echo ""
echo -e "01 Update youtube-dl"
echo -e "02 Return to PMYTD MENU"
echo ""
echo -e "Enter your choice: "
echo ""
read choice
case $choice in
1 | 01)
clear
ytdll=$(which youtube-dl)
if [ -w "$ytdll" ]; then
youtube-dl -U
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
else
resu=$(whoami)
echo ""
echo "Please enter password for user $resu"
echo ""
sudo youtube-dl -U
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
fi
;;
2 | 02)
clear
MenU
;;
*)
clear
echo ""
echo -e "$choice is an invalid option!"
echo ""
sleep 4
UpdatE
;;
esac
fi
}

function DiE(){
clear
echo ""
echo -e "OOPS!!! Something Went Wrong!!!"
echo -e "Please make sure '$link' exists."
echo -e "Also make sure video is available."
echo ""
exit 1
}

function AplS(){
clear
printf "%s\n" "" "Enter the youtube playlist link: " ""
read link
clear
youtube-dl --continue --yes-playlist --ignore-errors --extract-audio --audio-format "mp3" --audio-quality 0 --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
}

function VplS(){
clear
printf "%s\n" "" "Enter the youtube playlist link: " ""
read link
clear
youtube-dl --continue --yes-playlist --ignore-errors --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
}

function AudiO(){
clear
printf "%s\n" "" "Enter the youtube video link: " ""
read link
clear
youtube-dl --continue --extract-audio --audio-format "mp3" --audio-quality 0 --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
}

function FormaT(){
clear
printf "%s\n" "" "Enter the youtube video link: " ""
read link
clear
youtube-dl --list-formats "$link" || DiE
printf "%s\n" "" "Enter your desired video format code from the above list:" ""
read list
clear
youtube-dl --continue --format "$list" --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
}

function DependencieS(){
clear
printf "%s\n" "" "PMYTD needs to have following applications installed in order to function," "" "1. youtube-dl" "A small command-line program to download videos from youtube and other" "video sharing sites. It is available in repos of some distros but it" "would most likely be severly outdated. Here is the right way to install it," "Open terminal and run following commands," "'sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O " "/usr/local/bin/youtube-dl'" "'sudo chmod a+x /usr/local/bin/youtube-dl'" "" "youtube-dl homepage -> https://rg3.github.io/youtube-dl/" "" "2. Python" "Python should most likely be installed by default on your system." "If not install it via your distro's package manager." "" "Python homepage -> http://python.org" "" "3. FFmpeg" "Again ffmpeg should already be installed by default on most distros." "If not install it via your distro's package manager." "In some distros it is called avconv. ffprobe or avprobe are also required." "" "FFmpeg homepage -> https://www.ffmpeg.org/" "" "4. cURL" "curl is an open source command line tool and library for transferring data" "with URL syntax, supporting DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP," "IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMTP, SMTPS," "Telnet and TFTP." "You can easily install it using your package manager." "" "cURL homepage -> http://curl.haxx.se/" "" "5. Ping" "ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an" "ICMP ECHO_RESPONSE from a host or gateway." "ping is part of iputils package. Install iputils via your package manager." "" "iputils homepage -> http://www.skbuff.net/iputils/" "" "6. Downloads directory" "PMYTD is hard-wired to download video and audio to the Downloads directory" "under user's home directory." "Downloads directory should already be there by default but just in case make" "sure you have Downloads directory under your home folder." "" "Press 'q' to return to PMYTD MENU" "" | less
}

function AbouT(){
clear
printf "%s\n" "" "PMYTD is a simple script that can," "" "1. Download videos from youtube and other video sharing
websites." "2. Download and extract audio [mp3] from videos on youtube" "and other video sharing websites." "3. Download entire youtube playlists (video and audio)." "" "" "PMYTD is just a helper script for Ricardo Garcia's wonderful" "youtube-dl." "You can view the list of all supported video sharing websites here," "http://rg3.github.io/youtube-dl/supportedsites.html" "" "By the way PMYTD means Poor Man's YouTube Downloader. PMYTD is" "available under CC0 1.0 Universal licesense." "Got any question-suggestion? Please visit," "http://hakerdefo.blogspot.in/" "" "Press 'q' to return to PMYTD MENU" "" | less
}

function MenU(){
clear
echo ""
echo -e "PMYTD MENU"
echo ""
echo -e "01 About PMYTD"
echo -e "02 Dependencies of PMYTD"
echo -e "03 Download a video"
echo -e "04 Download & extract audio from video"
echo -e "05 Download entire youtube playlist"
echo -e "06 Download & extract audio from playlist"
echo -e "07 Check for updates"
echo -e "08 Help"
echo -e "09 Quit PMYTD"
echo ""
echo -e "Enter your choice: "
echo ""
read choice
case $choice in

01 | 1)
AbouT
;;

02 | 2)
DependencieS
;;

03 | 3)
FormaT
;;

04 | 4)
AudiO
;;

05 | 5)
VplS
;;

06 | 6)
AplS
;;

07 | 7)
UpdatE
;;

08 | 8)
HelP
;;

09 | 9)
ByE
;;

*)
clear
echo ""
echo -e "$choice is an invalid option!"
echo ""
sleep 4
;;

esac
}

while :
do

MenU

done



Cheers!!!



(23 August 2015) UPDATE ENDS:






(09 August 2015) UPDATE BEGINS:
A few cosmetic changes and one important change. Updated Dependencies information.
Here is the latest version,


#!/bin/bash

function ByE (){
clear
echo ""
echo -e '\E[1;31;40m'"It's "'\E[1;32;40m'"funny "'\E[1;33;40m'" how"'\E[1;35;40m'" the"'\E[1;36;40m'" colors"'\E[1;31;40m'" of"'\E[1;32;40m'" the"'\E[1;33;40m'" real"'\E[1;35;40m'" world"'\E[1;36;40m'" only"'\E[1;31;40m'" seem"'\E[1;32;40m'" really"'\E[1;33;40m'" real"
echo -e '\E[1;36;40m'"when "'\E[1;31;40m'"you "'\E[1;32;40m'"viddy "'\E[1;33;40m'"them "'\E[1;35;40m'"on "'\E[1;36;40m'"the "'\E[1;31;40m'"screen."
echo ""
echo -e '\e[0m'"Alex, A Clockwork Orange"
echo ""
sleep 4
clear
exit 0
}

function HelP (){
clear
printf "%s\n" "" "Having problems running PMYTD?" "" "First make sure you have all the required dependencies installed." "You can read more about it in 'Dependencies of PMYTD' option" "in PMYTD MENU." "" "Having problems downloading videos?" "" "Youtube and other video sharing sites continually change their APIs." "So it is advised to keep youtube-dl updated to latest version." "You can check for youtube-dl updates via 'Check for updates' option" "in PMYTD MENU." "If there is a newer version available then please update youtube-dl." "" "For any other queries you can contact me at," "http://hakerdefo.blogspot.com" "" "Press 'q' to return to PMYTD MENU" "" | less
}

function UpdatE (){
clear
ping -q -c 2 yt-dl.org >/dev/null 2>&1 || { clear; echo -e "Can't connect to youtube-dl server! Please try later!" >&2; read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key; MenU; }
ytdllv=$(curl -sL -w "%{url_effective}\\n" "https://yt-dl.org/downloads/latest/" -o /dev/null | tail -c-12 | sed 's/[/]//g')
ytdlcv=$(youtube-dl --version)
if [ "$ytdllv" == "$ytdlcv" ]; then
echo ""
echo -e "Installed version of youtube-dl - $ytdlcv"
echo -e "Available version of youtube-dl - $ytdllv"
echo ""
echo -e "youtube-dl is up-to-date."
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
else
echo ""
echo -e "Installed version of youtube-dl - $ytdlcv"
echo -e "Available version of youtube-dl - $ytdllv"
echo ""
echo -e "youtube-dl update is available."
echo ""
echo -e "Would you like to update youtube-dl?"
echo ""
echo -e "01 Update youtube-dl"
echo -e "02 Return to PMYTD MENU"
echo ""
echo -e "Enter your choice: "
echo ""
read choice
case $choice in
1 | 01)
clear
ytdll=$(which youtube-dl)
if [ -w "$ytdll" ]; then
youtube-dl -U
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
else
resu=$(whoami)
resu_test=$(sudo -u "$resu" -n true >/dev/null 2>&1)
if [[ -z "$resu_test" ]]; then
echo ""
echo -e "Please enter root password"
echo ""
su -c 'youtube-dl -U'
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
else
echo ""
echo "Please enter password for user $resu"
echo ""
sudo youtube-dl -U
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
fi
fi
;;
2 | 02)
clear
MenU
;;
*)
clear
echo ""
echo -e "$choice is an invalid option!"
echo ""
sleep 4
UpdatE
;;
esac
fi
}

function DiE(){
clear
echo ""
echo -e "OOPS!!! Something Went Wrong!!!"
echo -e "Please make sure '$link' exists."
echo -e "Also make sure video is available."
echo ""
exit 1
}

function AplS(){
clear
printf "%s\n" "" "Enter the youtube playlist link: " ""
read link
clear
youtube-dl --continue --yes-playlist --ignore-errors --extract-audio --audio-format "mp3" --audio-quality 0 --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
}

function VplS(){
clear
printf "%s\n" "" "Enter the youtube playlist link: " ""
read link
clear
youtube-dl --continue --yes-playlist --ignore-errors --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
}

function AudiO(){
clear
printf "%s\n" "" "Enter the youtube video link: " ""
read link
clear
youtube-dl --continue --extract-audio --audio-format "mp3" --audio-quality 0 --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
}

function FormaT(){
clear
printf "%s\n" "" "Enter the youtube video link: " ""
read link
clear
youtube-dl --list-formats "$link" || DiE
printf "%s\n" "" "Enter your desired video format code from the above list:" ""
read list
clear
youtube-dl --continue --format "$list" --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
}

function DependencieS(){
clear
printf "%s\n" "" "PMYTD needs to have following applications installed in order to function," "" "1. youtube-dl" "A small command-line program to download videos from youtube and other" "video sharing sites. It is available in repos of some distros but it" "would most likely be severly outdated. Here is the right way to install it," "Open terminal and run following commands," "'sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O " "/usr/local/bin/youtube-dl'" "'sudo chmod a+x /usr/local/bin/youtube-dl'" "" "youtube-dl homepage -> https://rg3.github.io/youtube-dl/" "" "2. Python" "Python should most likely be installed by default on your system." "If not install it via your distro's package manager." "" "Python homepage -> http://python.org" "" "3. FFmpeg" "Again ffmpeg should already be installed by default on most distros." "If not install it via your distro's package manager." "In some distros it is called avconv. ffprobe or avprobe are also required." "" "FFmpeg homepage -> https://www.ffmpeg.org/" "" "4. cURL" "curl is an open source command line tool and library for transferring data" "with URL syntax, supporting DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP," "IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMTP, SMTPS," "Telnet and TFTP." "You can easily install it using your package manager." "" "cURL homepage -> http://curl.haxx.se/" "" "5. Ping" "ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an" "ICMP ECHO_RESPONSE from a host or gateway." "ping is part of iputils package. Install iputils via your package manager." "" "iputils homepage -> http://www.skbuff.net/iputils/" "" "6. Downloads directory" "PMYTD is hard-wired to download video and audio to the Downloads directory" "under user's home directory." "Downloads directory should already be there by default but just in case make" "sure you have Downloads directory under your home folder." "" "Press 'q' to return to PMYTD MENU" "" | less
}

function AbouT(){
clear
printf "%s\n" "" "PMYTD is a simple script that can," "" "1. Download videos from youtube and other video sharing
websites." "2. Download and extract audio [mp3] from videos on youtube" "and other video sharing websites." "3. Download entire youtube playlists (video and audio)." "" "" "PMYTD is just a helper script for Ricardo Garcia's wonderful" "youtube-dl." "You can view the list of all supported video sharing websites here," "http://rg3.github.io/youtube-dl/supportedsites.html" "" "By the way PMYTD means Poor Man's YouTube Downloader. PMYTD is" "available under CC0 1.0 Universal licesense." "Got any question-suggestion? Please visit," "http://hakerdefo.blogspot.in/" "" "Press 'q' to return to PMYTD MENU" "" | less
}

function MenU(){
clear
echo ""
echo -e "PMYTD MENU"
echo ""
echo -e "01 About PMYTD"
echo -e "02 Dependencies of PMYTD"
echo -e "03 Download a video"
echo -e "04 Download & extract audio from video"
echo -e "05 Download entire youtube playlist"
echo -e "06 Download & extract audio from playlist"
echo -e "07 Check for updates"
echo -e "08 Help"
echo -e "09 Quit PMYTD"
echo ""
echo -e "Enter your choice: "
echo ""
read choice
case $choice in

01 | 1)
AbouT
;;

02 | 2)
DependencieS
;;

03 | 3)
FormaT
;;

04 | 4)
AudiO
;;

05 | 5)
VplS
;;

06 | 6)
AplS
;;

07 | 7)
UpdatE
;;

08 | 8)
HelP
;;

09 | 9)
ByE
;;

*)
clear
echo ""
echo -e "$choice is an invalid option!"
echo ""
sleep 4
;;

esac
}

while :
do

MenU

done



Cheers!!!


(09 August 2015) UPDATE ENDS:






(07 August 2015) UPDATE BEGINS:
Another update to 'Poor Man's Youtube Downloader'
So what's new?
'Check for updates' option is vastly improved. It now comapres the installed version of youtube-dl with available version and if an update is available gives user option to update youtube-dl.
The script will also check whether the user has the permission to update youtube-dl or not. If the user doesn't have the permission then the script will check whether the user has access to sudo or not. If the user have access to sudo then the script will use sudo to update youtube-dl else the script will use 'su'. This doesn't directly affect VSIDO but I wanted to make ''Poor Man's Youtube Downloader'' work on any distribution.
This update also make the script handle the errors related to connection and video availability in more efficient way.
View-Reviews-Comments are welcome!
Here is the updated script,


#!/bin/bash

function ByE (){
clear
echo ""
echo -e '\E[1;31;40m'"It's "'\E[1;32;40m'"funny "'\E[1;33;40m'" how"'\E[1;35;40m'" the"'\E[1;36;40m'" colors"'\E[1;31;40m'" of"'\E[1;32;40m'" the"'\E[1;33;40m'" real"'\E[1;35;40m'" world"'\E[1;36;40m'" only"'\E[1;31;40m'" seem"'\E[1;32;40m'" really"'\E[1;33;40m'" real"
echo -e '\E[1;36;40m'"when "'\E[1;31;40m'"you "'\E[1;32;40m'"viddy "'\E[1;33;40m'"them "'\E[1;35;40m'"on "'\E[1;36;40m'"the "'\E[1;31;40m'"screen."
echo ""
echo -e '\e[0m'"Alex, A Clockwork Orange"
echo ""
sleep 4
clear
exit 0
}

function HelP (){
clear
printf "%s\n" "" "Having problems running PMYTD?" "" "First make sure you have all the required dependencies installed." "You can read more about it in 'Dependencies of PMYTD' option" "in PMYTD MENU." "" "Having problems downloading videos?" "" "Youtube and other video sharing sites continually change their APIs." "So it is advised to keep youtube-dl updated to latest version." "You can check for youtube-dl updates via 'Check for updates' option" "in PMYTD MENU." "If there is a newer version available then please update youtube-dl." "" "For any other queries you can contact me at," "http://hakerdefo.blogspot.com" "" "Press 'q' to return to PMYTD MENU" "" | less
}

function UpdatE (){
clear
ytdllv=$(curl -sL -w "%{url_effective}\\n" "https://yt-dl.org/downloads/latest/" -o /dev/null | tail -c-12 | sed 's/[/]//g')
ytdlcv=$(youtube-dl --version)
if [ "$ytdllv" == "$ytdlcv" ]; then
echo ""
echo -e "Installed version of youtube-dl - $ytdlcv"
echo -e "Available version of youtube-dl - $ytdllv"
echo ""
echo -e "youtube-dl is up-to-date."
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
else
echo ""
echo -e "Installed version of youtube-dl - $ytdlcv"
echo -e "Available version of youtube-dl - $ytdllv"
echo ""
echo -e "youtube-dl update is available."
echo ""
echo -e "Would you like to update youtube-dl?"
echo ""
echo -e "01 Update youtube-dl"
echo -e "02 Return to PMYTD MENU"
echo ""
echo -e "Enter your choice: "
echo ""
read choice
case $choice in
1 | 01)
clear
ytdll=$(which youtube-dl)
if [ -w "$ytdll" ]; then
youtube-dl -U
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
else
resu=$(whoami)
resu_test=$(sudo -u "$resu" -n true >/dev/null 2>&1)
if [[ -z "$resu_test" ]]; then
echo ""
echo -e "Please enter root password"
echo ""
su -c 'youtube-dl -U'
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
else
echo ""
echo "Please enter password for user $resu"
echo ""
sudo youtube-dl -U
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
fi
fi
;;

2 | 02)
clear
MenU
;;

*)
clear
echo ""
echo -e "$choice is an invalid option!"
echo ""
sleep 4
UpdatE
;;
esac
fi
}

function DiE(){
clear
echo ""
echo -e "OOPS!!! Something Went Wrong!!!"
echo -e "Please make sure '$link' exists."
echo -e "Also make sure video is available."
echo ""
exit 1
}

function AplS(){
clear
printf "%s\n" "" "Enter the youtube playlist link: " ""
read link
clear
youtube-dl --continue --yes-playlist --ignore-errors --extract-audio --audio-format "mp3" --audio-quality 0 --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
}

function VplS(){
clear
printf "%s\n" "" "Enter the youtube playlist link: " ""
read link
clear
youtube-dl --continue --yes-playlist --ignore-errors --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
}

function AudiO(){
clear
printf "%s\n" "" "Enter the youtube video link: " ""
read link
clear
youtube-dl --continue --extract-audio --audio-format "mp3" --audio-quality 0 --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
}

function FormaT(){
clear
printf "%s\n" "" "Enter the youtube video link: " ""
read link
clear
youtube-dl --list-formats "$link" || DiE
printf "%s\n" "" "Enter your desired video format code from the above list:" ""
read list
clear
youtube-dl --continue --newline --format "$list" --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
echo ""
read -rsp $'Press any key to return to PMYTD MENU...\n' -n1 key
echo ""
clear
MenU
}

function DependencieS(){
clear
printf "%s\n" "" "PMYTD needs to have following applications installed in order to function," "" "1. youtube-dl" "A small command-line program to download videos from youtube and other" "video sharing sites. It is available in repos of some distros but it" "would most likely be severly outdated. Here is the right way to install it," "Open terminal and run following commands," "'sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O " "/usr/local/bin/youtube-dl'" "'sudo chmod a+x /usr/local/bin/youtube-dl'" "" "youtube-dl homepage -> https://rg3.github.io/youtube-dl/" "" "2. Python" "Python should most likely be installed by default on your system." "If not install it via your distro's package manager." "" "Python homepage -> http://python.org" "" "3. FFmpeg" "Again ffmpeg should already be installed by default on most distros." "If not install it via your distro's package manager." "In some distros it is called avconv. ffprobe or avprobe are also required." "" "FFmpeg homepage -> https://www.ffmpeg.org/" "" "4. Downloads directory" "PMYTD is hard-wired to download video and audio to the Downloads directory" "under user's home directory." "Downloads directory should already be there by default but just in case make" "sure you have Downloads directory under your home folder." "" "Press 'q' to return to PMYTD MENU" "" | less
}

function AbouT(){
clear
printf "%s\n" "" "PMYTD is a simple script that can," "" "1. Download videos from youtube and other video sharing
websites." "2. Download and extract audio [mp3] from videos on youtube" "and other video sharing websites." "3. Download entire youtube playlists (video and audio)." "" "" "PMYTD is just a helper script for Ricardo Garcia's wonderful" "youtube-dl." "You can view the list of all supported video sharing websites here," "http://rg3.github.io/youtube-dl/supportedsites.html" "" "By the way PMYTD means Poor Man's YouTube Downloader. PMYTD is" "available under CC0 1.0 Universal licesense." "Got any question-suggestion? Please visit," "http://hakerdefo.blogspot.in/" "" "Press 'q' to return to PMYTD MENU" "" | less
}

function MenU(){
clear
echo ""
echo -e "PMYTD MENU"
echo ""
echo -e "01 About PMYTD"
echo -e "02 Dependencies of PMYTD"
echo -e "03 Download a video"
echo -e "04 Download & extract audio from video"
echo -e "05 Download entire youtube playlist"
echo -e "06 Download & extract audio from playlist"
echo -e "07 Check for updates"
echo -e "08 Help"
echo -e "09 Quit PMYTD"
echo ""
echo -e "Enter your choice: "
echo ""
read choice
case $choice in

01 | 1)
AbouT
;;

02 | 2)
DependencieS
;;

03 | 3)
FormaT
;;

04 | 4)
AudiO
;;

05 | 5)
VplS
;;

06 | 6)
AplS
;;

07 | 7)
UpdatE
;;

08 | 8)
HelP
;;

09 | 9)
ByE
;;

*)
clear
echo ""
echo -e "$choice is an invalid option!"
echo ""
sleep 4
;;

esac
}

while :
do

MenU

done



Cheers!!!


(07 August 2015) UPDATE ENDS:







(08 July 2015) EDIT BEGINS:

I've improved 'Check for updates' option. And there are numerous other cosmetic changes. Here is the latest version of pmytd,


#!/bin/bash

function Bye (){
clear
printf "%s\n" "" "Thanks.. Bye Bye.." ""
sleep 2
clear
exit 0
}

function Update (){
ytdllv=$(curl -sL -w "%{url_effective}\\n" "https://yt-dl.org/downloads/latest/" -o /dev/null | tail -c-12 | sed 's/[/]//g')
ytdlcv=$(youtube-dl --version)
printf "%s\n" "" "Installed version of youtube-dl is - $ytdlcv" "" "Latest available version of youtube-dl is - $ytdllv" "" "Press 'q' to return to PMYTD MENU" "" | less
}

function Apls(){
clear
printf "%s\n" "" "Enter the youtube playlist link: " ""
read link
clear
youtube-dl --continue --yes-playlist --ignore-errors --extract-audio --audio-format "mp3" --audio-quality 0 --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
exit 0
}

function Vpls(){
clear
printf "%s\n" "" "Enter the youtube playlist link: " ""
read link
clear
youtube-dl --continue --yes-playlist --ignore-errors --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
exit 0
}

function Audio(){
clear
printf "%s\n" "" "Enter the youtube video link: " ""
read link
clear
youtube-dl --continue --extract-audio --audio-format "mp3" --audio-quality 0 --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
exit 0
}

function Format(){
clear
printf "%s\n" "" "Enter the youtube video link: " ""
read link
clear
youtube-dl --list-formats "$link"
printf "%s\n" "" "Enter your desired video format code from the above list:" ""
read list
clear
youtube-dl --continue --format "$list" --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
exit 0
}

function Dependencies(){
printf "%s\n" "PMYTD needs to have following applications installed in order to function," "" "1. youtube-dl" "A small command-line program to download videos from youtube and other" "video sharing sites. It is available in repos of some distros but it" "would most likely be severly outdated. Here is the right way to install it," "Open terminal and run following commands," "'sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O " "/usr/local/bin/youtube-dl'" "'sudo chmod a+x /usr/local/bin/youtube-dl'" "" "youtube-dl homepage -> https://rg3.github.io/youtube-dl/" "" "2. Python" "Python should most likely be installed by default on your system." "If not install it via your distro's package manager." "" "Python homepage -> http://python.org" "" "3. FFmpeg" "Again ffmpeg should already be installed by default on most distros." "If not install it via your distro's package manager." "In some distros it is called avconv. ffprobe or avprobe are also required." "" "FFmpeg homepage -> https://www.ffmpeg.org/" "" "4. Downloads directory" "PMYTD is hard-wired to download video and audio to the Downloads directory" "under user's home directory." "Downloads directory should already be there by default but just in case make" "sure you have Downloads directory under your home folder." "" "Press 'q' to return to PMYTD MENU" "" | less
}

function About(){
printf "%s\n" "PMYTD is a simple script that can," "" "1. Download videos from youtube and other video sharing
websites." "2. Download and extract audio [mp3] from videos on youtube" "and other video sharing websites." "3. Download entire youtube playlists (video and audio)." "" "" "PMYTD is just a helper script for Ricardo Garcia's wonderful" "youtube-dl." "You can view the list of all supported video sharing websites here," "http://rg3.github.io/youtube-dl/supportedsites.html" "" "Youtube and other video sharing sites continually change their APIs." "So it is advised to keep youtube-dl updated to latest version." "You can check for youtube-dl updates via 'Check for updates' option" "in PMYTD MENU." "If there is a newer version available then you can update youtube-dl" "by running following command in terminal," "'sudo youtube-dl -U'" "" "By the way PMYTD means Poor Man's YouTube Downloader. PMYTD is" "available under CC0 1.0 Universal licesense." "Got any question-suggestion? Please visit," "http://hakerdefo.blogspot.in/" "" "Press 'q' to return to PMYTD MENU" "" | less
}

while :
do
clear
cat << !
PMYTD MENU

1. About PMYTD
2. Dependencies of PMYTD
3. Download a video
4. Download & extract audio from video
5. Download entire youtube playlist
6. Download & extract audio from playlist
7. Check for updates
8. Quit PMYTD

!
echo -n "Enter your choice: "
read choice
case $choice in
1) About ;;
2) Dependencies ;;
3) Format ;;
4) Audio ;;
5) Vpls ;;
6) Apls ;;
7) Update ;;
8) Bye ;;
*) clear; printf "%s\n" "\"$choice\" is an invalid option!"; sleep 3;;
esac
done



(08 July 2015) EDIT ENDS:



It's been a while since I visited the forum! Reason? I'm without any proper Internet connection lately! Anyways I came across this topic by VastOne,
CHALLENGE Muz/gyts script fix/alternatives Yad script
Now I'm not a Bash scripting guru so you are free to improve-modify this script. Just save this script somewhere in your path with the name 'pmytd' and 'chmod 755' it. Run 'pmytd' from your terminal whenever you feel like scraping youtube  :)


#!/bin/bash

function Bye (){
printf "%s\n" "" "Thanks.. Bye Bye.." ""
sleep 3
clear
exit 0
}

function Update (){
youtube-dl --simulate -U | less
}

function Apls(){
printf "%s\n" "" "Enter the youtube playlist link" ""
read link
youtube-dl --continue --yes-playlist --ignore-errors --extract-audio --audio-format "mp3" --audio-quality 0 --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
exit 0
}

function Vpls(){
printf "%s\n" "" "Enter the youtube playlist link" ""
read link
youtube-dl --continue --yes-playlist --ignore-errors --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
exit 0
}

function Audio(){
printf "%s\n" "" "Enter the youtube video link" ""
read link
youtube-dl --continue --extract-audio --audio-format "mp3" --audio-quality 0 --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
exit 0
}

function Format(){
printf "%s\n" "" "Enter the youtube video link" ""
read link
youtube-dl --list-formats "$link"
printf "%s\n" "" "Enter your desired video format code from the above list" ""
read list
youtube-dl --continue --format "$list" --output "/home/$USER/Downloads/%(title)s.%(ext)s" "$link"
exit 0
}

function Dependencies(){
printf "%s\n" "PMYTD needs to have following applications installed in order to function," "" "1. youtube-dl" "A small command-line program to download videos from youtube and other video sharing sites. It is available in repos of some distros but chances are that it is severly outdated. Here is the right way to install it," "Open terminal and run following commands," "'sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl'" "'sudo chmod a+x /usr/local/bin/youtube-dl'" "" "Youtube and other video sharing sites continually change their APIs." "So it is advised to keep youtube-dl updated to latest version." "You can check for youtube-dl updates via 'Check for update' option in PMYTD MENU." "If there is a newer version available then you can update youtube-dl by running following command in terminal," "'sudo youtube-dl -U'" "http://rg3.github.io/youtube-dl/" "" "2. Python" "Python should most likely be installed by default on your system. If not install it via your distro's package manager." "http://python.org" "" "3. FFmpeg" "Again ffmpeg should already be installed by default on most distros. If not install it via your distro's package manager." "In some distros it is called avconv. ffprobe or avprobe are also required." "https://www.ffmpeg.org/" "" "4. Downloads directory" "PMYTD is hard-wired to download video and audio to the Downloads directory under user's home directory." "Downloads directory should already be there by default but just in case make sure you have Downloads directory under your home folder." "" "Press 'q' to return to PMYTD MENU" | less
}

function About(){
printf "%s\n" "PMYTD is a simple script that can," "" "1. Download videos from youtube and other video sharing
websites." "" "2. Download and extract audio [mp3] from videos on youtube and other video sharing websites." "" "3. Download entire youtube playlists (video and audio)." "" "PMYTD is just a helper script for Ricardo Garcia's wonderful youtube-dl." "You can view the list of all supported websites here," "http://rg3.github.io/youtube-dl/supportedsites.html" "" "By the way PMYTD means Poor Man's YouTube Downloader. PMYTD is available under WTFPL licesense." "Got any question-suggestion? Please visit," "http://hakerdefo.blogspot.in/" "" "Press 'q' to return to PMYTD MENU" | less
}

while :
do
clear
cat << !
PMYTD MENU

1. About PMYTD
2. Dependencies of PMYTD
3. Download a video
4. Download & extract audio from video
5. Download entire youtube playlist
6. Download & extract audio from playlist
7. Check for update
8. Quit PMYTD

!
echo -n "Enter your choice "
read choice
case $choice in
1) About ;;
2) Dependencies ;;
3) Format ;;
4) Audio ;;
5) Vpls ;;
6) Apls ;;
7) Update ;;
8) Bye ;;
*) echo "\"$choice\" is invalid"; sleep 3;;
esac
done



Cheers!!!
You Can't Always Git What You Want

VastOne

Welcome back hakerdefo!

Nice one man...  This code is just what I have been looking for

I did not have to install anything at all additional to get this to work but I did get these errors and I do not have ffprobe avprobe or avconv installed.  Even though it worked it did spit this out


WARNING: Your copy of avconv is outdated, update avconv to version 10-0 or newer if you encounter any errors.
[avconv] Destination: /home/vastone/Downloads/Julie Roberts - Wake Up Older.mp3
WARNING: Your copy of avconv is outdated, update avconv to version 10-0 or newer if you encounter any errors.
Deleting original file /home/vastone/Downloads/Julie Roberts - Wake Up Older.m4a (pass -k to keep)


What was written was also a bitrate of 237 which is OK but most everything I do is at a 320 bitrate.  I will look at the bash to see to improve that

This will be the replacement for gyts since it is no longer functioning,  I cannot tell you how much I appreciate this code and that it will be a part of VSIDO

Thank you!
VSIDO      VSIDO Change Blog    

    I dev VSIDO

VastOne

I did find that the youtube-dl settings are already at their best levels in the script
VSIDO      VSIDO Change Blog    

    I dev VSIDO

hakerdefo

Glad you liked it VastOne! The error you mentioned in your first reply was not an error but a warning! And the reason for that is youtube-dl's converter part is written keeping in mind avconv 10 or newer. If it finds the copy of your avconv version is older than 10, it spits out a warning. Now here comes the interesting part. avconv which is part of libav-tools package is at version 11.3 in vsido, which is at par with latest available upstream version. So why the error? Because Debian libav packages use different version numbering. Latest upstream libav-tools 11.3-2 is rechristned 6:11.3-2 in Debian. This fools youtube-dl and hence it warns you to update avconv.
Now regarding the audio quality, the script in most cases should get the best possible quality. Here the source audio quality plays a big part. No point in forcefully converting audio at 320 kbps if the source is not good enough, you won't get better sound and it will occupy extra space.
Cheers!!!
You Can't Always Git What You Want

jedi

Brilliant work hakerdefo!  Nice to have this tool back...   :)
Forum Netiquette

"No matter how smart you are you can never convince someone stupid that they are stupid."  Anonymous

hakerdefo

Quote from: jedi on April 27, 2015, 02:14:38 PM
Brilliant work hakerdefo!  Nice to have this tool back...   :)
Cheers jedi!!!
You Can't Always Git What You Want

hakerdefo

After much much hesitation I've started using GitHub and decided to publish 'Poor Man's Youtube Downloader' as my first project there! But remember you heard it first on VSIDO  8)

pmytd

Cheers!!!
You Can't Always Git What You Want

PackRat

Your git page and app are working as advertised. Screenshot or it never happened -

I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

hakerdefo

Thanks PackRat! By the way what is the WM in your screenshot? Looks cool!
You Can't Always Git What You Want

PackRat

No problem.

The window manager is bspwm. A tiling wm that is EWMH compliant so you can use panels. Set conky to window_type dock or panel.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

hakerdefo

bspwm seems interesting. But it is not available in Debian repos, is it? How hard is it to compile?
Cheers!!!
You Can't Always Git What You Want

PackRat

#11
Pretty straight forward to compile.

No deb packages that I'm aware of. Rooster over at #! use to maintain a repo for it, but it's gone now.

Need to get a few dependencies. Use the key binding app the author of bspwm developed.

From what I've gleaned from the Arch thread, there can be an issue with bspwm starting and you have to edit ~/.profile and add a socket or a fifo. That was a while ago when I was reading that though, I think the wm has progressed past that.

All the configuration options are in the Readme file.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

hakerdefo

Thanks PackRat! Your post gave a very good intro to bspwm!
Cheers!!!
You Can't Always Git What You Want

VastOne

Using pmytd option 4 and going after this url to extract Audio from the Video :https://www.youtube.com/watch?v=s6198qSm0Y0

Failure with the script now, here is the error codes

[youtube] s6198qSm0Y0: Downloading webpage
[youtube] s6198qSm0Y0: Downloading video info webpage
[youtube] s6198qSm0Y0: Extracting video information
ERROR: Signature extraction failed: Traceback (most recent call last):
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/youtube.py", line 700, in _decrypt_signature
    video_id, player_url, s
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/youtube.py", line 592, in _extract_signature_function
    raise ExtractorError('Cannot identify player %r' % player_url)
ExtractorError: Cannot identify player u'https://s.ytimg.com/yts/jsbin/player-en_US-vfl0w9xAB/base.js'; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type  youtube-dl -U  to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
(caused by ExtractorError(u"Cannot identify player u'https://s.ytimg.com/yts/jsbin/player-en_US-vfl0w9xAB/base.js'; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type  youtube-dl -U  to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.",)); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type  youtube-dl -U  to update. Be sure to call youtube-dl with the --verbose flag and include its complete output
VSIDO      VSIDO Change Blog    

    I dev VSIDO

hakerdefo

Hi there VastOne,
Please update youtube-dl via 'Check for updates' option in pmytd menu and try to download that video again.
Cheers!!!
You Can't Always Git What You Want