def downBTFile(b): ses = lt.session() ses.listen_on(port_lsit[0][0],port_lsit[0][1]) p = "%s%s%s"%(FILE_SAVE_PATH,b.torrent,b.name) s = "%s%s"%(FILE_SAVE_PATH,b.path) e = lt.bdecode(open(p, 'rb').read()) info = lt.torrent_info(e) #print 'PPPPPPPPPPP :',p #print 'ssssssssssp :',s params = {'save_path': str(s),'storage_mode': lt.storage_mode_t.storage_mode_sparse,'ti': info }#,lt.storage_mode_t(2) h = ses.add_torrent(params) params = {'save_path': 'ttt', 'storage_mode': lt.storage_mode_t.storage_mode_sparse,#lt.storage_mode_t(2), 'ti': info } while (not h.is_seed()) and public_dic_bt.get(b.id)[1]: s = h.status() #print 'b'*30 try: if s.state ==3: #载中的返回值 b.resources = "%s/%s" %(s.num_pieces,len(s.pieces)) b.requestUp = s.total_upload b.requestDown = s.total_download b.speedUp = '%.2f kB/s' %(s.upload_rate / 1000) b.speedDown = '%.2f kb/s' %(s.download_rate / 1000) b.percent = '%.2f%%'%(s.progress * 100) b.status = 2 b.save() #print '====>',b.speedDown else: b.speedUp = '-' b.speedDown = '-' b.status = 4 b.save() time.sleep(1) except:pass time.sleep(1) #print 'down over...' b.status = 1 b.speedUp = '-' b.speedDown = '-' b.requestDown = '-' b.requestUp = '-' b.percent = "100%" b.resources = "-" b.save() # 存放 Fileinfo_up bfp = "%s%s/" %(b.path,b.fname) fp = "%s%s" %(FILE_SAVE_PATH,bfp) lfs = os.listdir(fp) for f in lfs: try: #print '0'*30,f.decode('utf8') name,ftype = os.path.splitext(f) fu = Fileinfo_up() fu.name = name fu.ftype = ftype fu.size = b.totalSize fu.type = 0 fu.owner = b.user fu.status = 1 fu.path = bfp tmp_tiem = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") fu.lastwritetime = tmp_tiem fu.uploadstarttime = tmp_tiem fu.timestamp = 0 fu.userid = User.objects.get(UserName=b.user) fu.save() except Exception,e: print 'ddddddddddddd :',e pass
def downBTFile(b): ses = lt.session() ses.listen_on(port_lsit[0][0], port_lsit[0][1]) p = "%s%s%s" % (FILE_SAVE_PATH, b.torrent, b.name) s = "%s%s" % (FILE_SAVE_PATH, b.path) e = lt.bdecode(open(p, 'rb').read()) info = lt.torrent_info(e) #print 'PPPPPPPPPPP :',p #print 'ssssssssssp :',s params = { 'save_path': str(s), 'storage_mode': lt.storage_mode_t.storage_mode_sparse, 'ti': info } #,lt.storage_mode_t(2) h = ses.add_torrent(params) params = { 'save_path': 'ttt', 'storage_mode': lt.storage_mode_t.storage_mode_sparse, #lt.storage_mode_t(2), 'ti': info } while (not h.is_seed()) and public_dic_bt.get(b.id)[1]: s = h.status() #print 'b'*30 try: if s.state == 3: #载中的返回值 b.resources = "%s/%s" % (s.num_pieces, len(s.pieces)) b.requestUp = s.total_upload b.requestDown = s.total_download b.speedUp = '%.2f kB/s' % (s.upload_rate / 1000) b.speedDown = '%.2f kb/s' % (s.download_rate / 1000) b.percent = '%.2f%%' % (s.progress * 100) b.status = 2 b.save() #print '====>',b.speedDown else: b.speedUp = '-' b.speedDown = '-' b.status = 4 b.save() time.sleep(1) except: pass time.sleep(1) #print 'down over...' b.status = 1 b.speedUp = '-' b.speedDown = '-' b.requestDown = '-' b.requestUp = '-' b.percent = "100%" b.resources = "-" b.save() # 存放 Fileinfo_up bfp = "%s%s/" % (b.path, b.fname) fp = "%s%s" % (FILE_SAVE_PATH, bfp) lfs = os.listdir(fp) for f in lfs: try: #print '0'*30,f.decode('utf8') name, ftype = os.path.splitext(f) fu = Fileinfo_up() fu.name = name fu.ftype = ftype fu.size = b.totalSize fu.type = 0 fu.owner = b.user fu.status = 1 fu.path = bfp tmp_tiem = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") fu.lastwritetime = tmp_tiem fu.uploadstarttime = tmp_tiem fu.timestamp = 0 fu.userid = User.objects.get(UserName=b.user) fu.save() except Exception, e: print 'ddddddddddddd :', e pass