-
Notifications
You must be signed in to change notification settings - Fork 17
/
termux-url-opener
130 lines (117 loc) · 3.07 KB
/
termux-url-opener
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
cd ~/storage/downloads/
# Make sure termux-api is installed to copy to clipboardautomatically
# https://play.google.com/store/apps/details?id=com.termux.api
# and
# pkg install termux-api
#
echo
read -p " Press _w_ for a Web page, anything else to continue:" web_or_video
if [ "$web_or_video" = "w" ]
then
echo
echo
echo " Markfown-formated link to the web page:"
echo " ======================================="
echo
weblink=$(echo "$1")
web_title=$(wget -qO- "$weblink" | gawk -v IGNORECASE=1 -v RS='</title' 'RT{gsub(/.*<title[^>]*>/,"");print;exit}')
#web_title=$(echo "$web_title" | recode html)
markdownlink="* [$web_title]($weblink)"
echo " $markdownlink"
termux-clipboard-set "$markdownlink"
else
echo
echo
echo " Markfown-formated link to the video:"
echo " ===================================="
echo
markdownlink=$(echo "* [`youtube-dl -e $1`]($1) - `youtube-dl --get-duration $youtubelink` mins")
echo " $markdownlink"
termux-clipboard-set "$markdownlink"
fi
echo
echo
echo " press _e_ or _q_ to exit"
echo " press _a_ to add to the links file"
echo " press _g_ to add and get all the links"
echo " press _n_ to clear the file and add the new link"
echo " press _c_ to view the links file"
echo " ...anything else to keep downloading..."
echo
read -p " press a key... " selected_action
break_loop="n"
while [ "$break_loop" = "n" ]
do
if [ "$selected_action" = "e" ]
then
exit;
elif [ "$selected_action" = "q" ]
then
exit;
elif [ "$selected_action" = "a" ]
then
echo "$markdownlink" >> ~/YT_links.md
#exit;
read -p " press a key... "
elif [ "$selected_action" = "g" ]
then
echo "$markdownlink" >> ~/YT_links.md
cat ~/YT_links.md | termux-clipboard-set
rm ~/YT_links.md
touch ~/YT_links.md
#exit;
read -p " press a key... "
elif [ "$selected_action" = "n" ]
then
rm ~/YT_links.md
echo "$markdownlink" >> ~/YT_links.md
#exit;
read -p " press a key... "
elif [ "$selected_action" = "c" ]
then
echo
echo "`cat ~/YT_links.md`"
echo
read -p " press a key... " selected_action
else
if [ "$selected_action" != "c" ]
then
break_loop="y"
fi
fi
done
if [ "$web_or_video" = "w" ]
then
exit;
fi
echo
echo Checking available resolutions...
echo
/data/data/com.termux/files/usr/bin/python /data/data/com.termux/files/usr/bin/ytdl $1
echo
echo Please choose the file you want to download:
echo "(enter 0 to download using youtube-dl or e to exit)"
read selected_file
if [ "$selected_file" = "" ]
then
selected_file="1"
fi
if [ "$selected_file" = "e" ]
then
exit;
fi
if [ "$selected_file" = "q" ]
then
exit;
fi
if [ "$selected_file" = "0" ]
then
echo
echo Running: youtube-dl $1
/data/data/com.termux/files/usr/bin/python /data/data/com.termux/files/usr/bin/youtube-dl $1
else
echo
echo Running: ytdl -n$selected_file $1
/data/data/com.termux/files/usr/bin/python /data/data/com.termux/files/usr/bin/ytdl -n $selected_file $1
fi