Skip to content

Commit 00dd07f

Browse files
author
Nhoya
committed
Added -m option for mass-shorting, fixed argparsing
1 parent f00f599 commit 00dd07f

File tree

2 files changed

+51
-31
lines changed

2 files changed

+51
-31
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ This script lets you to **quickly shrink with z0r.it** any link and put the shri
1414

1515
*z0r -h* -> shows help
1616

17-
*z0r -e [short_link] -> expand function (short -> long)
17+
*z0r -e* [short_link] -> expand function (short -> long)
1818

1919
*z0r -c [short_link]* -> show number of clicks
2020

2121
*z0r -d* -> check dependencies
2222

2323
*z0r -l* -> show history
24+
25+
*z0r -m <long_URL1> <long_URL2>* ... -> mass shorting

z0r

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ readonly YELLOW="\033[00;33m"
2222
readonly BOLD="\033[01m"
2323
readonly FINE="\033[0m"
2424

25-
ver='1.3'
25+
ver='1.4'
2626
regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*\.[-A-Za-z0-9\+&@#/%=~_|():?]+'
2727
is_z0r='http://z0r.it/[^ \n]'
2828
url=(http://$1)
@@ -44,7 +44,7 @@ shr(){
4444
}
4545
#expand function (short -> long)
4646
expand(){
47-
avi=$(echo $@ |awk -F '/' '{print$NF}')
47+
avi=$(echo ${@:2} |awk -F '/' '{print$NF}')
4848
exp=$(curl $mode -L "http://z0r.it/yourls-api.php?signature=$apikey&action=expand&title=check_with_z0r_scipt&format=simply&shorturl=$avi")
4949
echo $exp
5050
echo "$exp" |xclip -selection clipboard
@@ -64,56 +64,70 @@ help(){
6464
echo " -c <short_URL> display numbers of clicks"
6565
echo " -d check dependencies"
6666
echo " -l show shorting history"
67+
echo " -m <long_URL1> <long_URL2> ... mass shorting"
6768
echo -e $GREEN"======================================================================================"$FINE
6869

6970
}
7071
#stats
7172
stats(){
72-
avi=$(echo $@ |awk -F '/' '{print$NF}')
73-
click=$(curl -s -L "http://z0r.it/yourls-api.php?signature=$apikey&action=url-stats&format=json&shorturl=$avi"|grep -Po '"clicks":.*?[^\\]"')
74-
echo $click
73+
lil=$(echo ${@:2} |awk -F '/' '{print$NF}')
74+
click=$(curl -s -L "http://z0r.it/yourls-api.php?signature=$apikey&action=url-stats&format=json&shorturl=$lil"|grep -Po '"clicks":.*?[^\\]"')
75+
echo $click
7576
}
76-
77-
#control over argument
78-
is_url(){
79-
if [[ $1 =~ $regex ]];then
80-
if wget --spider "$1" 2>/dev/null; then
81-
shr $1 $2
77+
mss(){
78+
for i in ${@:2}; do
79+
mass=$(curl -s -L "http://z0r.it/yourls-api.php?signature=$apikey&action=shorturl&title=uploaded_with_z0r_script&format=simply&url=$i"|awk -F '/' '{print$NF}')
80+
if wget --spider "$i" 2>/dev/null; then
81+
if [ -n "$mass" ] ; then
82+
echo "http://z0r.it/$mass" && echo "$(date +"%d-%h-%Y %H.%M.%S") - http://z0r.it/$mass - $i">>$LOGDIR
83+
else
84+
echo -e $RED"Bad Request"$FINE
85+
fi
8286
else
83-
echo -e $RED"Page does not exist"$FINE
87+
echo -e $RED"$i is not a valir URL"$FINE
8488
fi
85-
else
86-
if [[ $url =~ $regex ]];then
87-
if wget --spider "$1" 2>/dev/null; then
89+
done
90+
}
91+
#control over argument
92+
is_url(){
93+
if [[ $1 =~ $regex ]];then
94+
if wget --spider "$1" 2>/dev/null; then
8895
shr $1 $2
96+
else
97+
echo -e $RED"Page does not exist"$FINE
98+
fi
99+
else
100+
if [[ $url =~ $regex ]];then
101+
if wget --spider "$1" 2>/dev/null; then
102+
shr $1 $2
103+
else
104+
echo -e $RED"Page does not exist"$FINE
105+
fi
89106
else
90-
echo -e $RED"Page does not exist"$FINE
107+
echo -e $RED"Enter a valid url"$FINE
108+
fi
91109
fi
92-
else
93-
echo -e $RED"Enter a valid url"$FINE
94-
fi
95-
fi
96110
}
97111
#check dipendencies
98112
checkdep(){
99-
for i in "${dep[@]}"
100-
do
101-
if ( which $i &>/dev/null ); then
102-
echo -e $GREEN"$i found"$FINE
103-
else
104-
echo -e $RED"$i not found"$FINE
105-
fi
106-
done
113+
for i in "${dep[@]}"
114+
do
115+
if ( which $i &>/dev/null ); then
116+
echo -e $GREEN"$i found"$FINE
117+
else
118+
echo -e $RED"$i not found"$FINE
119+
fi
120+
done
107121
}
108122

109123
#option parser
110124
opsparser(){
111-
while getopts ":hvlde:c:" opt; do
125+
while getopts ":hvlde:c:m:" opt; do
112126
case "$opt" in
113127
h) help
114128
exit 0
115129
;;
116-
e) if [[ $@ =~ $is_z0r ]];then
130+
e) if [[ ${@:2} =~ $is_z0r ]];then
117131
expand $@
118132
else
119133
echo -e $RED"Enter a valid z0r url(http://z0r.it/...)"$FINE
@@ -126,6 +140,10 @@ while getopts ":hvlde:c:" opt; do
126140
d) checkdep $i
127141
exit 0
128142
;;
143+
m)
144+
mss $@
145+
exit 0
146+
;;
129147
v) echo $ver
130148
exit 0
131149
;;

0 commit comments

Comments
 (0)