Debug logging

This commit is contained in:
rembo10
2014-05-01 00:14:10 -07:00
parent 0c7ea8a5a0
commit e155f19d0d

View File

@@ -37,7 +37,7 @@ def addTorrent(link, title):
password = headphones.UTORRENT_PASSWORD
label = headphones.UTORRENT_LABEL
token = ''
logger.info("2")
if not host.startswith('http'):
host = 'http://' + host
@@ -52,18 +52,22 @@ def addTorrent(link, title):
# Retrieve session id
auth = (username, password) if username and password else None
token_request = request.request_response(host + 'token.html', auth=auth)
logger.info("3")
token = re.findall('<div.*?>(.*?)</', token_request.content)[0]
guid = token_request.cookies['GUID']
logger.info("4")
cookies = dict(GUID = guid)
logger.info("5")
if link.startswith("magnet") or link.startswith("http") or link.endswith(".torrent"):
logger.info("Adding link")
params = {'action':'add-url', 's':link, 'token':token}
response = request.request_json(host, params=params, auth=auth, cookies=cookies)
else:
method = "post"
logger.info("adding file")
params = {'action':'add-file', 'token':token}
files = {'torrent_file':{'music.torrent', link}}
response = request.request_json(host, method=method, params=params, files=files, auth=auth, cookies=cookies)
response = request.request_json(host, method="post", params=params, files=files, auth=auth, cookies=cookies)
if not response:
logger.error("Error sending torrent to uTorrent")
return