-
Notifications
You must be signed in to change notification settings - Fork 83
/
zx
executable file
·127 lines (109 loc) · 3.57 KB
/
zx
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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import zhuaxia.config as config
import sys
#load config at very beginning
config.load_config()
import sys,getopt
import zhuaxia.util as util
import logging
import zhuaxia.log as log
import zhuaxia.threadpool as threadpool
import zhuaxia.xiami as xm
import zhuaxia.downloader as downloader
import zhuaxia.commander as commander
import zhuaxia.zxver as zxver
import zhuaxia.option as user_option
import zhuaxia.hist_handler as hist_handler
# logger name
logger_name = 'zxLogger'
#after init config, loading message
if config.LANG.upper() == 'CN':
import zhuaxia.i18n.msg_cn as msg
else:
import zhuaxia.i18n.msg_en as msg
help_info = msg.help_info
def usage():
"""print usage information"""
import pydoc
pydoc.pager(help_info)
sys.exit(0)
def version():
"""print version"""
print msg.ver_text + zxver.version
def export_or_clear_hist(export_hist, empty_hist):
if export_hist and empty_hist : raise getopt.GetoptError("option -e and -d cannot be used together!")
if export_hist:
hist_handler.export_hists()
sys.exit(0)
elif empty_hist:
print log.hl(msg.history_clearing ,'cyan')
while True:
count = hist_handler.get_history_count()
sys.stdout.write(msg.history_clear_confirm % count)
choice = raw_input().lower()
if choice == 'n':
sys.exit(0)
elif choice == 'y':
hist_handler.empty_hists()
sys.exit(0)
if __name__ == '__main__':
log.setup_log(logger_name, config.LOG_LVL_CONSOLE, config.LOG_LVL_FILE)
LOG = log.get_logger(logger_name)
try:
hq = False
inFile = ''
inUrl = ''
needProxyPool = False
dl_lyric = False
incremental_dl = False
export_hist = False
empty_hist = False
if len(sys.argv)<2: raise getopt.GetoptError("parameters are missing...")
opts, args = getopt.getopt(sys.argv[1:],":f:Hhvplied")
for o, a in opts:
if o == '-h':
usage()
sys.exit(0)
elif o == '-H':
hq = True
elif o == '-v':
version()
sys.exit(0)
elif o == '-f':
inFile = a
elif o == '-p':
LOG.warning(msg.experimental)
needProxyPool = True
elif o == '-l':
dl_lyric = True
elif o == '-i':
incremental_dl = True
elif o == '-e': #export history data
export_hist = True
elif o == '-d': #empty history
empty_hist = True
#handle the export and empty
export_or_clear_hist(export_hist, empty_hist)
## -f check file
if not inFile:
if not len(args):
raise getopt.GetoptError("input file or xiami url is needed")
else:
inUrl = args[0]
#build the user option
option = user_option.Option()
option.is_hq = hq
option.need_proxy_pool = needProxyPool
option.dl_lyric = dl_lyric
option.inFile = inFile
option.inUrl = inUrl
option.incremental_dl = incremental_dl
#print debug
option.debug_me()
# ok, let's go!
commander.shall_I_begin(option)
except getopt.GetoptError as e:
LOG.error(str(e))
print log.hl("\nTo know how to use zhuaxia, run:\n\tzx -h\n",'cyan')
sys.exit(2)