-
Notifications
You must be signed in to change notification settings - Fork 0
/
ytd
executable file
·64 lines (42 loc) · 1.14 KB
/
ytd
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
#!/bin/bash
#ytd calls youtube-dl with -f mp4 then updates the date modified of the downloaded file.
#default directory is the home directory
script=$( basename $0 )
#params check
if [ $# -eq 0 ]
then
echo "Usage: $script <URL>" 1>&2
exit 1
fi
#initialize
echo "ytd: download in progress"
set +o noclobber
file=' '
echo ' ' > ytd_log #override old file
trap "rm ytd_log -f" exit 1 2 3 9 19 20
#download then print output (tty and file)
youtube-dl "$*" -f mp4 |
while read line
do
echo "$line" | tee -a ytd_log
done
#obtain file name
file=$( cat ytd_log | grep "\[download\] Destination:" | gawk -F': ' '{print $2}' )
# [Valid alternative] cat ytd_log | grep Destination: | cut -d: -f2
#if already downloaded end here
cat ytd_log | grep "already been downloaded" > /dev/null
if [ $? -eq 0 ]
then
echo
echo "$script says: already downloaded. check file name" 1>&2
exit 1
fi
#touch new file because date from Youtube will be inaccurate
if [ -f "$file" ];
then
touch "$file"
else
echo "ytd says:"
echo "No such file. Cannot set date modified. Please check the file name" 1>&2
fi
#created 08/03/2018