forked from djdagovs/zippyshare
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzippyshare.sh
More file actions
120 lines (104 loc) · 3.18 KB
/
zippyshare.sh
File metadata and controls
120 lines (104 loc) · 3.18 KB
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
#!/bin/bash
# @Description: zippyshare.com file download script
# @Author: Live2x
# @URL: https://github.com/ffluegel/zippyshare
# @Version: 201902240001
# @Date: 2019-02-24
# @Usage: ./zippyshare.sh url
declare OUTDIR
if [ -d "${2}" ]
then
OUTDIR=${2}
length=${#OUTDIR}
last_char=${OUTDIR:length-1:1}
[[ $last_char != "/" ]] && OUTDIR="$OUTDIR/"; :
echo File will be saved to $OUTDIR
fi
if [ -z "${1}" ]
then
echo "usage: ${0} url"
echo "batch usage: ${0} url-list.txt"
echo "url-list.txt is a file that contains one zippyshare.com url per line"
exit
fi
function zippydownload()
{
prefix="$( echo -n "${url}" | cut -c "11,12,31-38" | sed -e 's/[^a-zA-Z0-9]//g' )"
cookiefile="${prefix}-cookie.tmp"
infofile="${prefix}-info.tmp"
# loop that makes sure the script actually finds a filename
filename=""
retry=0
while [ -z "${filename}" -a ${retry} -lt 10 ]
do
let retry+=1
rm -f "${cookiefile}" 2> /dev/null
rm -f "${infofile}" 2> /dev/null
curl -s -c "${cookiefile}" -o "${infofile}" -L "${url}"
filename="$( cat "${infofile}" | grep "/d/" | cut -d'/' -f5 | cut -d'"' -f1 | grep -o "[^ ]\+\(\+[^ ]\+\)*" )"
done
if [ "${retry}" -ge 10 ]
then
echo "could not download file from ${url}"
rm -f "${cookiefile}" 2> /dev/null
rm -f "${infofile}" 2> /dev/null
return 1
fi
# Get cookie
if [ -f "${cookiefile}" ]
then
jsessionid="$( cat "${cookiefile}" | grep "JSESSIONID" | cut -f7)"
else
echo "can't find cookie file for ${prefix}"
exit 1
fi
if [ -f "${infofile}" ]
then
# Get url algorithm
dlbutton="$(grep -oE 'var a = [0-9]+;' ${infofile} | grep -oE '[0-9]+')"
if [ -n "${dlbutton}" ]
then
algorithm="${dlbutton}/3+${dlbutton}%742589"
else
echo "could not get zippyshare url algorithm"
exit 1
fi
a="$( echo $(( ${algorithm} )) )"
# Get ref, server, id
ref="$( cat "${infofile}" | grep 'property="og:url"' | cut -d'"' -f4 | grep -o "[^ ]\+\(\+[^ ]\+\)*" )"
server="$( echo "${ref}" | cut -d'/' -f3 )"
id="$( echo "${ref}" | cut -d'/' -f5 )"
else
echo "can't find info file for ${prefix}"
exit 1
fi
# Build download url
dl="https://${server}/d/${id}/${a}/${filename}"
# Set browser agent
agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36"
echo "${filename}"
# Start download file
curl -# -A "${agent}" -e "${ref}" -H "Cookie: JSESSIONID=${jsessionid}" -C - "${dl}" -o "${OUTDIR}${filename}"
rm -f "${cookiefile}" 2> /dev/null
rm -f "${infofile}" 2> /dev/null
}
if [ -f "${1}" ]
then
if [[ ${1} == *".dlc"* ]];
then
decrypt-dlc ${1}
for url in $( cat urls.txt | grep -i 'zippyshare.com' )
do
zippydownload "${url}"
done
rm urls.txt
else
for url in $( cat "${1}" | grep -i 'zippyshare.com' )
do
zippydownload "${url}"
done
fi
else
url="${1}"
zippydownload "${url}"
fi