Skip to content

Commit d00bfd2

Browse files
committed
202100610 - This is 1.5.0 - Fixing #3 and #4
1 parent 5eea021 commit d00bfd2

File tree

3 files changed

+133
-57
lines changed

3 files changed

+133
-57
lines changed

docs/CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# changelog
22

3+
## Version 1.5.0 (20210610)
4+
### Added
5+
* Added silent update check on script start (info onlx if update available)
6+
* Adding ascii-art to
7+
* youtube-dl update check
8+
* download start
9+
10+
### Changes
11+
* Improved version check to handle all 3 cases (up-to-date VS outdated VS dev version)
12+
* Download UI: changed button label
13+
* dialogs all show the project url using the --hline parameter
14+
* dialogs are now using the same width
15+
* Improve url input validation (now checks if it is a link & if so if its reachable)
16+
17+
### Removed
18+
* Removed zenity dependency
19+
20+
21+
322
## Version 1.4.1 (20210530)
423
### Changes
524
* Simplify dialogs
@@ -9,6 +28,7 @@
928
* Fix ydownl.sh update script (if version is up to date)
1029

1130

31+
1232
## Version 1.4.0 (20210527)
1333
* Switched to ncruses like mode based on 'dialog'
1434
* Added variable for download target folder
@@ -17,6 +37,7 @@
1737
* Youtube-DL: Adding --no-mtime
1838

1939

40+
2041
## Version 1.3.0 (20210402)
2142
* Youtube-DL: Adding --add-metadata
2243
* Youtube-DL: Adding --write-info-json

docs/ydown_preview_latest_.gif

624 KB
Loading

ydownl.sh

Lines changed: 112 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030
# DEFINE CONSTANTS - DON'T TOUCH
3131
# ------------------------------------------------------------------------------
3232
SCRIPT_NAME="ydownl.sh"
33-
SCRIPT_VERSION="1.4.1"
33+
SCRIPT_VERSION="1.5.0"
3434
SCRIPT_NAME_VERSION="$SCRIPT_NAME""-v""$SCRIPT_VERSION"
35+
SCRIPT_GITHUB_URL="https://github.com/yafp/ydownl.sh"
3536
SCRIPT_LATEST="https://github.com/yafp/ydownl.sh/releases/latest"
36-
SCRIPT_DEMO_URL="https://www.youtube.com/watch?v=Y52M28WQu2s"
3737
SCRIPT_USERAGENT="ydownl.sh"
38+
#
39+
#SCRIPT_DEMO_URL="https://www.youtube.com/watch?v=Y52M28WQu2s"
3840

3941
# ------------------------------------------------------------------------------
4042
# USER CONFIG
@@ -59,15 +61,7 @@ CONFIG_YTDL_AUDIOFORMAT="mp3" # default: "mp3"
5961
# (worse) for VBR or a specific bitrate like 128K (default 5)
6062
CONFIG_YTDL_AUDIOQUALITY=0
6163

62-
# CONFIG_ZENITY_TIMEOUT: Defines the timeout for the zenity notification dialog after download finished
63-
CONFIG_ZENITY_TIMEOUT=15 # default 15
64-
65-
# CONFIG_ZENITY_DIALOG_WIDTH: define dialog width
66-
CONFIG_ZENITY_WIDTH=500 # default 500
67-
68-
# CONFIG_ZENITY_DIALOG_HEIGHT: define dialog height
69-
CONFIG_ZENITY_HEIGHT=150 # default 150
70-
64+
CONFIG_INFODIALOG_TIMEOUT=5
7165

7266
# ------------------------------------------------------------------------------
7367
# FUNCTIONS
@@ -82,7 +76,7 @@ CONFIG_ZENITY_HEIGHT=150 # default 150
8276
#######################################
8377
function initColors() {
8478
# format
85-
bold=$(tput bold)
79+
#bold=$(tput bold)
8680
normal=$(tput sgr0)
8781
##blink=$(tput blink)
8882
##reverse=$(tput smso)
@@ -91,10 +85,10 @@ function initColors() {
9185
# colors
9286
##black=$(tput setaf 0)
9387
red=$(tput setaf 1)
94-
green=$(tput setaf 2)
95-
yellow=$(tput setaf 3)
96-
lime_yellow=$(tput setaf 190)
97-
powder_blue=$(tput setaf 153)
88+
#green=$(tput setaf 2)
89+
#yellow=$(tput setaf 3)
90+
#lime_yellow=$(tput setaf 190)
91+
#powder_blue=$(tput setaf 153)
9892
##blue=$(tput setaf 4)
9993
##magenta=$(tput setaf 5)
10094
##cyan=$(tput setaf 6)
@@ -136,13 +130,25 @@ function checkIfExecutableExists() {
136130
# none
137131
#######################################
138132
function checkDependencies () {
139-
checkIfExecutableExists "dialog" # for dialogs
140-
checkIfExecutableExists "zenity" # for dialogs
133+
checkIfExecutableExists "dialog" # for terminal UI & dialogs
141134
checkIfExecutableExists "curl" # for update-check
142135
checkIfExecutableExists "sed" # for update-check
143136
checkIfExecutableExists "youtube-dl" # main-component
144137
}
145138

139+
140+
#######################################
141+
# Compares 2 strings - usrf gpt update check
142+
# Arguments:
143+
# none
144+
# Outputs:
145+
# none
146+
#######################################
147+
function version {
148+
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
149+
}
150+
151+
146152
#######################################
147153
# Checks if a newer version of the script is available
148154
# Arguments:
@@ -157,35 +163,35 @@ function checkScriptVersion() {
157163
grep '"tag_name":' | # Get tag line
158164
sed -E 's/.*"([^"]+)".*/\1/' ) # Pluck JSON value
159165

160-
if [ "$SCRIPT_LATEST_VERSION" != "$SCRIPT_VERSION" ]
161-
then
166+
167+
# local version == latest public release
168+
if [ $(version $SCRIPT_LATEST_VERSION) -eq $(version "$SCRIPT_VERSION") ]; then
169+
if [ -z "$1" ]; then # output only in default mode - if $1 is not set
170+
dialog \
171+
--hline "$SCRIPT_GITHUB_URL" \
172+
--title "Update check: Up-to-date" \
173+
--backtitle "ydownl.sh" \
174+
--msgbox "You are running the latest version of $SCRIPT_NAME (as in: $SCRIPT_LATEST_VERSION)" 10 80
175+
fi
176+
fi
177+
178+
# local version < latest public release -> inform about update
179+
if [ $(version $SCRIPT_LATEST_VERSION) -gt $(version "$SCRIPT_VERSION") ]; then
162180
dialog \
181+
--hline "$SCRIPT_GITHUB_URL" \
182+
--title "Update check: Outdated" \
163183
--backtitle "ydownl.sh" \
164-
--msgbox "Your version of $SCRIPT_NAME is outdated.\n\nLatest official version is available under:\n$SCRIPT_LATEST" 10 80
165-
else
166-
dialog \
167-
--backtitle "ydownl.sh" \
168-
--msgbox "Your version of $SCRIPT_NAME is up to date" 10 80
184+
--msgbox "You are running the outdated version $SCRIPT_VERSION of $SCRIPT_NAME.\n\nLatest official version is $SCRIPT_LATEST_VERSION and is available under:\n$SCRIPT_LATEST" 10 80
169185
fi
170186

171-
showMainMenu
172-
}
187+
# local version > latest public release
188+
if [ $(version $SCRIPT_LATEST_VERSION) -lt $(version "$SCRIPT_VERSION") ]; then
189+
if [ -z "$1" ]; then # output only in default mode - if $1 is not set
190+
showInfoDialog "Seems like you are running a development version"
191+
fi
192+
fi
173193

174-
#######################################
175-
# Displays a text notification using zenity
176-
# Arguments:
177-
# notification text
178-
# Outputs:
179-
# none
180-
#######################################
181-
function showGuiNotification() {
182-
zenity \
183-
--info \
184-
--text="$1" \
185-
--title="$SCRIPT_NAME" \
186-
--width="$CONFIG_ZENITY_WIDTH" \
187-
--height="$CONFIG_ZENITY_HEIGHT" \
188-
--timeout="$CONFIG_ZENITY_TIMEOUT"
194+
showMainMenu
189195
}
190196

191197
#######################################
@@ -196,6 +202,9 @@ function showGuiNotification() {
196202
# none
197203
#######################################
198204
function startDownload () {
205+
206+
printAsciiArt
207+
199208
# start the main task
200209
youtube-dl \
201210
--format bestaudio \
@@ -216,10 +225,11 @@ function startDownload () {
216225
--user-agent "$SCRIPT_USERAGENT" \
217226
"$1"
218227

219-
showGuiNotification "Finished downloading\n\t<a href='$1'>$1</a>"
228+
showInfoDialog "Finished downloading $1"
220229
showMainMenu
221230
}
222231

232+
223233
#######################################
224234
# Shows the dialog-based main menu
225235
# Arguments:
@@ -229,12 +239,13 @@ function startDownload () {
229239
#######################################
230240
function showMainMenu () {
231241
USERSELECTION=$(dialog \
242+
--hline "$SCRIPT_GITHUB_URL" \
232243
--backtitle "ydownl.sh" \
233244
--title "Main menu" \
234245
--ok-label "Choose" \
235246
--no-cancel \
236-
--menu "Please choose:" 15 55 5 \
237-
1 "New download" \
247+
--menu "Please choose:" 12 80 5 \
248+
1 "New Audio Download" \
238249
2 "Check for youtube-dl updates" \
239250
3 "Check for ydownl.sh updates" \
240251
9 "Exit" \
@@ -260,7 +271,6 @@ function showMainMenu () {
260271

261272
*)
262273
reset
263-
#showErrorDialog "Unexpected error"
264274
;;
265275
esac
266276
}
@@ -274,12 +284,13 @@ function showMainMenu () {
274284
#######################################
275285
function showUrlInputDialog () {
276286
USERURL=$(dialog \
277-
--title "New Download" \
287+
--hline "$SCRIPT_GITHUB_URL" \
288+
--title "New Audio Download" \
278289
--backtitle $SCRIPT_NAME_VERSION \
279-
--ok-label "OK" \
290+
--ok-label "Start" \
280291
--cancel-label "Exit" \
281292
--no-cancel \
282-
--inputbox "Please paste the URL here" 10 90 \
293+
--inputbox "Please paste the URL here" 10 80 \
283294
--output-fd 1)
284295

285296
checkUserInput $USERURL
@@ -294,17 +305,26 @@ function showUrlInputDialog () {
294305
#######################################
295306
function checkUserInput () {
296307
if [[ $1 ]]; then
297-
reset
298308

299-
# check if the url is valid
300-
if curl --output /dev/null --silent --head --fail "$1"; then
301-
startDownload $1
309+
# Check if input looks like a link
310+
regex='(https?)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
311+
if [[ $1 =~ $regex ]]
312+
then
313+
#printf "Link valid"
314+
# check if it is reachable
315+
if curl --output /dev/null --silent --head --fail "$1"; then
316+
startDownload $1
317+
else
318+
showErrorDialog "The link $1 is not reachable"
319+
showMainMenu
320+
fi
321+
302322
else
303-
showErrorDialog "This is not a valid and/or reachable url"
323+
#printf "Link not valid"
324+
showErrorDialog "'$1' is not a valid link"
304325
showMainMenu
305326
fi
306327
else
307-
#showErrorDialog "Aborting..." # input was zero
308328
showMainMenu
309329
fi
310330
}
@@ -318,10 +338,29 @@ function checkUserInput () {
318338
#######################################
319339
function showErrorDialog () {
320340
dialog \
341+
--hline "$SCRIPT_GITHUB_URL" \
342+
--title "Error" \
343+
--backtitle "ydownl.sh" \
344+
--msgbox "$1" 10 80
345+
}
346+
347+
#######################################
348+
# Shows the dialog-based info dialog
349+
# Arguments:
350+
# $1 = info message
351+
# Outputs:
352+
# none
353+
#######################################
354+
function showInfoDialog () {
355+
dialog \
356+
--hline "$SCRIPT_GITHUB_URL" \
357+
--title "Info" \
321358
--backtitle "ydownl.sh" \
322-
--msgbox "$1" 10 90
359+
--timeout "$CONFIG_INFODIALOG_TIMEOUT" \
360+
--msgbox "$1" 10 80
323361
}
324362

363+
325364
#######################################
326365
# Call youtube-dl and tell it to run self update
327366
# Arguments:
@@ -330,16 +369,32 @@ function showErrorDialog () {
330369
# none
331370
#######################################
332371
function youtubeDLUpdate() {
333-
reset
372+
#reset
373+
printAsciiArt
334374
youtube-dl --update
335375
printf "\n"
336376
read -p "Press enter to continue"
337377
showMainMenu
338378
}
339379

380+
381+
function printAsciiArt() {
382+
reset
383+
printf ' _ _ _ \n'
384+
printf ' | | | | | | \n'
385+
printf ' _ _ __| | _____ ___ __ | | ___| |__ \n'
386+
printf '| | | |/ _` |/ _ \ \ /\ / / \ _ | | / __| _ \ \n'
387+
printf '| |_| | (_| | (_) \ V V /| | | | |_\__ \ | | |\n'
388+
printf ' \__, |\__,_|\___/ \_/\_/ |_| |_|_(_)___/_| |_|\n'
389+
printf ' __/ | \n'
390+
printf ' |___/\n\n'
391+
}
392+
393+
340394
# ------------------------------------------------------------------------------
341395
# SCRIPT
342396
# ------------------------------------------------------------------------------
343397
initColors
344398
checkDependencies
399+
checkScriptVersion "silent"
345400
showUrlInputDialog

0 commit comments

Comments
 (0)