Merge pull request #2545 from mano3m/develop_downloaders

Downloader and renamer improvements
This commit is contained in:
Joel Kåberg committed 2013-12-14 14:20:33 -08:00
commit 3b0e07100f
15 files changed
+410 -349

No files matched your search

+8 -3
View File
@@ -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):
@@ -51,10 +51,10 @@ class Blackhole(Downloader):
with open(full_path, 'wb') as f: with open(full_path, 'wb') as f:
f.write(filedata) f.write(filedata)
os.chmod(full_path, Env.getPermission('file')) os.chmod(full_path, Env.getPermission('file'))
return True return self.downloadReturnId('')
else: else:
log.info('File %s already exists.', full_path) log.info('File %s already exists.', full_path)
return True return self.downloadReturnId('')
except: except:
log.error('Failed to download to blackhole %s', traceback.format_exc()) log.error('Failed to download to blackhole %s', traceback.format_exc())
+30 -29
View File
@@ -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,38 +103,39 @@ class Deluge(Downloader):
for torrent_id in queue: for torrent_id in queue:
torrent = queue[torrent_id] torrent = queue[torrent_id]
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'])) 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']))
# 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.
#status = 'failed' #status = 'failed'
status = 'busy' status = 'busy'
if torrent['is_seed'] and tryFloat(torrent['ratio']) < tryFloat(torrent['stop_ratio']): if torrent['is_seed'] and tryFloat(torrent['ratio']) < tryFloat(torrent['stop_ratio']):
# We have torrent['seeding_time'] to work out what the seeding time is, but we do not # We have torrent['seeding_time'] to work out what the seeding time is, but we do not
# have access to the downloader seed_time, as with deluge we have no way to pass it # have access to the downloader seed_time, as with deluge we have no way to pass it
# when the torrent is added. So Deluge will only look at the ratio. # when the torrent is added. So Deluge will only look at the ratio.
# See above comment in download(). # See above comment in download().
status = 'seeding' status = 'seeding'
elif torrent['is_seed'] and torrent['is_finished'] and torrent['paused'] and torrent['state'] == 'Paused': elif torrent['is_seed'] and torrent['is_finished'] and torrent['paused'] and torrent['state'] == 'Paused':
status = 'completed' status = 'completed'
download_dir = sp(torrent['save_path']) download_dir = sp(torrent['save_path'])
if torrent['move_on_completed']: if torrent['move_on_completed']:
download_dir = torrent['move_completed_path'] download_dir = torrent['move_completed_path']
torrent_files = [] torrent_files = []
for file_item in torrent['files']: for file_item in torrent['files']:
torrent_files.append(sp(os.path.join(download_dir, file_item['path']))) torrent_files.append(sp(os.path.join(download_dir, file_item['path'])))
release_downloads.append({ release_downloads.append({
'id': torrent['hash'], 'id': torrent['hash'],
'name': torrent['name'], 'name': torrent['name'],
'status': status, 'status': status,
'original_status': torrent['state'], 'original_status': torrent['state'],
'seed_ratio': torrent['ratio'], 'seed_ratio': torrent['ratio'],
'timeleft': str(timedelta(seconds = torrent['eta'])), 'timeleft': str(timedelta(seconds = torrent['eta'])),
'folder': sp(download_dir if len(torrent_files) == 1 else os.path.join(download_dir, torrent['name'])), 'folder': sp(download_dir if len(torrent_files) == 1 else os.path.join(download_dir, torrent['name'])),
'files': '|'.join(torrent_files), 'files': '|'.join(torrent_files),
}) })
return release_downloads return release_downloads
+35 -32
View File
@@ -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,51 +102,54 @@ 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
try:
if nzb['ActiveDownloads'] > 0 and nzb['DownloadRate'] > 0 and not (status['DownloadPaused'] or status['Download2Paused']):
timeleft = str(timedelta(seconds = nzb['RemainingSizeMB'] / status['DownloadRate'] * 2 ^ 20))
except:
pass
timeleft = -1 release_downloads.append({
try: 'id': nzb_id,
if nzb['ActiveDownloads'] > 0 and nzb['DownloadRate'] > 0 and not (status['DownloadPaused'] or status['Download2Paused']): 'name': nzb['NZBFilename'],
timeleft = str(timedelta(seconds = nzb['RemainingSizeMB'] / status['DownloadRate'] * 2 ^ 20)) 'original_status': 'DOWNLOADING' if nzb['ActiveDownloads'] > 0 else 'QUEUED',
except: # Seems to have no native API function for time left. This will return the time left after NZBGet started downloading this item
pass 'timeleft': timeleft,
})
release_downloads.append({
'id': nzb_id,
'name': nzb['NZBFilename'],
'original_status': 'DOWNLOADING' if nzb['ActiveDownloads'] > 0 else 'QUEUED',
# Seems to have no native API function for time left. This will return the time left after NZBGet started downloading this item
'timeleft': timeleft,
})
for nzb in queue: # 'Parameters' is not passed in rpc.postqueue for nzb in queue: # 'Parameters' is not passed in rpc.postqueue
log.debug('Found %s in NZBGet postprocessing queue', nzb['NZBFilename']) if nzb['NZBID'] in ids:
release_downloads.append({ log.debug('Found %s in NZBGet postprocessing queue', nzb['NZBFilename'])
'id': nzb['NZBID'], release_downloads.append({
'name': nzb['NZBFilename'], 'id': nzb['NZBID'],
'original_status': nzb['Stage'], 'name': nzb['NZBFilename'],
'timeleft': str(timedelta(seconds = 0)) if not status['PostPaused'] else -1, 'original_status': nzb['Stage'],
}) 'timeleft': str(timedelta(seconds = 0)) if not status['PostPaused'] else -1,
})
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']
release_downloads.append({
'id': nzb_id, if nzb_id in ids:
'name': nzb['NZBFilename'], log.debug('Found %s in NZBGet history. ParStatus: %s, ScriptStatus: %s, Log: %s', (nzb['NZBFilename'] , nzb['ParStatus'], nzb['ScriptStatus'] , nzb['Log']))
'status': 'completed' if nzb['ParStatus'] in ['SUCCESS', 'NONE'] and nzb['ScriptStatus'] in ['SUCCESS', 'NONE'] else 'failed', release_downloads.append({
'original_status': nzb['ParStatus'] + ', ' + nzb['ScriptStatus'], 'id': nzb_id,
'timeleft': str(timedelta(seconds = 0)), 'name': nzb['NZBFilename'],
'folder': sp(nzb['DestDir']) 'status': 'completed' if nzb['ParStatus'] in ['SUCCESS', 'NONE'] and nzb['ScriptStatus'] in ['SUCCESS', 'NONE'] else 'failed',
}) 'original_status': nzb['ParStatus'] + ', ' + nzb['ScriptStatus'],
'timeleft': str(timedelta(seconds = 0)),
'folder': sp(nzb['DestDir'])
})
return release_downloads return release_downloads
+20 -16
View File
@@ -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,35 +34,37 @@ 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'
if nzb['state'] == 20: if nzb['state'] == 20:
status = 'completed' status = 'completed'
elif nzb['state'] in [21, 22, 24]: elif nzb['state'] in [21, 22, 24]:
status = 'failed' status = 'failed'
release_downloads.append({ release_downloads.append({
'id': nzb['id'], 'id': nzb['id'],
'name': nzb['uiTitle'], 'name': nzb['uiTitle'],
'status': status, 'status': status,
'original_status': nzb['state'], 'original_status': nzb['state'],
'timeleft':-1, 'timeleft':-1,
'folder': sp(nzb['destinationPath']), 'folder': sp(nzb['destinationPath']),
}) })
return release_downloads return release_downloads
@@ -41,11 +41,11 @@ class Pneumatic(Downloader):
strm_file.write(strmContent) strm_file.write(strmContent)
strm_file.close() strm_file.close()
return True return self.downloadReturnId('')
else: else:
log.info('File %s already exists.', fullPath) log.info('File %s already exists.', fullPath)
return True return self.downloadReturnId('')
except: except:
log.error('Failed to download .strm: %s', traceback.format_exc()) log.error('Failed to download .strm: %s', traceback.format_exc())
+21 -20
View File
@@ -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,27 +155,28 @@ class rTorrent(Downloader):
release_downloads = ReleaseDownloadList(self) release_downloads = ReleaseDownloadList(self)
for torrent in torrents: for torrent in torrents:
torrent_files = [] if torrent.info_hash in ids:
for file_item in torrent.get_files(): torrent_files = []
torrent_files.append(sp(os.path.join(torrent.directory, file_item.path))) for file_item in torrent.get_files():
torrent_files.append(sp(os.path.join(torrent.directory, file_item.path)))
status = 'busy' status = 'busy'
if torrent.complete: if torrent.complete:
if torrent.active: if torrent.active:
status = 'seeding' status = 'seeding'
else: else:
status = 'completed' status = 'completed'
release_downloads.append({ release_downloads.append({
'id': torrent.info_hash, 'id': torrent.info_hash,
'name': torrent.name, 'name': torrent.name,
'status': status, 'status': status,
'seed_ratio': torrent.ratio, 'seed_ratio': torrent.ratio,
'original_status': torrent.state, 'original_status': torrent.state,
'timeleft': str(timedelta(seconds = float(torrent.left_bytes) / torrent.down_rate)) if torrent.down_rate > 0 else -1, 'timeleft': str(timedelta(seconds = float(torrent.left_bytes) / torrent.down_rate)) if torrent.down_rate > 0 else -1,
'folder': sp(torrent.directory), 'folder': sp(torrent.directory),
'files': '|'.join(torrent_files) 'files': '|'.join(torrent_files)
}) })
return release_downloads return release_downloads
+26 -25
View File
@@ -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,35 +91,36 @@ class Sabnzbd(Downloader):
# Get busy releases # Get busy releases
for nzb in queue.get('slots', []): for nzb in queue.get('slots', []):
status = 'busy' if nzb['nzo_id'] in ids:
if 'ENCRYPTED / ' in nzb['filename']: status = 'busy'
status = 'failed' if 'ENCRYPTED / ' in nzb['filename']:
status = 'failed'
release_downloads.append({ release_downloads.append({
'id': nzb['nzo_id'], 'id': nzb['nzo_id'],
'name': nzb['filename'], 'name': nzb['filename'],
'status': status, 'status': status,
'original_status': nzb['status'], 'original_status': nzb['status'],
'timeleft': nzb['timeleft'] if not queue['paused'] else -1, 'timeleft': nzb['timeleft'] if not queue['paused'] else -1,
}) })
# 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'
if nzb['status'] == 'Failed' or (nzb['status'] == 'Completed' and nzb['fail_message'].strip()):
status = 'failed'
elif nzb['status'] == 'Completed':
status = 'completed'
status = 'busy' release_downloads.append({
if nzb['status'] == 'Failed' or (nzb['status'] == 'Completed' and nzb['fail_message'].strip()): 'id': nzb['nzo_id'],
status = 'failed' 'name': nzb['name'],
elif nzb['status'] == 'Completed': 'status': status,
status = 'completed' 'original_status': nzb['status'],
'timeleft': str(timedelta(seconds = 0)),
release_downloads.append({ 'folder': sp(os.path.dirname(nzb['storage']) if os.path.isfile(nzb['storage']) else nzb['storage']),
'id': nzb['nzo_id'], })
'name': nzb['name'],
'status': status,
'original_status': nzb['status'],
'timeleft': str(timedelta(seconds = 0)),
'folder': sp(os.path.dirname(nzb['storage']) if os.path.isfile(nzb['storage']) else nzb['storage']),
})
return release_downloads return release_downloads
@@ -42,7 +42,7 @@ class Synology(Downloader):
except: except:
log.error('Exception while adding torrent: %s', traceback.format_exc()) log.error('Exception while adding torrent: %s', traceback.format_exc())
finally: finally:
return response return self.downloadReturnId('') if response else False
def getEnabledProtocol(self): def getEnabledProtocol(self):
if self.conf('use_for') == 'both': if self.conf('use_for') == 'both':
@@ -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,31 +102,32 @@ class Transmission(Downloader):
return False return False
for torrent in queue['torrents']: for torrent in queue['torrents']:
log.debug('name=%s / id=%s / downloadDir=%s / hashString=%s / percentDone=%s / status=%s / eta=%s / uploadRatio=%s / isFinished=%s', if torrent['hashString'] in ids:
(torrent['name'], torrent['id'], torrent['downloadDir'], torrent['hashString'], torrent['percentDone'], torrent['status'], torrent['eta'], torrent['uploadRatio'], torrent['isFinished'])) 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_files = [] torrent_files = []
for file_item in torrent['files']: for file_item in torrent['files']:
torrent_files.append(sp(os.path.join(torrent['downloadDir'], file_item['name']))) torrent_files.append(sp(os.path.join(torrent['downloadDir'], file_item['name'])))
status = 'busy' status = 'busy'
if torrent.get('isStalled') and self.conf('stalled_as_failed'): if torrent.get('isStalled') and self.conf('stalled_as_failed'):
status = 'failed' status = 'failed'
elif torrent['status'] == 0 and torrent['percentDone'] == 1: elif torrent['status'] == 0 and torrent['percentDone'] == 1:
status = 'completed' status = 'completed'
elif torrent['status'] in [5, 6]: elif torrent['status'] in [5, 6]:
status = 'seeding' status = 'seeding'
release_downloads.append({ release_downloads.append({
'id': torrent['hashString'], 'id': torrent['hashString'],
'name': torrent['name'], 'name': torrent['name'],
'status': status, 'status': status,
'original_status': torrent['status'], 'original_status': torrent['status'],
'seed_ratio': torrent['uploadRatio'], 'seed_ratio': torrent['uploadRatio'],
'timeleft': str(timedelta(seconds = torrent['eta'])), 'timeleft': str(timedelta(seconds = torrent['eta'])),
'folder': sp(torrent['downloadDir'] if len(torrent_files) == 1 else os.path.join(torrent['downloadDir'], torrent['name'])), 'folder': sp(torrent['downloadDir'] if len(torrent_files) == 1 else os.path.join(torrent['downloadDir'], torrent['name'])),
'files': '|'.join(torrent_files) 'files': '|'.join(torrent_files)
}) })
return release_downloads return release_downloads
+38 -37
View File
@@ -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,47 +130,48 @@ 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 = []
try: try:
torrent_files = json.loads(self.utorrent_api.get_files(torrent[0])) torrent_files = json.loads(self.utorrent_api.get_files(torrent[0]))
torrent_files = [sp(os.path.join(torrent[26], torrent_file[0])) for torrent_file in torrent_files['files'][1]] torrent_files = [sp(os.path.join(torrent[26], torrent_file[0])) for torrent_file in torrent_files['files'][1]]
except: except:
log.debug('Failed getting files from torrent: %s', torrent[2]) log.debug('Failed getting files from torrent: %s', torrent[2])
status_flags = { status_flags = {
"STARTED" : 1, "STARTED" : 1,
"CHECKING" : 2, "CHECKING" : 2,
"CHECK-START" : 4, "CHECK-START" : 4,
"CHECKED" : 8, "CHECKED" : 8,
"ERROR" : 16, "ERROR" : 16,
"PAUSED" : 32, "PAUSED" : 32,
"QUEUED" : 64, "QUEUED" : 64,
"LOADED" : 128 "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] & status_flags["STARTED"] or torrent[1] & status_flags["QUEUED"]) and torrent[4] == 1000:
status = 'seeding' status = 'seeding'
elif (torrent[1] & status_flags["ERROR"]): elif (torrent[1] & status_flags["ERROR"]):
status = 'failed' status = 'failed'
elif torrent[4] == 1000: elif torrent[4] == 1000:
status = 'completed' status = 'completed'
if not status == 'busy': if not status == 'busy':
self.removeReadOnly(torrent_files) self.removeReadOnly(torrent_files)
release_downloads.append({ release_downloads.append({
'id': torrent[0], 'id': torrent[0],
'name': torrent[2], 'name': torrent[2],
'status': status, 'status': status,
'seed_ratio': float(torrent[7]) / 1000, 'seed_ratio': float(torrent[7]) / 1000,
'original_status': torrent[1], 'original_status': torrent[1],
'timeleft': str(timedelta(seconds = torrent[10])), 'timeleft': str(timedelta(seconds = torrent[10])),
'folder': sp(torrent[26]), 'folder': sp(torrent[26]),
'files': '|'.join(torrent_files) 'files': '|'.join(torrent_files)
}) })
return release_downloads return release_downloads
+4
View File
@@ -54,6 +54,10 @@ def sp(path, *args):
if not path or len(path) == 0: if not path or len(path) == 0:
return path return path
# convert windows path (from remote box) to *nix path
if os.path.sep == '/' and '\\' in path:
path = '/' + path.replace(':', '').replace('\\', '/')
path = os.path.normcase(os.path.normpath(ss(path, *args))) path = os.path.normcase(os.path.normpath(ss(path, *args)))
if path != os.path.sep: if path != os.path.sep:
+3 -5
View File
@@ -1,6 +1,6 @@
from couchpotato.api import addApiView from couchpotato.api import addApiView
from couchpotato.core.event import fireEvent, addEvent, fireEventAsync from couchpotato.core.event import fireEvent, addEvent, fireEventAsync
from couchpotato.core.helpers.encoding import ss from couchpotato.core.helpers.encoding import sp
from couchpotato.core.helpers.variable import splitString, getTitle from couchpotato.core.helpers.variable import splitString, getTitle
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin from couchpotato.core.plugins.base import Plugin
@@ -122,12 +122,10 @@ class Manage(Plugin):
releases = fireEvent('release.for_movie', id = done_movie.get('id'), single = True) releases = fireEvent('release.for_movie', id = done_movie.get('id'), single = True)
for release in releases: for release in releases:
if len(release.get('files', [])) == 0: if len(release.get('files', [])) > 0:
fireEvent('release.delete', release['id'])
else:
for release_file in release.get('files', []): for release_file in release.get('files', []):
# Remove release not available anymore # Remove release not available anymore
if not os.path.isfile(ss(release_file['path'])): if not os.path.isfile(sp(release_file['path'])):
fireEvent('release.clean', release['id']) fireEvent('release.clean', release['id'])
break break
+1 -1
View File
@@ -288,7 +288,7 @@ class Release(Plugin):
value = toUnicode(download_result.get(key)) value = toUnicode(download_result.get(key))
) )
rls.info.append(rls_info) rls.info.append(rls_info)
db.commit() db.commit()
log_movie = '%s (%s) in %s' % (getTitle(media['library']), media['library']['year'], rls.quality.label) log_movie = '%s (%s) in %s' % (getTitle(media['library']), media['library']['year'], rls.quality.label)
snatch_message = 'Snatched "%s": %s' % (data.get('name'), log_movie) snatch_message = 'Snatched "%s": %s' % (data.get('name'), log_movie)
+195 -153
View File
@@ -30,10 +30,10 @@ class Renamer(Plugin):
'desc': 'For the renamer to check for new files to rename in a folder', 'desc': 'For the renamer to check for new files to rename in a folder',
'params': { 'params': {
'async': {'desc': 'Optional: Set to 1 if you dont want to fire the renamer.scan asynchronous.'}, 'async': {'desc': 'Optional: Set to 1 if you dont want to fire the renamer.scan asynchronous.'},
'movie_folder': {'desc': 'Optional: The folder of the movie to scan. Keep empty for default renamer folder.'}, 'media_folder': {'desc': 'Optional: The folder of the media to scan. Keep empty for default renamer folder.'},
'files': {'desc': 'Optional: Provide the release files if more releases are in the same movie_folder, delimited with a \'|\'. Note that no dedicated release folder is expected for releases with one file.'}, 'files': {'desc': 'Optional: Provide the release files if more releases are in the same media_folder, delimited with a \'|\'. Note that no dedicated release folder is expected for releases with one file.'},
'downloader' : {'desc': 'Optional: The downloader the release has been downloaded with. \'download_id\' is required with this option.'}, 'downloader' : {'desc': 'Optional: The downloader the release has been downloaded with. \'download_id\' is required with this option.'},
'download_id': {'desc': 'Optional: The nzb/torrent ID of the release in movie_folder. \'downloader\' is required with this option.'}, 'download_id': {'desc': 'Optional: The nzb/torrent ID of the release in media_folder. \'downloader\' is required with this option.'},
'status': {'desc': 'Optional: The status of the release: \'completed\' (default) or \'seeding\''}, 'status': {'desc': 'Optional: The status of the release: \'completed\' (default) or \'seeding\''},
}, },
}) })
@@ -64,13 +64,18 @@ class Renamer(Plugin):
def scanView(self, **kwargs): def scanView(self, **kwargs):
async = tryInt(kwargs.get('async', 0)) async = tryInt(kwargs.get('async', 0))
movie_folder = sp(kwargs.get('movie_folder')) media_folder = sp(kwargs.get('media_folder'))
# Backwards compatibility, to be removed after a few versions :)
if not media_folder:
media_folder = sp(kwargs.get('movie_folder'))
downloader = kwargs.get('downloader') downloader = kwargs.get('downloader')
download_id = kwargs.get('download_id') download_id = kwargs.get('download_id')
files = '|'.join([sp(filename) for filename in splitString(kwargs.get('files'), '|')]) files = '|'.join([sp(filename) for filename in splitString(kwargs.get('files'), '|')])
status = kwargs.get('status', 'completed') status = kwargs.get('status', 'completed')
release_download = {'folder': movie_folder} if movie_folder else None release_download = {'folder': media_folder} if media_folder else None
if release_download: if release_download:
release_download.update({'id': download_id, 'downloader': downloader, 'status': status, 'files': files} if download_id else {}) release_download.update({'id': download_id, 'downloader': downloader, 'status': status, 'files': files} if download_id else {})
@@ -95,8 +100,8 @@ class Renamer(Plugin):
from_folder = sp(self.conf('from')) from_folder = sp(self.conf('from'))
to_folder = sp(self.conf('to')) to_folder = sp(self.conf('to'))
# Get movie folder to process # Get media folder to process
movie_folder = release_download.get('folder') media_folder = release_download.get('folder')
# Get all folders that should not be processed # Get all folders that should not be processed
no_process = [to_folder] no_process = [to_folder]
@@ -115,39 +120,39 @@ class Renamer(Plugin):
else: else:
for item in no_process: for item in no_process:
if '%s%s' % (from_folder, os.path.sep) in item: if '%s%s' % (from_folder, os.path.sep) in item:
log.error('To protect your data, the movie libraries can\'t be inside of or the same as the "from" folder.') log.error('To protect your data, the media libraries can\'t be inside of or the same as the "from" folder.')
return return
# Check to see if the no_process folders are inside the provided movie_folder # Check to see if the no_process folders are inside the provided media_folder
if movie_folder and not os.path.isdir(movie_folder): if media_folder and not os.path.isdir(media_folder):
log.debug('The provided movie folder %s does not exist. Trying to find it in the \'from\' folder.', movie_folder) log.debug('The provided media folder %s does not exist. Trying to find it in the \'from\' folder.', media_folder)
# Update to the from folder # Update to the from folder
if len(splitString(release_download.get('files'), '|')) == 1: if len(splitString(release_download.get('files'), '|')) == 1:
new_movie_folder = from_folder new_media_folder = from_folder
else: else:
new_movie_folder = os.path.join(from_folder, os.path.basename(movie_folder)) new_media_folder = os.path.join(from_folder, os.path.basename(media_folder))
if not os.path.isdir(new_movie_folder): if not os.path.isdir(new_media_folder):
log.error('The provided movie folder %s does not exist and could also not be found in the \'from\' folder.', movie_folder) log.error('The provided media folder %s does not exist and could also not be found in the \'from\' folder.', media_folder)
return return
# Update the files # Update the files
new_files = [os.path.join(new_movie_folder, os.path.relpath(filename, movie_folder)) for filename in splitString(release_download.get('files'), '|')] new_files = [os.path.join(new_media_folder, os.path.relpath(filename, media_folder)) for filename in splitString(release_download.get('files'), '|')]
if new_files and not os.path.isfile(new_files[0]): if new_files and not os.path.isfile(new_files[0]):
log.error('The provided movie folder %s does not exist and its files could also not be found in the \'from\' folder.', movie_folder) log.error('The provided media folder %s does not exist and its files could also not be found in the \'from\' folder.', media_folder)
return return
# Update release_download info to the from folder # Update release_download info to the from folder
log.debug('Release %s found in the \'from\' folder.', movie_folder) log.debug('Release %s found in the \'from\' folder.', media_folder)
release_download['folder'] = new_movie_folder release_download['folder'] = new_media_folder
release_download['files'] = '|'.join(new_files) release_download['files'] = '|'.join(new_files)
movie_folder = new_movie_folder media_folder = new_media_folder
if movie_folder: if media_folder:
for item in no_process: for item in no_process:
if '%s%s' % (movie_folder, os.path.sep) in item: if '%s%s' % (media_folder, os.path.sep) in item:
log.error('To protect your data, the movie libraries can\'t be inside of or the same as the provided movie folder.') log.error('To protect your data, the media libraries can\'t be inside of or the same as the provided media folder.')
return return
# Make sure a checkSnatched marked all downloads/seeds as such # Make sure a checkSnatched marked all downloads/seeds as such
@@ -156,26 +161,26 @@ class Renamer(Plugin):
self.renaming_started = True self.renaming_started = True
# make sure the movie folder name is included in the search # make sure the media folder name is included in the search
folder = None folder = None
files = [] files = []
if movie_folder: if media_folder:
log.info('Scanning movie folder %s...', movie_folder) log.info('Scanning media folder %s...', media_folder)
folder = os.path.dirname(movie_folder) folder = os.path.dirname(media_folder)
if release_download.get('files', ''): if release_download.get('files', ''):
files = splitString(release_download['files'], '|') files = splitString(release_download['files'], '|')
# If there is only one file in the torrent, the downloader did not create a subfolder # If there is only one file in the torrent, the downloader did not create a subfolder
if len(files) == 1: if len(files) == 1:
folder = movie_folder folder = media_folder
else: else:
# Get all files from the specified folder # Get all files from the specified folder
try: try:
for root, folders, names in os.walk(movie_folder): for root, folders, names in os.walk(media_folder):
files.extend([sp(os.path.join(root, name)) for name in names]) files.extend([sp(os.path.join(root, name)) for name in names])
except: except:
log.error('Failed getting files from %s: %s', (movie_folder, traceback.format_exc())) log.error('Failed getting files from %s: %s', (media_folder, traceback.format_exc()))
db = get_session() db = get_session()
@@ -185,7 +190,7 @@ class Renamer(Plugin):
# Unpack any archives # Unpack any archives
extr_files = None extr_files = None
if self.conf('unrar'): if self.conf('unrar'):
folder, movie_folder, files, extr_files = self.extractFiles(folder = folder, movie_folder = movie_folder, files = files, folder, media_folder, files, extr_files = self.extractFiles(folder = folder, media_folder = media_folder, files = files,
cleanup = self.conf('cleanup') and not self.downloadIsTorrent(release_download)) cleanup = self.conf('cleanup') and not self.downloadIsTorrent(release_download))
groups = fireEvent('scanner.scan', folder = folder if folder else from_folder, groups = fireEvent('scanner.scan', folder = folder if folder else from_folder,
@@ -497,7 +502,7 @@ class Renamer(Plugin):
os.remove(src) os.remove(src)
parent_dir = os.path.dirname(src) parent_dir = os.path.dirname(src)
if delete_folders.count(parent_dir) == 0 and os.path.isdir(parent_dir) and not parent_dir in [destination, movie_folder] and not from_folder in parent_dir: if delete_folders.count(parent_dir) == 0 and os.path.isdir(parent_dir) and not '%s%s' % (parent_dir, os.path.sep) in [destination, media_folder] and not '%s%s' % (from_folder, os.path.sep) in parent_dir:
delete_folders.append(parent_dir) delete_folders.append(parent_dir)
except: except:
@@ -529,7 +534,7 @@ class Renamer(Plugin):
self.tagRelease(group = group, tag = 'failed_rename') self.tagRelease(group = group, tag = 'failed_rename')
# Tag folder if it is in the 'from' folder and it will not be removed because it is a torrent # Tag folder if it is in the 'from' folder and it will not be removed because it is a torrent
if self.movieInFromFolder(movie_folder) and self.downloadIsTorrent(release_download): if self.movieInFromFolder(media_folder) and self.downloadIsTorrent(release_download):
self.tagRelease(group = group, tag = 'renamed_already') self.tagRelease(group = group, tag = 'renamed_already')
# Remove matching releases # Remove matching releases
@@ -541,9 +546,9 @@ class Renamer(Plugin):
log.error('Failed removing %s: %s', (release.identifier, traceback.format_exc())) log.error('Failed removing %s: %s', (release.identifier, traceback.format_exc()))
if group['dirname'] and group['parentdir'] and not self.downloadIsTorrent(release_download): if group['dirname'] and group['parentdir'] and not self.downloadIsTorrent(release_download):
if movie_folder: if media_folder:
# Delete the movie folder # Delete the movie folder
group_folder = movie_folder group_folder = media_folder
else: else:
# Delete the first empty subfolder in the tree relative to the 'from' folder # Delete the first empty subfolder in the tree relative to the 'from' folder
group_folder = sp(os.path.join(from_folder, os.path.relpath(group['parentdir'], from_folder).split(os.path.sep)[0])) group_folder = sp(os.path.join(from_folder, os.path.relpath(group['parentdir'], from_folder).split(os.path.sep)[0]))
@@ -614,6 +619,11 @@ Remove it if you want it to be renamed (again, or at least let it try again)
tag_files.extend([os.path.join(root, name) for name in names]) tag_files.extend([os.path.join(root, name) for name in names])
for filename in tag_files: for filename in tag_files:
# Dont tag .ignore files
if os.path.splitext(filename)[1] == '.ignore':
continue
tag_filename = '%s.%s.ignore' % (os.path.splitext(filename)[0], tag) tag_filename = '%s.%s.ignore' % (os.path.splitext(filename)[0], tag)
if not os.path.isfile(tag_filename): if not os.path.isfile(tag_filename):
self.createFile(tag_filename, text) self.createFile(tag_filename, text)
@@ -806,126 +816,159 @@ Remove it if you want it to be renamed (again, or at least let it try again)
Release.status_id.in_([snatched_status.get('id'), seeding_status.get('id'), missing_status.get('id')]) Release.status_id.in_([snatched_status.get('id'), seeding_status.get('id'), missing_status.get('id')])
).all() ).all()
if not rels:
#No releases found that need status checking
self.checking_snatched = False
return 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') and rel_dict['info'].get('download_downloader'):
download_ids.append({'id': rel_dict['info']['download_id'], 'downloader': rel_dict['info']['download_downloader']})
except:
log.error('Error getting download IDs from database')
self.checking_snatched = False
return False
release_downloads = fireEvent('download.status', download_ids, merge = True)
if not release_downloads:
log.debug('Download status functionality is not implemented for any active downloaders.')
fireEvent('renamer.scan')
self.checking_snatched = False
return True
scan_releases = [] scan_releases = []
scan_required = False scan_required = False
if rels: log.debug('Checking status snatched releases...')
log.debug('Checking status snatched releases...')
release_downloads = fireEvent('download.status', merge = True) try:
if not release_downloads: for rel in rels:
log.debug('Download status functionality is not implemented for active downloaders.') rel_dict = rel.to_dict({'info': {}})
scan_required = True movie_dict = fireEvent('media.get', media_id = rel.movie_id, single = True)
else:
try:
for rel in rels:
rel_dict = rel.to_dict({'info': {}})
movie_dict = fireEvent('media.get', media_id = rel.movie_id, single = True)
if not isinstance(rel_dict['info'], (dict)): if not isinstance(rel_dict['info'], (dict)):
log.error('Faulty release found without any info, ignoring.') log.error('Faulty release found without any info, ignoring.')
fireEvent('release.update_status', rel.id, status = ignored_status, single = True)
continue
# Check if download ID is available
if not rel_dict['info'].get('download_id') or not rel_dict['info'].get('download_downloader'):
log.debug('Download status functionality is not implemented for downloader (%s) of release %s.', (rel_dict['info'].get('download_downloader', 'unknown'), rel_dict['info']['name']))
scan_required = True
# Continue with next release
continue
# Find release in downloaders
nzbname = self.createNzbName(rel_dict['info'], movie_dict)
for release_download in release_downloads:
found_release = False
if rel_dict['info'].get('download_id'):
if release_download['id'] == rel_dict['info']['download_id'] and release_download['downloader'] == rel_dict['info']['download_downloader']:
log.debug('Found release by id: %s', release_download['id'])
found_release = True
break
else:
if release_download['name'] == nzbname or rel_dict['info']['name'] in release_download['name'] or getImdb(release_download['name']) == movie_dict['library']['identifier']:
log.debug('Found release by release name or imdb ID: %s', release_download['name'])
found_release = True
break
if not found_release:
log.info('%s not found in downloaders', nzbname)
#Check status if already missing and for how long, if > 1 week, set to ignored else to missing
if rel.status_id == missing_status.get('id'):
if rel.last_edit < int(time.time()) - 7 * 24 * 60 * 60:
fireEvent('release.update_status', rel.id, status = ignored_status, single = True) fireEvent('release.update_status', rel.id, status = ignored_status, single = True)
continue else:
# Set the release to missing
fireEvent('release.update_status', rel.id, status = missing_status, single = True)
# check status # Continue with next release
nzbname = self.createNzbName(rel_dict['info'], movie_dict) continue
found = False # Log that we found the release
for release_download in release_downloads: timeleft = 'N/A' if release_download['timeleft'] == -1 else release_download['timeleft']
found_release = False log.debug('Found %s: %s, time to go: %s', (release_download['name'], release_download['status'].upper(), timeleft))
if rel_dict['info'].get('download_id'):
if release_download['id'] == rel_dict['info']['download_id'] and release_download['downloader'] == rel_dict['info']['download_downloader']: # Check status of release
log.debug('Found release by id: %s', release_download['id']) if release_download['status'] == 'busy':
found_release = True # Set the release to snatched if it was missing before
fireEvent('release.update_status', rel.id, status = snatched_status, single = True)
# Tag folder if it is in the 'from' folder and it will not be processed because it is still downloading
if self.movieInFromFolder(release_download['folder']):
self.tagRelease(release_download = release_download, tag = 'downloading')
elif release_download['status'] == 'seeding':
#If linking setting is enabled, process release
if self.conf('file_action') != 'move' and not rel.status_id == seeding_status.get('id') and self.statusInfoComplete(release_download):
log.info('Download of %s completed! It is now being processed while leaving the original files alone for seeding. Current ratio: %s.', (release_download['name'], release_download['seed_ratio']))
# Remove the downloading tag
self.untagRelease(release_download = release_download, tag = 'downloading')
# Scan and set the torrent to paused if required
release_download.update({'pause': True, 'scan': True, 'process_complete': False})
scan_releases.append(release_download)
else:
#let it seed
log.debug('%s is seeding with ratio: %s', (release_download['name'], release_download['seed_ratio']))
# Set the release to seeding
fireEvent('release.update_status', rel.id, status = seeding_status, single = True)
elif release_download['status'] == 'failed':
# Set the release to failed
fireEvent('release.update_status', rel.id, status = failed_status, single = True)
fireEvent('download.remove_failed', release_download, single = True)
if self.conf('next_on_failed'):
fireEvent('movie.searcher.try_next_release', media_id = rel.movie_id)
elif release_download['status'] == 'completed':
log.info('Download of %s completed!', release_download['name'])
#Make sure the downloader sent over a path to look in
if self.statusInfoComplete(release_download):
# If the release has been seeding, process now the seeding is done
if rel.status_id == seeding_status.get('id'):
if self.conf('file_action') != 'move':
# Set the release to done as the movie has already been renamed
fireEvent('release.update_status', rel.id, status = downloaded_status, single = True)
# Allow the downloader to clean-up
release_download.update({'pause': False, 'scan': False, 'process_complete': True})
scan_releases.append(release_download)
else: else:
if release_download['name'] == nzbname or rel_dict['info']['name'] in release_download['name'] or getImdb(release_download['name']) == movie_dict['library']['identifier']: # Scan and Allow the downloader to clean-up
found_release = True release_download.update({'pause': False, 'scan': True, 'process_complete': True})
scan_releases.append(release_download)
if found_release: else:
timeleft = 'N/A' if release_download['timeleft'] == -1 else release_download['timeleft'] # Set the release to snatched if it was missing before
log.debug('Found %s: %s, time to go: %s', (release_download['name'], release_download['status'].upper(), timeleft)) fireEvent('release.update_status', rel.id, status = snatched_status, single = True)
if release_download['status'] == 'busy': # Remove the downloading tag
# Set the release to snatched if it was missing before self.untagRelease(release_download = release_download, tag = 'downloading')
fireEvent('release.update_status', rel.id, status = snatched_status, single = True)
# Tag folder if it is in the 'from' folder and it will not be processed because it is still downloading # Scan and Allow the downloader to clean-up
if self.movieInFromFolder(release_download['folder']): release_download.update({'pause': False, 'scan': True, 'process_complete': True})
self.tagRelease(release_download = release_download, tag = 'downloading') scan_releases.append(release_download)
else:
scan_required = True
elif release_download['status'] == 'seeding': except:
#If linking setting is enabled, process release log.error('Failed checking for release in downloader: %s', traceback.format_exc())
if self.conf('file_action') != 'move' and not rel.status_id == seeding_status.get('id') and self.statusInfoComplete(release_download):
log.info('Download of %s completed! It is now being processed while leaving the original files alone for seeding. Current ratio: %s.', (release_download['name'], release_download['seed_ratio']))
# Remove the downloading tag
self.untagRelease(release_download = release_download, tag = 'downloading')
# Scan and set the torrent to paused if required
release_download.update({'pause': True, 'scan': True, 'process_complete': False})
scan_releases.append(release_download)
else:
#let it seed
log.debug('%s is seeding with ratio: %s', (release_download['name'], release_download['seed_ratio']))
# Set the release to seeding
fireEvent('release.update_status', rel.id, status = seeding_status, single = True)
elif release_download['status'] == 'failed':
# Set the release to failed
fireEvent('release.update_status', rel.id, status = failed_status, single = True)
fireEvent('download.remove_failed', release_download, single = True)
if self.conf('next_on_failed'):
fireEvent('movie.searcher.try_next_release', media_id = rel.movie_id)
elif release_download['status'] == 'completed':
log.info('Download of %s completed!', release_download['name'])
if self.statusInfoComplete(release_download):
# If the release has been seeding, process now the seeding is done
if rel.status_id == seeding_status.get('id'):
if self.conf('file_action') != 'move':
# Set the release to done as the movie has already been renamed
fireEvent('release.update_status', rel.id, status = downloaded_status, single = True)
# Allow the downloader to clean-up
release_download.update({'pause': False, 'scan': False, 'process_complete': True})
scan_releases.append(release_download)
else:
# Scan and Allow the downloader to clean-up
release_download.update({'pause': False, 'scan': True, 'process_complete': True})
scan_releases.append(release_download)
else:
# Set the release to snatched if it was missing before
fireEvent('release.update_status', rel.id, status = snatched_status, single = True)
# Remove the downloading tag
self.untagRelease(release_download = release_download, tag = 'downloading')
# Scan and Allow the downloader to clean-up
release_download.update({'pause': False, 'scan': True, 'process_complete': True})
scan_releases.append(release_download)
else:
scan_required = True
found = True
break
if not found:
log.info('%s not found in downloaders', nzbname)
#Check status if already missing and for how long, if > 1 week, set to ignored else to missing
if rel.status_id == missing_status.get('id'):
if rel.last_edit < int(time.time()) - 7 * 24 * 60 * 60:
fireEvent('release.update_status', rel.id, status = ignored_status, single = True)
else:
# Set the release to missing
fireEvent('release.update_status', rel.id, status = missing_status, single = True)
except:
log.error('Failed checking for release in downloader: %s', traceback.format_exc())
# The following can either be done here, or inside the scanner if we pass it scan_items in one go # The following can either be done here, or inside the scanner if we pass it scan_items in one go
for release_download in scan_releases: for release_download in scan_releases:
@@ -948,7 +991,6 @@ Remove it if you want it to be renamed (again, or at least let it try again)
fireEvent('renamer.scan') fireEvent('renamer.scan')
self.checking_snatched = False self.checking_snatched = False
return True return True
def extendReleaseDownload(self, release_download): def extendReleaseDownload(self, release_download):
@@ -995,10 +1037,10 @@ Remove it if you want it to be renamed (again, or at least let it try again)
def statusInfoComplete(self, release_download): def statusInfoComplete(self, release_download):
return release_download['id'] and release_download['downloader'] and release_download['folder'] return release_download['id'] and release_download['downloader'] and release_download['folder']
def movieInFromFolder(self, movie_folder): def movieInFromFolder(self, media_folder):
return movie_folder and sp(self.conf('from')) in sp(movie_folder) or not movie_folder return media_folder and '%s%s' % (sp(self.conf('from')), os.path.sep) in sp(media_folder) or not media_folder
def extractFiles(self, folder = None, movie_folder = None, files = None, cleanup = False): def extractFiles(self, folder = None, media_folder = None, files = None, cleanup = False):
if not files: files = [] if not files: files = []
# RegEx for finding rar files # RegEx for finding rar files
@@ -1013,7 +1055,7 @@ Remove it if you want it to be renamed (again, or at least let it try again)
folder = from_folder folder = from_folder
check_file_date = True check_file_date = True
if movie_folder: if media_folder:
check_file_date = False check_file_date = False
if not files: if not files:
@@ -1109,18 +1151,18 @@ Remove it if you want it to be renamed (again, or at least let it try again)
if cleanup: if cleanup:
# Remove all left over folders # Remove all left over folders
log.debug('Removing old movie folder %s...', movie_folder) log.debug('Removing old movie folder %s...', media_folder)
self.deleteEmptyFolder(movie_folder) self.deleteEmptyFolder(media_folder)
movie_folder = os.path.join(from_folder, os.path.relpath(movie_folder, folder)) media_folder = os.path.join(from_folder, os.path.relpath(media_folder, folder))
folder = from_folder folder = from_folder
if extr_files: if extr_files:
files.extend(extr_files) files.extend(extr_files)
# Cleanup files and folder if movie_folder was not provided # Cleanup files and folder if media_folder was not provided
if not movie_folder: if not media_folder:
files = [] files = []
folder = None folder = None
return folder, movie_folder, files, extr_files return folder, media_folder, files, extr_files