mirror of
https://github.com/rembo10/headphones.git
synced 2026-04-05 04:29:25 +01:00
Slowly making progress
This commit is contained in:
@@ -696,6 +696,35 @@ def send_to_downloader(data, bestqual, album):
|
||||
except Exception, e:
|
||||
logger.exception("Unhandled exception")
|
||||
|
||||
else:
|
||||
logger.info("Sending torrent to uTorrent")
|
||||
|
||||
# rutracker needs cookies to be set, pass the .torrent file instead of url
|
||||
if bestqual[3] == 'rutracker.org':
|
||||
file_or_url = rutracker.get_torrent(bestqual[2])
|
||||
else:
|
||||
file_or_url = bestqual[2]
|
||||
|
||||
torrentid = utorrent.addTorrent(file_or_url)
|
||||
|
||||
if not torrentid:
|
||||
logger.error("Error sending torrent to uTorrent. Are you sure it's running?")
|
||||
return
|
||||
|
||||
folder_name = utorrent.getTorrentFolder(torrentid)
|
||||
if folder_name:
|
||||
logger.info('Torrent folder name: %s' % folder_name)
|
||||
else:
|
||||
logger.error('Torrent folder name could not be determined')
|
||||
return
|
||||
|
||||
# remove temp .torrent file created above
|
||||
if bestqual[3] == 'rutracker.org':
|
||||
try:
|
||||
shutil.rmtree(os.path.split(file_or_url)[0])
|
||||
except Exception, e:
|
||||
logger.exception("Unhandled exception")
|
||||
|
||||
myDB = db.DBConnection()
|
||||
myDB.action('UPDATE albums SET status = "Snatched" WHERE AlbumID=?', [album['AlbumID']])
|
||||
myDB.action('INSERT INTO snatched VALUES( ?, ?, ?, ?, DATETIME("NOW", "localtime"), ?, ?, ?)', [album['AlbumID'], bestqual[0], bestqual[1], bestqual[2], "Snatched", folder_name, kind])
|
||||
|
||||
@@ -29,14 +29,23 @@ from headphones import logger, notifiers, request
|
||||
# Store torrent id so we can check up on it
|
||||
|
||||
def addTorrent(link):
|
||||
method = 'torrent-add'
|
||||
arguments = {'filename': link, 'download-dir': headphones.DOWNLOAD_TORRENT_DIR}
|
||||
|
||||
response = torrentAction(method,arguments)
|
||||
if link.startswith("magnet") or link.startswith("http") or link.endswith(".torrent"):
|
||||
method = None
|
||||
params = {'action':'add-url', 's':link}
|
||||
files = None
|
||||
else:
|
||||
method = "post"
|
||||
params = {'action':'add-file'}
|
||||
files = {'torrent_file':{'music.torrent', link}}
|
||||
|
||||
response = torrentAction(method,params,files)
|
||||
|
||||
if not response:
|
||||
return False
|
||||
|
||||
print response
|
||||
|
||||
if response['result'] == 'success':
|
||||
if 'torrent-added' in response['arguments']:
|
||||
name = response['arguments']['torrent-added']['name']
|
||||
@@ -75,7 +84,7 @@ def getTorrentFolder(torrentid):
|
||||
|
||||
return torrent_folder_name
|
||||
|
||||
def torrentAction(method, arguments):
|
||||
def torrentAction(method=None, params=None, files=None):
|
||||
|
||||
host = headphones.UTORRENT_HOST
|
||||
username = headphones.UTORRENT_USERNAME
|
||||
@@ -98,12 +107,10 @@ def torrentAction(method, arguments):
|
||||
token_request = request.request_response(host + 'token.html')
|
||||
token = re.findall('<div.*?>(.*?)</', request.read())[0]
|
||||
|
||||
data = { 'method': method, 'arguments': arguments }
|
||||
|
||||
response = request.request_json(host, method="post", data=json.dumps(data), headers=headers, auth=auth)
|
||||
response = request.request_json(host, method=method, params=params, files=files, auth=auth)
|
||||
|
||||
if not response:
|
||||
logger.error("Error sending torrent to Transmission")
|
||||
logger.error("Error sending torrent to uTorrent")
|
||||
return
|
||||
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user