-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDownloadYouTubeVideo.sh
executable file
·87 lines (77 loc) · 3.07 KB
/
DownloadYouTubeVideo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/zsh
#================================================================================
# AUTHOR
# Clint Box
# https://www.youtube.com/bearcatjamboree
#
# FUNCTION
# Download a YouTube video in highest quality
#
# DETAILS
# This script will invoke yt-dlp with parameters required to take an input
# video (or video ID) and download it to a specified folder in the highest
# quality available on YouTube
#
# USAGE
# ${SCRIPT_NAME} "<url>" "<output folder>"
#================================================================================
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
echo ${machine}
url="$1"
output_folder="$2"
##############################################################################
# Prompt for url
###############################################################################
if [[ "$url" == "" ]]; then
if [[ "$machine" == "Mac" ]]; then
url=$(osascript -e 'set T to text returned of (display dialog "Enter YouTube video url:" buttons {"Cancel", "OK"} default button "OK" default answer "")')
elif [[ "$machine" == "Linux" ]]; then
url=$(dialog --title "Enter YouTube video url:" --inputbox "url:" 8 60)
elif [[ "$machine" == "Cygwin" ]]; then
url=$(dialog --title "Enter YouTube video url:" --inputbox "url:" 8 60)
else
echo "Usage: $0 language [video URL or ID] output_folder"
exit 1
fi
fi
if [[ "$url" == "" ]]; then
echo "Usage: $0 output_folder [video URL]"
exit 1
fi
url="${url##*v=}"
url="${url##*/}"
video_id="${url%&*}"
video_id=$(echo $video_id | sed 's/^-/\\-/g')
echo "video_id = $video_id"
##############################################################################
# Check for file was passed. Show open file dialog if no argument and on Mac
###############################################################################
if ! [ -d "$output_folder" ]; then
if [[ "$machine" == "Mac" ]]; then
output_folder=$(osascript -e 'tell application (path to frontmost application as text)
set output_folder to choose folder with prompt "Please choose an _output folder"
POSIX path of output_folder
end')
elif [[ "$machine" == "Linux" ]]; then
output_folder=$(dialog --title "Choose a folder" --stdout --title "Please select output folder:" --fselect ~/ 14 48)
elif [[ "$machine" == "Cygwin" ]]; then
output_folder=$(dialog --title "Choose a folder" --stdout --title "Please select output folder:" --fselect ~/ 14 48)
else
echo "Usage: $0 language [video URL or ID] output_folder"
exit 1
fi
fi
echo "$output_folder"
if ! [ -d "$output_folder" ]; then
echo "Usage: $0 output_folder [video URL or ID] "
exit 1
fi
#yt-dlp "ytsearch:$url" -f "bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b" -o "$output_folder%(title)s.%(ext)s"
yt-dlp "$url" -f "bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b" -o "$output_folder%(title)s.%(ext)s"