Skip to content

Commit

Permalink
Merge pull request #38 from petronny/beta
Browse files Browse the repository at this point in the history
fixed bug #36 && 可以根据任务的状态调整颜色
  • Loading branch information
kikyous committed Dec 17, 2014
2 parents 566eecc + 491c96a commit 7bbe604
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
30 changes: 20 additions & 10 deletions xfdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
class XFdownUi:
palette = [
('body', '', '', 'standout'),
('header', 'black', 'light gray', 'standout'),
('header', 'light cyan', 'black', 'standout'),
('footer', 'light gray', 'black'),
('button normal','', '', 'standout'),
('button downloading','dark blue', '', 'standout'),
('button checking','yellow', '', 'standout'),
('button failed','dark red', '', 'standout'),
('button select','white', 'dark green'),
('button selected','white', 'dark blue'),
('button disabled','dark gray','dark blue'),
('exit', 'white', 'dark cyan'),
('key', 'light cyan', 'black', 'underline'),
Expand All @@ -23,9 +25,10 @@ class XFdownUi:
footer_text = [
('key', "UP或K"), ",", ('key', "DOWN或J"), "上下移动 ,",
('key', "SPACE"), "选择项目 ,",
('key', "ENTER"), "下载项目 ,", ('key', "D"), "删除项目 ,",('key', "O"),
"在线播放 ,",
('key', "Q"), " 退出",
('key', "ENTER"), "下载项目 ,",
('key', "D"), "删除项目 ,",
('key', "O"), "在线播放 ,",
('key', "Q"), " 退出",
]

def create_checkbox(self, g=None, name='', font=None, fn=None):
Expand All @@ -38,15 +41,23 @@ def setup_view(self):
l = []
self.items = []
j = xf.getlist()
for size ,percent,name in j:
for size,percent,name,status,tasktype,fileurl in j:
w = self.create_checkbox()
self.items.append(w)
w = urwid.Columns( [('fixed', 4, w),
('fixed',7,urwid.Text(size, align='right')),
('fixed',6,urwid.Text(percent+'%', align='right')),
urwid.Text(name)],1)

w = urwid.AttrWrap(w, 'button normal', 'button select')
if status == 12:
w = urwid.AttrWrap(w, 'button normal', 'button select')
elif status == 6:
w = urwid.AttrWrap(w, 'button downloading', 'button select')
elif status == 8:
w = urwid.AttrWrap(w, 'button checking', 'button select')
elif status == 7:
w = urwid.AttrWrap(w, 'button failed', 'button select')

l.append(w)

w = urwid.ListBox(urwid.SimpleListWalker(l))
Expand Down Expand Up @@ -110,13 +121,12 @@ def work(self):
xf.download(self.getSelected())
elif self.key==['d']:
xf.deltask(self.getSelected())
self.setMsg("删除成功")
self.loop.run()
self.main()
elif self.key==['o']:
xf.online_v(self.getSelected())
elif self.key==['q']:
print (" exit now.")
exit(0)
exit(0)

if '__main__'==__name__:
def usage():
Expand Down
14 changes: 8 additions & 6 deletions xfdown_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def download(self,lists):
self.gethttp(lists)
cmds=[]
for i in lists:
cmd=['aria2c', '-c', '-s10', '-x10', '--header', 'Cookie:ptisp=edu; FTN5K=%s'%self.filecom[i], '%s'%self.filehttp[i]]
cmd=['aria2c', '-c', '-s10', '-x10', '--header', 'Cookie: FTN5K=%s'%self.filecom[i], '%s'%self.filehttp[i]]

cmds.append(cmd)

Expand Down Expand Up @@ -240,7 +240,7 @@ def getfilename_url(self,url):
filename=url.split("/")[-1]
return filename.split("?")[0]
def __getlogin(self):
self.__request(url ="http://lixian.qq.com/handler/lixian/check_tc.php",data={},savecookie=True)
self.__request(url ="http://lixian.qq.com/handler/log_handler.php",data={'cmd': 'stat'},savecookie=True)
urlv = 'http://lixian.qq.com/handler/lixian/do_lixian_login.php'
f=open(self.__cookiepath)
fi = re.compile('skey="([^"]+)"')
Expand All @@ -254,7 +254,7 @@ def getlist(self):
得到任务名与hash值
"""
urlv = 'http://lixian.qq.com/handler/lixian/get_lixian_items.php'
res = self.__request(urlv, {'page': 0, 'limit': 500})
res = self.__request(urlv, {'page': 0, 'limit': 200})
res = json.JSONDecoder().decode(res)
result = []
if res["msg"]==_('未登录!'):
Expand All @@ -269,13 +269,16 @@ def getlist(self):
self.filemid = []
if not res["data"]:
return result
res['data'].sort(key=lambda x: x["file_name"])
#res['data'].sort(key=lambda x: x["file_name"])
# _print ("序号\t大小\t进度\t文件名")
for num in range(len(res['data'])):
index=res['data'][num]
self.filename.append(index['file_name'].encode("u8"))
self.filehash.append(index['hash'])
size=index['file_size']
status=index['dl_status']
fileurl=index['file_url']
tasktype=index['task_type']
self.filemid.append(index['mid'])
if size==0:
percent="-0"
Expand All @@ -290,7 +293,7 @@ def getlist(self):
else:
break
size="%.1f%s"%(size,_dw)
item=(size,percent,_(self.filename[num]))
item=(size,percent,_(self.filename[num]),status,tasktype,fileurl)
result.append(item)
return result

Expand All @@ -314,7 +317,6 @@ def deltask(self,lists):
for i in lists:
data={'mids':self.filemid[i]}
self.__request(urlv,data)
_print("任务删除完成")


def __addtask(self):
Expand Down

0 comments on commit 7bbe604

Please sign in to comment.