Browse Source

Update renamer to not trigger twice

Keep track of status support on releases
pull/2670/merge
Ruud 11 years ago
parent
commit
a408cc0246
  1. 4
      couchpotato/core/downloaders/base.py
  2. 1
      couchpotato/core/downloaders/blackhole/main.py
  3. 4
      couchpotato/core/downloaders/deluge/main.py
  4. 6
      couchpotato/core/downloaders/nzbget/main.py
  5. 1
      couchpotato/core/downloaders/pneumatic/main.py
  6. 4
      couchpotato/core/downloaders/rtorrent/main.py
  7. 4
      couchpotato/core/downloaders/sabnzbd/main.py
  8. 1
      couchpotato/core/downloaders/synology/main.py
  9. 4
      couchpotato/core/downloaders/transmission/main.py
  10. 73
      couchpotato/core/downloaders/utorrent/main.py
  11. 25
      couchpotato/core/plugins/renamer/main.py

4
couchpotato/core/downloaders/base.py

@ -13,6 +13,7 @@ class Downloader(Provider):
protocol = [] protocol = []
http_time_between_calls = 0 http_time_between_calls = 0
status_support = True
torrent_sources = [ torrent_sources = [
'http://torrage.com/torrent/%s.torrent', 'http://torrage.com/torrent/%s.torrent',
@ -69,7 +70,7 @@ class Downloader(Provider):
return return
def getAllDownloadStatus(self, ids): def getAllDownloadStatus(self, ids):
return return []
def _removeFailed(self, release_download): def _removeFailed(self, release_download):
if self.isDisabled(manual = True, data = {}): if self.isDisabled(manual = True, data = {}):
@ -133,6 +134,7 @@ class Downloader(Provider):
def downloadReturnId(self, download_id): def downloadReturnId(self, download_id):
return { return {
'downloader': self.getName(), 'downloader': self.getName(),
'status_support': self.status_support,
'id': download_id 'id': download_id
} }

1
couchpotato/core/downloaders/blackhole/main.py

@ -11,6 +11,7 @@ log = CPLog(__name__)
class Blackhole(Downloader): class Blackhole(Downloader):
protocol = ['nzb', 'torrent', 'torrent_magnet'] protocol = ['nzb', 'torrent', 'torrent_magnet']
status_support = False
def download(self, data = None, media = None, filedata = None): def download(self, data = None, media = None, filedata = None):
if not media: media = {} if not media: media = {}

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

@ -91,7 +91,7 @@ class Deluge(Downloader):
log.debug('Checking Deluge download status.') log.debug('Checking Deluge download status.')
if not self.connect(): if not self.connect():
return False return []
release_downloads = ReleaseDownloadList(self) release_downloads = ReleaseDownloadList(self)
@ -99,7 +99,7 @@ class Deluge(Downloader):
if not queue: if not queue:
log.debug('Nothing in queue or error') log.debug('Nothing in queue or error')
return False return []
for torrent_id in queue: for torrent_id in queue:
torrent = queue[torrent_id] torrent = queue[torrent_id]

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

@ -81,13 +81,13 @@ class NZBGet(Downloader):
log.info('Successfully connected to NZBGet, but unable to send a message') log.info('Successfully connected to NZBGet, but unable to send a message')
except socket.error: except socket.error:
log.error('NZBGet is not responding. Please ensure that NZBGet is running and host setting is correct.') log.error('NZBGet is not responding. Please ensure that NZBGet is running and host setting is correct.')
return False return []
except xmlrpclib.ProtocolError, e: except xmlrpclib.ProtocolError, e:
if e.errcode == 401: if e.errcode == 401:
log.error('Password is incorrect.') log.error('Password is incorrect.')
else: else:
log.error('Protocol Error: %s', e) log.error('Protocol Error: %s', e)
return False return []
# Get NZBGet data # Get NZBGet data
try: try:
@ -97,7 +97,7 @@ class NZBGet(Downloader):
history = rpc.history() history = rpc.history()
except: except:
log.error('Failed getting data: %s', traceback.format_exc(1)) log.error('Failed getting data: %s', traceback.format_exc(1))
return False return []
release_downloads = ReleaseDownloadList(self) release_downloads = ReleaseDownloadList(self)

1
couchpotato/core/downloaders/pneumatic/main.py

@ -11,6 +11,7 @@ class Pneumatic(Downloader):
protocol = ['nzb'] protocol = ['nzb']
strm_syntax = 'plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb=%s&nzbname=%s' strm_syntax = 'plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb=%s&nzbname=%s'
status_support = False
def download(self, data = None, media = None, filedata = None): def download(self, data = None, media = None, filedata = None):
if not media: media = {} if not media: media = {}

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

@ -147,7 +147,7 @@ class rTorrent(Downloader):
log.debug('Checking rTorrent download status.') log.debug('Checking rTorrent download status.')
if not self.connect(): if not self.connect():
return False return []
try: try:
torrents = self.rt.get_torrents() torrents = self.rt.get_torrents()
@ -182,7 +182,7 @@ class rTorrent(Downloader):
except Exception, err: except Exception, err:
log.error('Failed to get status from rTorrent: %s', err) log.error('Failed to get status from rTorrent: %s', err)
return False return []
def pause(self, release_download, pause = True): def pause(self, release_download, pause = True):
if not self.connect(): if not self.connect():

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

@ -75,7 +75,7 @@ class Sabnzbd(Downloader):
}) })
except: except:
log.error('Failed getting queue: %s', traceback.format_exc(1)) log.error('Failed getting queue: %s', traceback.format_exc(1))
return False return []
# Go through history items # Go through history items
try: try:
@ -85,7 +85,7 @@ class Sabnzbd(Downloader):
}) })
except: except:
log.error('Failed getting history json: %s', traceback.format_exc(1)) log.error('Failed getting history json: %s', traceback.format_exc(1))
return False return []
release_downloads = ReleaseDownloadList(self) release_downloads = ReleaseDownloadList(self)

1
couchpotato/core/downloaders/synology/main.py

@ -11,6 +11,7 @@ log = CPLog(__name__)
class Synology(Downloader): class Synology(Downloader):
protocol = ['nzb', 'torrent', 'torrent_magnet'] protocol = ['nzb', 'torrent', 'torrent_magnet']
status_support = False
def download(self, data = None, media = None, filedata = None): def download(self, data = None, media = None, filedata = None):
if not media: media = {} if not media: media = {}

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

@ -88,7 +88,7 @@ class Transmission(Downloader):
log.debug('Checking Transmission download status.') log.debug('Checking Transmission download status.')
if not self.connect(): if not self.connect():
return False return []
release_downloads = ReleaseDownloadList(self) release_downloads = ReleaseDownloadList(self)
@ -99,7 +99,7 @@ class Transmission(Downloader):
queue = self.trpc.get_alltorrents(return_params) queue = self.trpc.get_alltorrents(return_params)
if not (queue and queue.get('torrents')): if not (queue and queue.get('torrents')):
log.debug('Nothing in queue or error') log.debug('Nothing in queue or error')
return False return []
for torrent in queue['torrents']: for torrent in queue['torrents']:
if torrent['hashString'] in ids: if torrent['hashString'] in ids:

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

@ -24,6 +24,16 @@ class uTorrent(Downloader):
protocol = ['torrent', 'torrent_magnet'] protocol = ['torrent', 'torrent_magnet']
utorrent_api = None utorrent_api = None
status_flags = {
'STARTED' : 1,
'CHECKING' : 2,
'CHECK-START' : 4,
'CHECKED' : 8,
'ERROR' : 16,
'PAUSED' : 32,
'QUEUED' : 64,
'LOADED' : 128
}
def connect(self): def connect(self):
# Load host from config and split out port. # Load host from config and split out port.
@ -40,7 +50,7 @@ class uTorrent(Downloader):
if not media: media = {} if not media: media = {}
if not data: data = {} if not data: data = {}
log.debug('Sending "%s" (%s) to uTorrent.', (data.get('name'), data.get('protocol'))) log.debug("Sending '%s' (%s) to uTorrent.", (data.get('name'), data.get('protocol')))
if not self.connect(): if not self.connect():
return False return False
@ -75,7 +85,7 @@ class uTorrent(Downloader):
torrent_hash = re.findall('urn:btih:([\w]{32,40})', data.get('url'))[0].upper() torrent_hash = re.findall('urn:btih:([\w]{32,40})', data.get('url'))[0].upper()
torrent_params['trackers'] = '%0D%0A%0D%0A'.join(self.torrent_trackers) torrent_params['trackers'] = '%0D%0A%0D%0A'.join(self.torrent_trackers)
else: else:
info = bdecode(filedata)["info"] info = bdecode(filedata)['info']
torrent_hash = sha1(benc(info)).hexdigest().upper() torrent_hash = sha1(benc(info)).hexdigest().upper()
torrent_filename = self.createFileName(data, filedata, media) torrent_filename = self.createFileName(data, filedata, media)
@ -110,23 +120,23 @@ class uTorrent(Downloader):
log.debug('Checking uTorrent download status.') log.debug('Checking uTorrent download status.')
if not self.connect(): if not self.connect():
return False return []
release_downloads = ReleaseDownloadList(self) release_downloads = ReleaseDownloadList(self)
data = self.utorrent_api.get_status() data = self.utorrent_api.get_status()
if not data: if not data:
log.error('Error getting data from uTorrent') log.error('Error getting data from uTorrent')
return False return []
queue = json.loads(data) queue = json.loads(data)
if queue.get('error'): if queue.get('error'):
log.error('Error getting data from uTorrent: %s', queue.get('error')) log.error('Error getting data from uTorrent: %s', queue.get('error'))
return False return []
if not queue.get('torrents'): if not queue.get('torrents'):
log.debug('Nothing in queue') log.debug('Nothing in queue')
return False return []
# Get torrents # Get torrents
for torrent in queue['torrents']: for torrent in queue['torrents']:
@ -140,21 +150,10 @@ class uTorrent(Downloader):
except: except:
log.debug('Failed getting files from torrent: %s', torrent[2]) log.debug('Failed getting files from torrent: %s', torrent[2])
status_flags = {
"STARTED" : 1,
"CHECKING" : 2,
"CHECK-START" : 4,
"CHECKED" : 8,
"ERROR" : 16,
"PAUSED" : 32,
"QUEUED" : 64,
"LOADED" : 128
}
status = 'busy' status = 'busy'
if (torrent[1] & status_flags["STARTED"] or torrent[1] & status_flags["QUEUED"]) and torrent[4] == 1000: if (torrent[1] & self.status_flags['STARTED'] or torrent[1] & self.status_flags['QUEUED']) and torrent[4] == 1000:
status = 'seeding' status = 'seeding'
elif (torrent[1] & status_flags["ERROR"]): elif (torrent[1] & self.status_flags['ERROR']):
status = 'failed' status = 'failed'
elif torrent[4] == 1000: elif torrent[4] == 1000:
status = 'completed' status = 'completed'
@ -224,7 +223,7 @@ class uTorrentAPI(object):
if time.time() > self.last_time + 1800: if time.time() > self.last_time + 1800:
self.last_time = time.time() self.last_time = time.time()
self.token = self.get_token() self.token = self.get_token()
request = urllib2.Request(self.url + "?token=" + self.token + "&" + action, data) request = urllib2.Request(self.url + '?token=' + self.token + '&' + action, data)
try: try:
open_request = self.opener.open(request) open_request = self.opener.open(request)
response = open_request.read() response = open_request.read()
@ -244,52 +243,52 @@ class uTorrentAPI(object):
return False return False
def get_token(self): def get_token(self):
request = self.opener.open(self.url + "token.html") request = self.opener.open(self.url + 'token.html')
token = re.findall("<div.*?>(.*?)</", request.read())[0] token = re.findall('<div.*?>(.*?)</', request.read())[0]
return token return token
def add_torrent_uri(self, filename, torrent, add_folder = False): def add_torrent_uri(self, filename, torrent, add_folder = False):
action = "action=add-url&s=%s" % urllib.quote(torrent) action = 'action=add-url&s=%s' % urllib.quote(torrent)
if add_folder: if add_folder:
action += "&path=%s" % urllib.quote(filename) action += '&path=%s' % urllib.quote(filename)
return self._request(action) return self._request(action)
def add_torrent_file(self, filename, filedata, add_folder = False): def add_torrent_file(self, filename, filedata, add_folder = False):
action = "action=add-file" action = 'action=add-file'
if add_folder: if add_folder:
action += "&path=%s" % urllib.quote(filename) action += '&path=%s' % urllib.quote(filename)
return self._request(action, {"torrent_file": (ss(filename), filedata)}) return self._request(action, {'torrent_file': (ss(filename), filedata)})
def set_torrent(self, hash, params): def set_torrent(self, hash, params):
action = "action=setprops&hash=%s" % hash action = 'action=setprops&hash=%s' % hash
for k, v in params.iteritems(): for k, v in params.iteritems():
action += "&s=%s&v=%s" % (k, v) action += '&s=%s&v=%s' % (k, v)
return self._request(action) return self._request(action)
def pause_torrent(self, hash, pause = True): def pause_torrent(self, hash, pause = True):
if pause: if pause:
action = "action=pause&hash=%s" % hash action = 'action=pause&hash=%s' % hash
else: else:
action = "action=unpause&hash=%s" % hash action = 'action=unpause&hash=%s' % hash
return self._request(action) return self._request(action)
def stop_torrent(self, hash): def stop_torrent(self, hash):
action = "action=stop&hash=%s" % hash action = 'action=stop&hash=%s' % hash
return self._request(action) return self._request(action)
def remove_torrent(self, hash, remove_data = False): def remove_torrent(self, hash, remove_data = False):
if remove_data: if remove_data:
action = "action=removedata&hash=%s" % hash action = 'action=removedata&hash=%s' % hash
else: else:
action = "action=remove&hash=%s" % hash action = 'action=remove&hash=%s' % hash
return self._request(action) return self._request(action)
def get_status(self): def get_status(self):
action = "list=1" action = 'list=1'
return self._request(action) return self._request(action)
def get_settings(self): def get_settings(self):
action = "action=getsettings" action = 'action=getsettings'
settings_dict = {} settings_dict = {}
try: try:
utorrent_settings = json.loads(self._request(action)) utorrent_settings = json.loads(self._request(action))
@ -321,5 +320,5 @@ class uTorrentAPI(object):
return self._request(action) return self._request(action)
def get_files(self, hash): def get_files(self, hash):
action = "action=getfiles&hash=%s" % hash action = 'action=getfiles&hash=%s' % hash
return self._request(action) return self._request(action)

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

@ -163,7 +163,7 @@ class Renamer(Plugin):
# Make sure a checkSnatched marked all downloads/seeds as such # Make sure a checkSnatched marked all downloads/seeds as such
if not release_download and self.conf('run_every') > 0: if not release_download and self.conf('run_every') > 0:
fireEvent('renamer.check_snatched') self.checkSnatched(fire_scan = False)
self.renaming_started = True self.renaming_started = True
@ -809,7 +809,7 @@ Remove it if you want it to be renamed (again, or at least let it try again)
except: except:
loge('Couldn\'t remove empty directory %s: %s', (folder, traceback.format_exc())) loge('Couldn\'t remove empty directory %s: %s', (folder, traceback.format_exc()))
def checkSnatched(self): def checkSnatched(self, fire_scan = True):
if self.checking_snatched: if self.checking_snatched:
log.debug('Already checking snatched') log.debug('Already checking snatched')
@ -832,20 +832,29 @@ Remove it if you want it to be renamed (again, or at least let it try again)
# Collect all download information with the download IDs from the releases # Collect all download information with the download IDs from the releases
download_ids = [] download_ids = []
no_status_support = []
try: try:
for rel in rels: for rel in rels:
rel_dict = rel.to_dict({'info': {}}) rel_dict = rel.to_dict({'info': {}})
if rel_dict['info'].get('download_id') and rel_dict['info'].get('download_downloader'): if rel_dict['info'].get('download_id') and rel_dict['info'].get('download_downloader'):
download_ids.append({'id': rel_dict['info']['download_id'], 'downloader': rel_dict['info']['download_downloader']}) download_ids.append({'id': rel_dict['info']['download_id'], 'downloader': rel_dict['info']['download_downloader']})
ds = rel_dict['info'].get('download_status_support')
if ds == False or ds == 'False':
no_status_support.append(ss(rel_dict['info'].get('download_downloader')))
except: except:
log.error('Error getting download IDs from database') log.error('Error getting download IDs from database')
self.checking_snatched = False self.checking_snatched = False
return False return False
release_downloads = fireEvent('download.status', download_ids, merge = True) release_downloads = fireEvent('download.status', download_ids, merge = True) if download_ids else []
if len(no_status_support) > 0:
log.debug('Download status functionality is not implemented for one of the active downloaders: %s', no_status_support)
if not release_downloads: if not release_downloads:
log.debug('Download status functionality is not implemented for any active downloaders.') if fire_scan:
fireEvent('renamer.scan') self.scan()
self.checking_snatched = False self.checking_snatched = False
return True return True
@ -985,7 +994,7 @@ Remove it if you want it to be renamed (again, or at least let it try again)
if release_download['scan']: if release_download['scan']:
if release_download['pause'] and self.conf('file_action') == 'link': if release_download['pause'] and self.conf('file_action') == 'link':
fireEvent('download.pause', release_download = release_download, pause = True, single = True) fireEvent('download.pause', release_download = release_download, pause = True, single = True)
fireEvent('renamer.scan', release_download = release_download) self.scan(release_download = release_download)
if release_download['pause'] and self.conf('file_action') == 'link': if release_download['pause'] and self.conf('file_action') == 'link':
fireEvent('download.pause', release_download = release_download, pause = False, single = True) fireEvent('download.pause', release_download = release_download, pause = False, single = True)
if release_download['process_complete']: if release_download['process_complete']:
@ -996,8 +1005,8 @@ Remove it if you want it to be renamed (again, or at least let it try again)
# Ask the downloader to process the item # Ask the downloader to process the item
fireEvent('download.process_complete', release_download = release_download, single = True) fireEvent('download.process_complete', release_download = release_download, single = True)
if scan_required: if fire_scan and (scan_required or len(no_status_support) > 0):
fireEvent('renamer.scan') self.scan()
self.checking_snatched = False self.checking_snatched = False
return True return True

Loading…
Cancel
Save