@@ -23,40 +23,36 @@ readonly YELLOW="\033[00;33m"
2323readonly BOLD=" \033[01m"
2424readonly FINE=" \033[0m"
2525
26- ver=' v1.7.4'
27- regex=' (https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*\.[A-Za-z0-9\+&@%#/=~_|():?]+'
28- is_z0r=' http://z0r.it/[^ \n]'
29- url=(http://$1 )
26+ ver=' v1.8'
27+ regex=' ((https?)*:\/\/)*[-A-Za-z0-9\+&@#/%?=~_|!:,.;]+\.[A-Za-z0-9\+&@%#/=~_|():?]{2,}'
3028mode=-s
3129dep=(curl awk xclip wget)
3230apikey=4e4b657a91
3331clip=$( xclip -o 2> /dev/null)
3432LOGDIR=/$HOME /.z0r_logs
33+
3534# upload function (long -> short)
3635shr (){
3736 url_e=$( echo $1 | sed ' s/?/%3F/' )
38- short=$( curl $mode -L " http://z0r.it/yourls-api.php?signature=$apikey &action=shorturl&title=uploaded_with_z0r_script&keyword=$2 &format=simply&url=$url_e " | awk -F ' /' ' {print$NF}' )
39- uc=" http://z0r.it/$short "
37+ short=$( curl $mode -L " http://z0r.it/yourls-api.php?signature=$apikey &action=shorturl&title=uploaded_with_z0r_script&keyword=$2 &format=simply&url=$url_e " )
4038 if [ -n " $short " ]; then
41- if curl $mode -L " http://z0r.it/yourls-api.php?signature=$apikey &action=shorturl&title=uploaded_with_z0r_script&keyword=$2 &format=simply&url=$url_e " | grep -q " Errore 406" ; then
42- echo -e $RED " Error 406 - URL not valid(try to use https instead of http or try encoding the URL)" $FINE
43- else
44- echo " http://z0r.it/$short " && echo " $( date +" %d-%h-%Y %H.%M.%S" ) - $uc - $1 " >> $LOGDIR
45- echo " $uc " | xclip -selection clipboard
39+ if curl $mode -L " http://z0r.it/yourls-api.php?signature=$apikey &action=shorturl&title=uploaded_with_z0r_script&keyword=$2 &format=simply&url=$url_e " | grep -q " Unreachable" ; then
40+ echo -e $RED " Invalid URL" $FINE
41+ elif [ -n " $2 " ]; then
42+ if curl $mode -L " http://z0r.it/yourls-api.php?signature=$apikey &action=shorturl&title=uploaded_with_z0r_script&keyword=$2 &format=simply&url=$url_e " | grep -q " already exists" ; then
43+ echo -e $RED " Custom URL already exists" $FINE
44+ fi
45+ else
46+ echo " $short " && echo " $( date +" %d-%h-%Y %H.%M.%S" ) - $short - $1 " >> $LOGDIR
47+ echo " $short " | xclip -selection clipboard
4648 fi
4749 else
4850 if [ -n " $2 " ]; then
4951 echo -e $RED " custom URL already in use" $FINE
5052 fi
5153 fi
5254 }
53- # expand function (short -> long)
54- expand (){
55- avi=$( echo ${@: 2} | awk -F ' /' ' {print$NF}' )
56- exp=$( curl $mode -L " http://z0r.it/yourls-api.php?signature=$apikey &action=expand&title=check_with_z0r_scipt&format=simply&shorturl=$avi " )
57- echo $exp
58- echo " $exp " | xclip -selection clipboard
59- }
55+
6056# help screen
6157help (){
6258 echo -e " $YELLOW$BOLD $0 $FINE $GREEN$ver$FINE , faster uploader for z0r.it shortner. Based on YOURL API"
@@ -67,10 +63,8 @@ help(){
6763 echo " "
6864 echo -e $GREEN " ======================================================================================" $FINE
6965 echo " Available Options:"
70- echo " -e <short_URL> expand URL (short -> long)"
7166 echo " -h display this page"
7267 echo " -c <short_URL> display numbers of clicks"
73- echo " -d check dependencies"
7468 echo " -l show shorting history"
7569 echo " -m <long_URL1> <long_URL2> ... mass shorting"
7670 echo " -r reset history"
@@ -80,48 +74,32 @@ help(){
8074 }
8175# stats
8276stats (){
83- lil=$( echo ${ @: 2} | awk -F ' /' ' {print$NF}' )
77+ lil=$( echo $OPTARG | awk -F ' /' ' {print$NF}' )
8478 click=$( curl -s -L " http://z0r.it/yourls-api.php?signature=$apikey &action=url-stats&format=json&shorturl=$lil " | grep -Po ' "clicks":.*?[^\\]"' )
8579 echo $click
8680}
8781mss (){
8882 for i in ${@: 2} ; do
89- mass=$( curl -s -L " http://z0r.it/yourls-api.php?signature=$apikey &action=shorturl&title=uploaded_with_z0r_script&format=simply&url=$( echo $i | sed ' s/?/%3F/' ) " | awk -F ' /' ' {print$NF}' )
90- if wget --spider " $i " 2> /dev/null || curl -s --head $i | head -n 1 | grep -q " 405" ; then
83+ mass=$( curl -s -L " http://z0r.it/yourls-api.php?signature=$apikey &action=shorturl&title=uploaded_with_z0r_script&format=simply&url=$( echo $i | sed ' s/?/%3F/' ) " )
9184 if [ -n " $mass " ] ; then
92- if curl $mode -L " http://z0r.it/yourls-api.php?signature=$apikey &action=shorturl&title=uploaded_with_z0r_script&format=simply&url=$( echo $i | sed ' s/?/%3F/' ) " | grep -q " Errore 406 " ; then
93- echo -e $RED " Error 406 - URL not valid(try to use https instead of http) " $FINE
85+ if curl $mode -L " http://z0r.it/yourls-api.php?signature=$apikey &action=shorturl&title=uploaded_with_z0r_script&format=simply&url=$( echo $i | sed ' s/?/%3F/' ) " | grep -q " Unreachable " ; then
86+ echo -e $RED " Invalid URL" $FINE
9487 else
9588
96- echo " http://z0r.it/ $mass " && echo " $( date +" %d-%h-%Y %H.%M.%S" ) - http://z0r.it/ $mass - $i " >> $LOGDIR
89+ echo " $mass " && echo " $( date +" %d-%h-%Y %H.%M.%S" ) - $mass - $i " >> $LOGDIR
9790 fi
9891 else
9992 echo -e $RED " Bad Request" $FINE
10093 fi
101- else
102- echo -e $RED " $i is not a valir URL" $FINE
103- fi
10494 done
10595}
10696# control over argument
10797is_url (){
108- if [[ $1 =~ $regex ]]; then
109- if wget --spider " $1 " 2> /dev/null || curl $mode --head $1 | head -n 1 | grep -q " 405" ; then
98+ if [[ $1 =~ $regex ]]; then
11099 shr $1 $2
111100 else
112- echo -e $RED " Page does not exist" $FINE
113- fi
114- else
115- if [[ $url =~ $regex ]]; then
116- if wget --spider " $1 " 2> /dev/null || curl $mode --head $1 | head -n 1 | grep -q " 405" | grep -q " 405" ; then
117- shr $1 $2
118- else
119- echo -e $RED " Page does not exist" $FINE
101+ echo -e $RED " " $1 " is not a valid URL" $FINE
120102 fi
121- else
122- echo -e $RED " " $1 " is not a valid url" $FINE
123- fi
124- fi
125103}
126104# check dipendencies
127105checkdep (){
160138}
161139# option parser
162140opsparser (){
163- while getopts " :hvulre :c:m:" opt; do
141+ while getopts " :hvulr :c:m:" opt; do
164142 case " $opt " in
165143 h) help
166144 exit 0
167145 ;;
168- e) if [[ ${@: 2} =~ $is_z0r ]]; then
169- expand $@
170- else
171- echo -e $RED " Enter a valid z0r url(http://z0r.it/...)" $FINE
172- fi
173- exit 0
174- ;;
175- c) stats $@
146+ c) stats $OPTARG
176147 exit 0
177148 ;;
178149 m)
0 commit comments