-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsget
executable file
·64 lines (39 loc) · 1.16 KB
/
jsget
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
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# simle sciprt for downloading from jshare.net
import os
import sys
import urllib
import subprocess
import chardet
def urlunquote(url):
return urllib.unquote(url)
def guess_encoding(text):
return 'gb18030'
result = chardet.detect(text)
encoding = result["encoding"]
encoding = encoding.lower()
if encoding in [ 'gb2312', 'gbk', 'gb18030',] :
return 'gb18030'
elif encoding in [ 'ascii', 'utf-8', ]:
return 'utf-8'
def decode(text):
encoding = guess_encoding(text)
uni_text = text.decode(encoding)
return uni_text
def get_filename_from_url(url):
_, lastpart = os.path.split(url)
lastpart = urlunquote(lastpart)
filename = decode(lastpart)
return filename
if __name__ == '__main__':
if len(sys.argv) > 1 :
options = sys.argv[:-1]
url = sys.argv[-1]
filename = get_filename_from_url(url)
command = ['wget', '-c',]
command.extend( ['-O', filename,] )
command.extend( options)
command.append(url)
print "command: %s" % (command)
subprocess.call( command, shell=False)