-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmega-download
executable file
·271 lines (248 loc) · 12.6 KB
/
mega-download
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/sh
##
## NAME: mega-download
##
## Made by Stefano Viola (aka) Esteban Sannin
## email: stefanoviola[at]sannioglug[dot]org
##
## NOTE: mega-download is a small downloader for
## Megaupload Premium Users
##
## LICENSE: GPL v.3
##
##
AUTHOR="Stefano Viola (aka) Esteban Sannin"
EMAIL="stefanoviola[at]sannioglug[dot]org"
COPYRIGHT="(C) 2010 Stefano Viola"
DATA_BUILD="MAY 2010"
VERSION="0.8.1"
LICENSE="GPLv3"
CONFIG_FILE_NAME=mega-download.cfg
CONFIG_FILE=`pwd`/$CONFIG_FILE_NAME
LIMIT_RATE_VALUE=`cat $CONFIG_FILE | grep LIMIT | cut -f 2 -d=` # Valore contenuto nel file di configurazione
DIR_DOWNLOAD_VALUE=`cat $CONFIG_FILE | grep DIR_DOWNLOAD | cut -f 2 -d\"` # Valore contenuto nel file di configurazione
DIR_DOWNLOAD=`pwd`
LIMIT_RATE=0
FINAL_LINK=`pwd`/.directLink
CONFIG_FILE=`pwd`/mega-download.cfg
read_config()
{ if [ -e $CONFIG_FILE ]; then
. ./mega-download.cfg
echo -n "\n\n\tLoaded configuration file $CONFIG_FILE...\n\n"
echo -n " LIMIT_RATE_VALUE = $LIMIT_RATE_VALUE\n"
echo -n " DIR_DOWNLOAD_VALUE = $DIR_DOWNLOAD_VALUE\n\n\n\n"
else
echo -n "\n\n\tConfiguration file mega-download.cfg not present!\n\n"
echo "Loaded Default Value:"
echo "LIMIT_RATE = $LIMIT_RATE (0 is unlimited)"
echo "DIR_DOWNLOAD = $DIR_DOWNLOAD"
echo ""
fi
}
version(){
echo -n "\n\n\tMega-Download v0.5\n\n"
echo -n " [INFO]: Downloader for only Megaupload Premium Users\n\n"
echo -n " [AUTHOR]: $AUTHOR\n"
echo -n " [EMAIL]: $EMAIL\n"
echo -n " [COPYRIGHT]: $COPYRIGHT\n"
echo -n " [DATA BUILD]: $DATA_BUILD\n"
echo -n " [VERSION]: $VERSION\n"
echo -n " [LICENSE]: $LICENSE\n\n\n"
}
clear(){
rm index.* .directLink .temp
}
usage(){
echo -n "\n\n"
echo -n "\tMega-Download the command line downloader\n"
echo -n "\t(C) 2010 Stefano Viola\n"
echo -n "\tstefanoviola[at]sannioglug[dot]org\n\n"
echo "[INFO]: "
echo " Downloader only for Premium Users "
echo "[USAGE]: "
echo " mega-download http://link.megaupload.com "
echo " If the cookie does not exist will be asked to create "
echo "[OPTION]: "
echo " -h Print this help "
echo " -v Print version info "
echo " -n Normal mode. Download any file: \"mega-download -n http://link-downlod\" "
echo " --list List mode. Download from a list of link "
echo " Example: mega-download --list list-link "
echo " list-link= is the file containing the list of links "
echo " --config start the interactive configuration parameters "
echo ""
echo "[CONFIGURATION]: To set up mega-download is easy. There are two possibilities: "
echo " 1. start \"mega-download --config\" and sets your parameters "
echo ""
echo " 2. Create the file: "
echo " \"mega-download.cfg\" in the same directory and insert this string: "
echo ""
echo " DIR_DOWNLOAD=your-path ---> your-path is the directory where the files are downloaded"
echo " LIMIT_RATE=1000 ---> 1000 is a byte limit to download (0 is unlimited) "
echo -n "\n\n"
#echo -n ""
#echo -n ""
#echo -n ""
}
capture_link(){
ls | grep index > .temp
number_link=`wc -l .temp | awk {'print $1'}`
dir="`pwd`/.temp"
for i in `seq 1 $number_link`;
do
p=p
sum=$i$p
temp_link=`sed -n $sum $dir`
cat_link=`cat $temp_link | grep files`
cat $temp_link | grep files | cut -f 2 -d\">>.directLink
done
}
case "$1" in
-h) usage
;;
-v) version
;;
-n) echo -n "\t\n\nNormal Mode\n"
read_config
wget -c $2 --limit-rate=$LIMIT_RATE -P $DIR_DOWNLOAD
;;
-t) read_config # for debug..
;;
--config) echo $LIMIT_RATE_VALUE
echo $DIR_DOWNLOAD_VALUE
control=1
if [ -e $CONFIG_FILE ]; then
while [ $control = 1 ]; do
echo -n "\n\n"
echo " ***************************************"
echo " * Setting your configuration file: *"
echo " * *"
echo " * 1 - Print current value *"
echo " * 2 - Setting current value *"
echo " * 3 - Exit menu config *"
echo " * *"
echo " ***************************************"
echo -n "\nenter your choice: "
read menu_value
case "$menu_value" in
1)
echo -n "\nCurrent value:\n\n"
cat $CONFIG_FILE | grep =
echo
;;
2)
echo ""
echo " ****************************************"
echo " * Choose the value to be set: *"
echo " * *"
echo " * 1 - Setting the Limit Rate *"
echo " * 2 - Setting the download directory *"
echo " * 3 - Return to main menu *"
echo " * *"
echo " ****************************************"
echo -n "\nenter your choice: "
read submenu_value
case "$submenu_value" in
1)
echo "Current limit rate is $LIMIT_RATE_VALUE (byte)"
echo -n "Insert new value (byte): "
read new_limit_rate
sed -i "s%$LIMIT_RATE_VALUE%$new_limit_rate%g" $CONFIG_FILE
;;
2)
echo "Current Download directory is: $DIR_DOWNLOAD_VALUE"
echo -n "Insert new path: "
read new_dir_download
sed -i "s%$DIR_DOWNLOAD_VALUE%$new_dir_download%g" $CONFIG_FILE
;;
3)
echo "Return to main menu"
;;
*)
echo "Immesso valore errato"
;;
esac
;;
3)
control=0
echo -n "\nexit\n"
;;
*)
echo "error value"
;;
esac
done
else
echo -n "\n\tConfigure file not present!\t\t\n"
echo "Creating new file configuration..."
echo ""
echo -n "Insert Limit Rate (byte): "
read limit
echo -n "Insert Download directory: "
read directory
echo "LIMIT_RATE=$limit" >> $CONFIG_FILE_NAME
echo "DIR_DOWNLOAD=\"$directory\"" >> $CONFIG_FILE_NAME
if [ -e $CONFIG_FILE_NAME ]; then
echo "Configuration file created!"
else
echo "Error file not created"
fi
fi
;;
--list)
echo "LIST MODE"
wget -c --load-cookies ./cookie -i $2
capture_link
echo -n "Download file...\n"
read_config
wget -c --load-cookies ./cookie -i "$FINAL_LINK" --limit-rate=$LIMIT_RATE -P $DIR_DOWNLOAD
clear
;;
*)
if [ -e `pwd`/cookie ]; then
if [ -z $1 ]; then #controllo se ci sono argomenti passati da linea di comando
echo -n "Insert direct link:\n"
read full_link
echo -n "Get direct link... \n"
sleep 3
wget -c --load-cookies ./cookie $full_link -q
echo -n "direct link obtained!\n"
capture_link
echo -n "Download file...\n"
def_link=`pwd`/.directLink
read_config
wget -c --load-cookies ./cookie -i "$def_link" --limit-rate=$LIMIT_RATE -P $DIR_DOWNLOAD
clear
else
echo -n "Get direct link... \n"
wget -c --load-cookies ./cookie $1 -q
capture_link
echo -n "Download file...\n"
read_config
wget -c --load-cookies ./cookie -i "$FINAL_LINK" --limit-rate=$LIMIT_RATE -P $DIR_DOWNLOAD
clear
fi
else
echo -n "\n\n\tCookie Not present!\n"
echo -n "\tGenerating new Cookie...\n\n"
echo -n "Insert Megaupload User:\n"
read user
stty -echo # Disabilita la visualizzazione sullo schermo.
echo -n "Insert Megaupload Password:\n"
read passwd
stty echo # Ripristina la visualizzazione sullo schermo.
echo -n "Generating the cookie..."
wget --save-cookies ./cookie --post-data "login=1&next=c%3Daccount&username=$user&password=$passwd" -O - http://www.megaupload.com/?c=account > /dev/null
status=`cat cookie | grep TRUE | awk '{print $2}'`
if [ -z $status ]; then
echo -n "Error: Access Failed!\n"
echo -n "Cookie not Generated!\n\n"
rm cookie
else
echo -n "\nCookie Generated!\n"
echo -n "Restart mega-download\n\n"
fi
fi
;;
esac
exit 0