6
6
# ./ydownl.sh URL
7
7
#
8
8
9
+ # ------------------------------------------------------------------------------
10
+ # IDEAS
11
+ # ------------------------------------------------------------------------------
12
+ # - setting for target dir:
13
+ # example: CONFIG_TARGET_DIR="~/Downloads"
14
+ # - youtube-dl parameter:
15
+ # - youtube-dl: ffmpeg or avconv?
16
+ # --prefer-avconv (default)
17
+ # --prefer-ffmpeg
18
+ #
19
+
9
20
# ------------------------------------------------------------------------------
10
21
# DEBUG
11
22
# ------------------------------------------------------------------------------
17
28
# DEFINE CONSTANTS - DON'T TOUCH
18
29
# ------------------------------------------------------------------------------
19
30
SCRIPT_NAME=" ydownl.sh"
20
- SCRIPT_VERSION=" 1.2 .0"
31
+ SCRIPT_VERSION=" 1.3 .0"
21
32
SCRIPT_LATEST=" https://github.com/yafp/ydownl.sh/releases/latest"
22
33
SCRIPT_DEMO_URL=" https://www.youtube.com/watch?v=Y52M28WQu2s"
34
+ SCRIPT_USERAGENT=" ydownl.sh"
23
35
24
36
25
37
@@ -56,6 +68,14 @@ CONFIG_ZENITY_HEIGHT=150 # default 150
56
68
# ------------------------------------------------------------------------------
57
69
# FUNCTIONS
58
70
# ------------------------------------------------------------------------------
71
+
72
+ # ######################################
73
+ # Defines some text color & formating options
74
+ # Arguments:
75
+ # none
76
+ # Outputs:
77
+ # none
78
+ # ######################################
59
79
function initColors() {
60
80
# format
61
81
bold=$( tput bold)
@@ -77,46 +97,76 @@ function initColors() {
77
97
white=$( tput setaf 7)
78
98
}
79
99
100
+ # ######################################
101
+ # Clears the terminal / screen
102
+ # Arguments:
103
+ # none
104
+ # Outputs:
105
+ # none
106
+ # ######################################
80
107
function reset() {
81
108
tput reset
82
109
}
83
110
111
+ # ######################################
112
+ # Shows a simple header
113
+ # Arguments:
114
+ # none
115
+ # Outputs:
116
+ # none
117
+ # ######################################
84
118
function showHeader() {
85
119
printf " ${bold}${lime_yellow} %s${normal} - ${bold} %s ${normal} \n" " $SCRIPT_NAME " " $SCRIPT_VERSION "
86
120
printf " ${bold} ----------------------------------------------------------${normal} \n"
87
121
}
88
122
89
- function showNotification() {
90
- if ! hash notify-send 2> /dev/null
91
- then
92
- printf " Notifications using notify-send is not supported - skipping ...\n"
93
- else
94
- # notify-send -u low -t 0 "$SCRIPT_NAME" "$1"
95
- zenity --info --text=" $1 " --title=" $SCRIPT_NAME " --width=" $CONFIG_ZENITY_WIDTH " --height=" $CONFIG_ZENITY_HEIGHT " --timeout=" $CONFIG_ZENITY_TIMEOUT "
96
- fi
123
+ # ######################################
124
+ # Displays a text notification using zenity
125
+ # Arguments:
126
+ # notification text
127
+ # Outputs:
128
+ # none
129
+ # ######################################
130
+ function showGuiNotification() {
131
+ zenity \
132
+ --info \
133
+ --text=" $1 " \
134
+ --title=" $SCRIPT_NAME " \
135
+ --width=" $CONFIG_ZENITY_WIDTH " \
136
+ --height=" $CONFIG_ZENITY_HEIGHT " \
137
+ --timeout=" $CONFIG_ZENITY_TIMEOUT "
97
138
}
98
139
140
+ # ######################################
141
+ # Checks if a file/executable exists.
142
+ # Arguments:
143
+ # Name of executable
144
+ # Outputs:
145
+ # OK if it exists
146
+ # Error if it doesnt exists
147
+ # ######################################
99
148
function checkIfExists() {
100
149
if ! hash " $1 " 2> /dev/null
101
150
then
102
- # does not exist
103
- printf " ${red} [ FAIL ]${normal} $1 not found\n"
151
+ printf " ${red} [ FAIL ]${normal} $1 not found on this system. Please install this dependency.\n" # does not exist
104
152
exit 1
105
153
else
106
- # exists
107
- printf " ${green} [ OK ]${normal} $1 detected\n"
154
+ printf " ${green} [ OK ]${normal} $1 detected\n" # exists
108
155
fi
109
156
}
110
157
158
+ # ######################################
159
+ # Checks if a newer version of the script is available
160
+ # Arguments:
161
+ # none
162
+ # Outputs:
163
+ # OK if no update available
164
+ # INFO if update is available
165
+ # ######################################
111
166
function checkVersion() {
112
- SCRIPT_LATEST_VERSION=` curl --silent " https://api.github.com/repos/yafp/ydownl.sh/releases/latest" | # Get latest release from GitHub api
167
+ SCRIPT_LATEST_VERSION=$( curl --silent " https://api.github.com/repos/yafp/ydownl.sh/releases/latest" | # Get latest release from GitHub api
113
168
grep ' "tag_name":' | # Get tag line
114
- sed -E 's/.*"([^"]+)".*/\1/' ` # Pluck JSON value
115
-
116
-
117
- # printf "Your version: $SCRIPT_VERSION\n"
118
- # printf "Latest version: $SCRIPT_LATEST_VERSION\n"
119
-
169
+ sed -E ' s/.*"([^"]+)".*/\1/' ) # Pluck JSON value
120
170
121
171
if [ " $SCRIPT_LATEST_VERSION " == " $SCRIPT_VERSION " ]
122
172
then
@@ -126,26 +176,59 @@ function checkVersion() {
126
176
fi
127
177
}
128
178
179
+ # ######################################
180
+ # Triggers the download using youtube-dl
181
+ # Arguments:
182
+ # URL
183
+ # Outputs:
184
+ # none
185
+ # ######################################
186
+ function startDownload () {
187
+ # start downloading (alt: youtube-dlc)
188
+ youtube-dl \
189
+ --format bestaudio \
190
+ --extract-audio \
191
+ --restrict-filenames \
192
+ --write-description \
193
+ --newline \
194
+ --console-title \
195
+ --audio-format " $CONFIG_YTDL_AUDIOFORMAT " \
196
+ --audio-quality $CONFIG_YTDL_AUDIOQUALITY \
197
+ --output " %(playlist_index)s%(playlist)s%(title)s.%(ext)s" \
198
+ --output-na-placeholder " " \
199
+ --write-info-json \
200
+ --write-annotations \
201
+ --write-thumbnail \
202
+ --embed-thumbnail \
203
+ --add-metadata \
204
+ --user-agent " $SCRIPT_USERAGENT " \
205
+ " $1 "
206
+ }
207
+
129
208
130
209
# ------------------------------------------------------------------------------
131
210
# SCRIPT
132
211
# ------------------------------------------------------------------------------
133
212
reset # clear the screen
134
213
initColors # initialize the color and font formating variables
135
214
showHeader # show the script header
136
- checkIfExists " youtube-dl"
137
- checkIfExists " ffmpeg"
138
- checkIfExists " zenity"
139
- checkIfExists " curl"
140
- checkIfExists " sed"
141
- checkVersion
142
-
143
- # Check if a parameter was supplied - if not stop execution
215
+
216
+ # check all dependencies / requirements
217
+ checkIfExists " youtube-dl" # main-component
218
+ checkIfExists " ffmpeg" # youtube-dl dependency
219
+ checkIfExists " zenity" # for dialogs
220
+ checkIfExists " curl" # for update-check
221
+ checkIfExists " sed" # for update-check
222
+
223
+ # check for available updates of this script
224
+ checkVersion
225
+
226
+ # Check if a parameter/url was supplied
144
227
if [ -z " $1 " ]
145
228
then
146
229
printf " ${yellow} [ WARN ]${normal} no URL detected. Starting input dialog\n"
147
230
148
- # start input dialog to handle the missing url
231
+ # start zenity input dialog to ask for the missing url
149
232
URL=$( zenity --entry --width=" $CONFIG_ZENITY_WIDTH " --height=" $CONFIG_ZENITY_HEIGHT " --title=" $SCRIPT_NAME " --text=" Please insert an URL:" )
150
233
if [ -z " $URL " ]
151
234
then
@@ -162,10 +245,10 @@ if curl --output /dev/null --silent --head --fail "$URL"; then
162
245
printf " ${green} [ OK ]${normal} URL is valid\n"
163
246
printf " \nStart processing the following url:\n\t${bold} %s${normal} \n\n" " $URL "
164
247
165
- # start downloading (alt: youtube-dlc)
166
- youtube-dl -f bestaudio --extract-audio --restrict-filenames --write-description --newline --console-title --audio-format " $CONFIG_YTDL_AUDIOFORMAT " --audio-quality $CONFIG_YTDL_AUDIOQUALITY -o " %(playlist_index)s-%(playlist)s---%(title)s.%(ext)s " $URL
248
+ startDownload " $URL "
249
+
167
250
printf " \n${green} [ OK ]${normal} Finished processing the URL: $URL \n\n"
168
- showNotification " Finished downloading\n\t<a href='$URL '>$URL </a>"
251
+ showGuiNotification " Finished downloading\n\t<a href='$URL '>$URL </a>"
169
252
else
170
253
printf " ${red} [ FAIL ]${normal} URL is not reachable. Aborting..\n\n"
171
254
exit 1
0 commit comments