Skip to content

Commit

Permalink
use requests
Browse files Browse the repository at this point in the history
  • Loading branch information
chliny committed Oct 5, 2013
1 parent cc3f4a0 commit 496aca9
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions xfdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import random,time
import json,os,sys,re,hashlib
import getopt
from poster.streaminghttp import register_openers
#from poster.streaminghttp import register_openers

def _(string):
try:
Expand Down Expand Up @@ -114,8 +114,9 @@ def start(self):
except:
pass

opener = register_openers()
opener.add_handler(request.HTTPCookieProcessor(self.cookieJar))
opener = request.build_opener(request.HTTPCookieProcessor(self.cookieJar))
#opener = register_openers()
#opener.add_handler(request.HTTPCookieProcessor(self.cookieJar))
opener.addheaders = [('User-Agent', 'Mozilla/5.0'),("Referer","http://lixian.qq.com/main.html")]
request.install_opener(opener)

Expand Down Expand Up @@ -355,11 +356,15 @@ def __pushtor(self,url):
"""
上传torrent文件信息及添加BT任务
"""
from poster.encode import multipart_encode

data1,header1 = multipart_encode({"myfile":open(url)})
ireq = request.Request("http://lixian.qq.com/handler/bt_handler.php?cmd=readinfo",data1,header1)
torinfo = self.__request(ireq).encode("utf8").strip()
#from poster.encode import multipart_encode
import requests

urlv1 = "http://lixian.qq.com/handler/bt_handler.php?cmd=readinfo"
#data1,header1 = multipart_encode({"myfile":open(url)})
#ireq = request.Request("http://lixian.qq.com/handler/bt_handler.php?cmd=readinfo",data1,header1)
ireq = requests.post(urlv1,files={"myfile":open(url)})
#torinfo = self.__request(ireq.text).encode("utf8").strip()
torinfo = ireq.text.encode("utf8").strip()
torinfo = "{" + "{".join(torinfo.split("{")[1:])

torinfo = json.JSONDecoder().decode(torinfo)
Expand All @@ -373,8 +378,8 @@ def __pushtor(self,url):
for fileentry in torinfo["files"]:
try:
totalsize += fileentry["file_size_ori"]
except:
print ("torrent error!")
except Exception as e:
print ("torrent error!",e)
return False

aversize = totalsize / len(torinfo["files"])
Expand Down

0 comments on commit 496aca9

Please # to comment.