Browse Source

Provide IDs to check to all downloaders

pull/2545/head
mano3m 12 years ago
parent
commit
cff1b3abdb
  1. 11
      couchpotato/core/downloaders/base.py
  2. 3
      couchpotato/core/downloaders/deluge/main.py
  3. 11
      couchpotato/core/downloaders/nzbget/main.py
  4. 8
      couchpotato/core/downloaders/nzbvortex/main.py
  5. 3
      couchpotato/core/downloaders/rtorrent/main.py
  6. 5
      couchpotato/core/downloaders/sabnzbd/main.py
  7. 3
      couchpotato/core/downloaders/transmission/main.py
  8. 3
      couchpotato/core/downloaders/utorrent/main.py
  9. 15
      couchpotato/core/plugins/renamer/main.py

11
couchpotato/core/downloaders/base.py

@ -57,13 +57,18 @@ class Downloader(Provider):
return return
return self.download(data = data, media = media, filedata = filedata) return self.download(data = data, media = media, filedata = filedata)
def _getAllDownloadStatus(self): def _getAllDownloadStatus(self, download_ids):
if self.isDisabled(manual = True, data = {}): if self.isDisabled(manual = True, data = {}):
return return
return self.getAllDownloadStatus() ids = [download_id['id'] for download_id in download_ids if download_id['downloader'] == self.getName()]
def getAllDownloadStatus(self): if ids:
return self.getAllDownloadStatus(ids)
else:
return
def getAllDownloadStatus(self, ids):
return return
def _removeFailed(self, release_download): def _removeFailed(self, release_download):

3
couchpotato/core/downloaders/deluge/main.py

@ -86,7 +86,7 @@ class Deluge(Downloader):
log.info('Torrent sent to Deluge successfully.') log.info('Torrent sent to Deluge successfully.')
return self.downloadReturnId(remote_torrent) return self.downloadReturnId(remote_torrent)
def getAllDownloadStatus(self): def getAllDownloadStatus(self, ids):
log.debug('Checking Deluge download status.') log.debug('Checking Deluge download status.')
@ -103,6 +103,7 @@ class Deluge(Downloader):
for torrent_id in queue: for torrent_id in queue:
torrent = queue[torrent_id] torrent = queue[torrent_id]
if torrent['hash'] in ids:
log.debug('name=%s / id=%s / save_path=%s / move_completed_path=%s / hash=%s / progress=%s / state=%s / eta=%s / ratio=%s / stop_ratio=%s / is_seed=%s / is_finished=%s / paused=%s', (torrent['name'], torrent['hash'], torrent['save_path'], torrent['move_completed_path'], torrent['hash'], torrent['progress'], torrent['state'], torrent['eta'], torrent['ratio'], torrent['stop_ratio'], torrent['is_seed'], torrent['is_finished'], torrent['paused'])) log.debug('name=%s / id=%s / save_path=%s / move_completed_path=%s / hash=%s / progress=%s / state=%s / eta=%s / ratio=%s / stop_ratio=%s / is_seed=%s / is_finished=%s / paused=%s', (torrent['name'], torrent['hash'], torrent['save_path'], torrent['move_completed_path'], torrent['hash'], torrent['progress'], torrent['state'], torrent['eta'], torrent['ratio'], torrent['stop_ratio'], torrent['is_seed'], torrent['is_finished'], torrent['paused']))
# Deluge has no easy way to work out if a torrent is stalled or failing. # Deluge has no easy way to work out if a torrent is stalled or failing.

11
couchpotato/core/downloaders/nzbget/main.py

@ -67,7 +67,7 @@ class NZBGet(Downloader):
log.error('NZBGet could not add %s to the queue.', nzb_name) log.error('NZBGet could not add %s to the queue.', nzb_name)
return False return False
def getAllDownloadStatus(self): def getAllDownloadStatus(self, ids):
log.debug('Checking NZBGet download status.') log.debug('Checking NZBGet download status.')
@ -102,13 +102,13 @@ class NZBGet(Downloader):
release_downloads = ReleaseDownloadList(self) release_downloads = ReleaseDownloadList(self)
for nzb in groups: for nzb in groups:
log.debug('Found %s in NZBGet download queue', nzb['NZBFilename'])
try: try:
nzb_id = [param['Value'] for param in nzb['Parameters'] if param['Name'] == 'couchpotato'][0] nzb_id = [param['Value'] for param in nzb['Parameters'] if param['Name'] == 'couchpotato'][0]
except: except:
nzb_id = nzb['NZBID'] nzb_id = nzb['NZBID']
if nzb_id in ids:
log.debug('Found %s in NZBGet download queue', nzb['NZBFilename'])
timeleft = -1 timeleft = -1
try: try:
if nzb['ActiveDownloads'] > 0 and nzb['DownloadRate'] > 0 and not (status['DownloadPaused'] or status['Download2Paused']): if nzb['ActiveDownloads'] > 0 and nzb['DownloadRate'] > 0 and not (status['DownloadPaused'] or status['Download2Paused']):
@ -125,6 +125,7 @@ class NZBGet(Downloader):
}) })
for nzb in queue: # 'Parameters' is not passed in rpc.postqueue for nzb in queue: # 'Parameters' is not passed in rpc.postqueue
if nzb['NZBID'] in ids:
log.debug('Found %s in NZBGet postprocessing queue', nzb['NZBFilename']) log.debug('Found %s in NZBGet postprocessing queue', nzb['NZBFilename'])
release_downloads.append({ release_downloads.append({
'id': nzb['NZBID'], 'id': nzb['NZBID'],
@ -134,11 +135,13 @@ class NZBGet(Downloader):
}) })
for nzb in history: for nzb in history:
log.debug('Found %s in NZBGet history. ParStatus: %s, ScriptStatus: %s, Log: %s', (nzb['NZBFilename'] , nzb['ParStatus'], nzb['ScriptStatus'] , nzb['Log']))
try: try:
nzb_id = [param['Value'] for param in nzb['Parameters'] if param['Name'] == 'couchpotato'][0] nzb_id = [param['Value'] for param in nzb['Parameters'] if param['Name'] == 'couchpotato'][0]
except: except:
nzb_id = nzb['NZBID'] nzb_id = nzb['NZBID']
if nzb_id in ids:
log.debug('Found %s in NZBGet history. ParStatus: %s, ScriptStatus: %s, Log: %s', (nzb['NZBFilename'] , nzb['ParStatus'], nzb['ScriptStatus'] , nzb['Log']))
release_downloads.append({ release_downloads.append({
'id': nzb_id, 'id': nzb_id,
'name': nzb['NZBFilename'], 'name': nzb['NZBFilename'],

8
couchpotato/core/downloaders/nzbvortex/main.py

@ -8,9 +8,11 @@ from uuid import uuid4
import hashlib import hashlib
import httplib import httplib
import json import json
import os
import socket import socket
import ssl import ssl
import sys import sys
import time
import traceback import traceback
import urllib2 import urllib2
@ -32,19 +34,21 @@ class NZBVortex(Downloader):
nzb_filename = self.createFileName(data, filedata, media) nzb_filename = self.createFileName(data, filedata, media)
self.call('nzb/add', params = {'file': (nzb_filename, filedata)}, multipart = True) self.call('nzb/add', params = {'file': (nzb_filename, filedata)}, multipart = True)
time.sleep(10)
raw_statuses = self.call('nzb') raw_statuses = self.call('nzb')
nzb_id = [nzb['id'] for nzb in raw_statuses.get('nzbs', []) if nzb['name'] == nzb_filename][0] nzb_id = [nzb['id'] for nzb in raw_statuses.get('nzbs', []) if os.path.basename(item['nzbFileName']) == nzb_filename][0]
return self.downloadReturnId(nzb_id) return self.downloadReturnId(nzb_id)
except: except:
log.error('Something went wrong sending the NZB file: %s', traceback.format_exc()) log.error('Something went wrong sending the NZB file: %s', traceback.format_exc())
return False return False
def getAllDownloadStatus(self): def getAllDownloadStatus(self, ids):
raw_statuses = self.call('nzb') raw_statuses = self.call('nzb')
release_downloads = ReleaseDownloadList(self) release_downloads = ReleaseDownloadList(self)
for nzb in raw_statuses.get('nzbs', []): for nzb in raw_statuses.get('nzbs', []):
if nzb['id'] in ids:
# Check status # Check status
status = 'busy' status = 'busy'

3
couchpotato/core/downloaders/rtorrent/main.py

@ -143,7 +143,7 @@ class rTorrent(Downloader):
log.error('Failed to send torrent to rTorrent: %s', err) log.error('Failed to send torrent to rTorrent: %s', err)
return False return False
def getAllDownloadStatus(self): def getAllDownloadStatus(self, ids):
log.debug('Checking rTorrent download status.') log.debug('Checking rTorrent download status.')
if not self.connect(): if not self.connect():
@ -155,6 +155,7 @@ class rTorrent(Downloader):
release_downloads = ReleaseDownloadList(self) release_downloads = ReleaseDownloadList(self)
for torrent in torrents: for torrent in torrents:
if torrent.info_hash in ids:
torrent_files = [] torrent_files = []
for file_item in torrent.get_files(): for file_item in torrent.get_files():
torrent_files.append(sp(os.path.join(torrent.directory, file_item.path))) torrent_files.append(sp(os.path.join(torrent.directory, file_item.path)))

5
couchpotato/core/downloaders/sabnzbd/main.py

@ -64,7 +64,7 @@ class Sabnzbd(Downloader):
log.error('Error getting data from SABNZBd: %s', sab_data) log.error('Error getting data from SABNZBd: %s', sab_data)
return False return False
def getAllDownloadStatus(self): def getAllDownloadStatus(self, ids):
log.debug('Checking SABnzbd download status.') log.debug('Checking SABnzbd download status.')
@ -91,6 +91,7 @@ class Sabnzbd(Downloader):
# Get busy releases # Get busy releases
for nzb in queue.get('slots', []): for nzb in queue.get('slots', []):
if nzb['nzo_id'] in ids:
status = 'busy' status = 'busy'
if 'ENCRYPTED / ' in nzb['filename']: if 'ENCRYPTED / ' in nzb['filename']:
status = 'failed' status = 'failed'
@ -105,7 +106,7 @@ class Sabnzbd(Downloader):
# Get old releases # Get old releases
for nzb in history.get('slots', []): for nzb in history.get('slots', []):
if nzb['nzo_id'] in ids:
status = 'busy' status = 'busy'
if nzb['status'] == 'Failed' or (nzb['status'] == 'Completed' and nzb['fail_message'].strip()): if nzb['status'] == 'Failed' or (nzb['status'] == 'Completed' and nzb['fail_message'].strip()):
status = 'failed' status = 'failed'

3
couchpotato/core/downloaders/transmission/main.py

@ -83,7 +83,7 @@ class Transmission(Downloader):
log.info('Torrent sent to Transmission successfully.') log.info('Torrent sent to Transmission successfully.')
return self.downloadReturnId(remote_torrent['torrent-added']['hashString']) return self.downloadReturnId(remote_torrent['torrent-added']['hashString'])
def getAllDownloadStatus(self): def getAllDownloadStatus(self, ids):
log.debug('Checking Transmission download status.') log.debug('Checking Transmission download status.')
@ -102,6 +102,7 @@ class Transmission(Downloader):
return False return False
for torrent in queue['torrents']: for torrent in queue['torrents']:
if torrent['hashString'] in ids:
log.debug('name=%s / id=%s / downloadDir=%s / hashString=%s / percentDone=%s / status=%s / eta=%s / uploadRatio=%s / isFinished=%s', log.debug('name=%s / id=%s / downloadDir=%s / hashString=%s / percentDone=%s / status=%s / eta=%s / uploadRatio=%s / isFinished=%s',
(torrent['name'], torrent['id'], torrent['downloadDir'], torrent['hashString'], torrent['percentDone'], torrent['status'], torrent['eta'], torrent['uploadRatio'], torrent['isFinished'])) (torrent['name'], torrent['id'], torrent['downloadDir'], torrent['hashString'], torrent['percentDone'], torrent['status'], torrent['eta'], torrent['uploadRatio'], torrent['isFinished']))

3
couchpotato/core/downloaders/utorrent/main.py

@ -105,7 +105,7 @@ class uTorrent(Downloader):
return self.downloadReturnId(torrent_hash) return self.downloadReturnId(torrent_hash)
def getAllDownloadStatus(self): def getAllDownloadStatus(self, ids):
log.debug('Checking uTorrent download status.') log.debug('Checking uTorrent download status.')
@ -130,6 +130,7 @@ class uTorrent(Downloader):
# Get torrents # Get torrents
for torrent in queue['torrents']: for torrent in queue['torrents']:
if torrent[0] in ids:
#Get files of the torrent #Get files of the torrent
torrent_files = [] torrent_files = []

15
couchpotato/core/plugins/renamer/main.py

@ -811,9 +811,20 @@ Remove it if you want it to be renamed (again, or at least let it try again)
self.checking_snatched = False self.checking_snatched = False
return True return True
release_downloads = fireEvent('download.status', merge = True) # Collect all download information with the download IDs from the releases
download_ids = []
try:
for rel in rels:
rel_dict = rel.to_dict({'info': {}})
if rel_dict['info'].get('download_id'):
download_ids.append({'id': rel_dict['info']['download_id'], 'downloader': rel_dict['info']['download_downloader']})
except:
log.error('Error getting download IDs from database')
return False
release_downloads = fireEvent('download.status', download_ids, merge = True)
if not release_downloads: if not release_downloads:
log.debug('Download status functionality is not implemented for active downloaders.') log.debug('Download status functionality is not implemented for any active downloaders.')
fireEvent('renamer.scan') fireEvent('renamer.scan')
self.checking_snatched = False self.checking_snatched = False

Loading…
Cancel
Save