SP function wrapping whole variables
This commit is contained in:
@@ -129,7 +129,7 @@ class Deluge(Downloader):
|
|||||||
'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(sp(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),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class NZBVortex(Downloader):
|
|||||||
# Send the nzb
|
# Send the nzb
|
||||||
try:
|
try:
|
||||||
nzb_filename = self.createFileName(data, filedata, movie)
|
nzb_filename = self.createFileName(data, filedata, movie)
|
||||||
self.call('nzb/add', params = {'file': (sp(nzb_filename), filedata)}, multipart = True)
|
self.call('nzb/add', params = {'file': (nzb_filename, filedata)}, multipart = True)
|
||||||
|
|
||||||
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 nzb['name'] == nzb_filename][0]
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ class rTorrent(Downloader):
|
|||||||
for torrent in torrents:
|
for torrent in torrents:
|
||||||
torrent_files = []
|
torrent_files = []
|
||||||
for file_item in torrent.get_files():
|
for file_item in torrent.get_files():
|
||||||
torrent_files.append(os.path.join(sp(torrent.directory), sp(file_item.path)))
|
torrent_files.append(sp(os.path.join(torrent.directory, file_item.path)))
|
||||||
|
|
||||||
status = 'busy'
|
status = 'busy'
|
||||||
if torrent.complete:
|
if torrent.complete:
|
||||||
@@ -217,7 +217,7 @@ class rTorrent(Downloader):
|
|||||||
if torrent.is_multi_file() and torrent.directory.endswith(torrent.name):
|
if torrent.is_multi_file() and torrent.directory.endswith(torrent.name):
|
||||||
# Remove empty directories bottom up
|
# Remove empty directories bottom up
|
||||||
try:
|
try:
|
||||||
for path, _, _ in os.walk(torrent.directory, topdown=False):
|
for path, _, _ in os.walk(torrent.directory, topdown = False):
|
||||||
os.rmdir(path)
|
os.rmdir(path)
|
||||||
except OSError:
|
except OSError:
|
||||||
log.info('Directory "%s" contains extra files, unable to remove', torrent.directory)
|
log.info('Directory "%s" contains extra files, unable to remove', torrent.directory)
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ class Sabnzbd(Downloader):
|
|||||||
'status': status,
|
'status': status,
|
||||||
'original_status': nzb['status'],
|
'original_status': nzb['status'],
|
||||||
'timeleft': str(timedelta(seconds = 0)),
|
'timeleft': str(timedelta(seconds = 0)),
|
||||||
'folder': os.path.dirname(sp(nzb['storage'])) if os.path.isfile(sp(nzb['storage'])) else sp(nzb['storage']),
|
'folder': sp(os.path.dirname(nzb['storage']) if os.path.isfile(nzb['storage']) else nzb['storage']),
|
||||||
})
|
})
|
||||||
|
|
||||||
return release_downloads
|
return release_downloads
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class Transmission(Downloader):
|
|||||||
|
|
||||||
torrent_files = []
|
torrent_files = []
|
||||||
for file_item in torrent['files']:
|
for file_item in torrent['files']:
|
||||||
torrent_files.append(os.path.join(sp(torrent['downloadDir']), sp(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'):
|
||||||
@@ -122,7 +122,7 @@ class Transmission(Downloader):
|
|||||||
'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(sp(torrent['downloadDir']), sp(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)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ class uTorrent(Downloader):
|
|||||||
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 = [os.path.join(sp(torrent[26]), sp(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])
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
from couchpotato.core.event import fireEvent, addEvent
|
from couchpotato.core.event import fireEvent, addEvent
|
||||||
from couchpotato.core.helpers.encoding import tryUrlencode, ss, toSafeString, \
|
from couchpotato.core.helpers.encoding import tryUrlencode, ss, toSafeString, \
|
||||||
toUnicode
|
toUnicode, sp
|
||||||
from couchpotato.core.helpers.variable import getExt, md5, isLocalIP
|
from couchpotato.core.helpers.variable import getExt, md5, isLocalIP
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.environment import Env
|
from couchpotato.environment import Env
|
||||||
@@ -294,7 +294,7 @@ class Plugin(object):
|
|||||||
return '%s%s' % (toSafeString(toUnicode(data.get('name'))[:127 - len(tag)]), tag)
|
return '%s%s' % (toSafeString(toUnicode(data.get('name'))[:127 - len(tag)]), tag)
|
||||||
|
|
||||||
def createFileName(self, data, filedata, movie):
|
def createFileName(self, data, filedata, movie):
|
||||||
name = os.path.join(self.createNzbName(data, movie))
|
name = sp(os.path.join(self.createNzbName(data, movie)))
|
||||||
if data.get('protocol') == 'nzb' and 'DOCTYPE nzb' not in filedata and '</nzb>' not in filedata:
|
if data.get('protocol') == 'nzb' and 'DOCTYPE nzb' not in filedata and '</nzb>' not in filedata:
|
||||||
return '%s.%s' % (name, 'rar')
|
return '%s.%s' % (name, 'rar')
|
||||||
return '%s.%s' % (name, data.get('protocol'))
|
return '%s.%s' % (name, data.get('protocol'))
|
||||||
|
|||||||
@@ -89,11 +89,14 @@ class Renamer(Plugin):
|
|||||||
log.info('Renamer is already running, if you see this often, check the logs above for errors.')
|
log.info('Renamer is already running, if you see this often, check the logs above for errors.')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
from_folder = sp(self.conf('from'))
|
||||||
|
to_folder = sp(self.conf('to'))
|
||||||
|
|
||||||
# Get movie folder to process
|
# Get movie folder to process
|
||||||
movie_folder = release_download and release_download.get('folder')
|
movie_folder = release_download and release_download.get('folder')
|
||||||
|
|
||||||
# Get all folders that should not be processed
|
# Get all folders that should not be processed
|
||||||
no_process = [sp(self.conf('to'))]
|
no_process = [to_folder]
|
||||||
cat_list = fireEvent('category.all', single = True) or []
|
cat_list = fireEvent('category.all', single = True) or []
|
||||||
no_process.extend([item['destination'] for item in cat_list])
|
no_process.extend([item['destination'] for item in cat_list])
|
||||||
try:
|
try:
|
||||||
@@ -103,12 +106,12 @@ class Renamer(Plugin):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Check to see if the no_process folders are inside the "from" folder.
|
# Check to see if the no_process folders are inside the "from" folder.
|
||||||
if not os.path.isdir(sp(self.conf('from'))) or not os.path.isdir(sp(self.conf('to'))):
|
if not os.path.isdir(from_folder) or not os.path.isdir(to_folder):
|
||||||
log.error('Both the "To" and "From" have to exist.')
|
log.error('Both the "To" and "From" have to exist.')
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
for item in no_process:
|
for item in no_process:
|
||||||
if sp(self.conf('from')) in item:
|
if from_folder 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 movie libraries can\'t be inside of or the same as the "from" folder.')
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -118,9 +121,9 @@ class Renamer(Plugin):
|
|||||||
|
|
||||||
# Update to the from folder
|
# Update to the from folder
|
||||||
if len(release_download.get('files')) == 1:
|
if len(release_download.get('files')) == 1:
|
||||||
new_movie_folder = ss(self.conf('from')) # ADD 'sp' function when that is pulled
|
new_movie_folder = from_folder
|
||||||
else:
|
else:
|
||||||
new_movie_folder = os.path.join(ss(self.conf('from')), os.path.basename(movie_folder)) # ADD 'sp' function when that is pulled
|
new_movie_folder = sp(os.path.join(from_folder, os.path.basename(movie_folder)))
|
||||||
|
|
||||||
if not os.path.isdir(new_movie_folder):
|
if not os.path.isdir(new_movie_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 movie folder %s does not exist and could also not be found in the \'from\' folder.', movie_folder)
|
||||||
@@ -182,7 +185,7 @@ class Renamer(Plugin):
|
|||||||
folder, movie_folder, files, extr_files = self.extractFiles(folder = folder, movie_folder = movie_folder, files = files,
|
folder, movie_folder, files, extr_files = self.extractFiles(folder = folder, movie_folder = movie_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 sp(self.conf('from')),
|
groups = fireEvent('scanner.scan', folder = folder if folder else from_folder,
|
||||||
files = files, release_download = release_download, return_ignored = False, single = True) or []
|
files = files, release_download = release_download, return_ignored = False, single = True) or []
|
||||||
|
|
||||||
folder_name = self.conf('folder_name')
|
folder_name = self.conf('folder_name')
|
||||||
@@ -221,7 +224,7 @@ class Renamer(Plugin):
|
|||||||
movie_title = getTitle(library)
|
movie_title = getTitle(library)
|
||||||
|
|
||||||
# Overwrite destination when set in category
|
# Overwrite destination when set in category
|
||||||
destination = sp(self.conf('to'))
|
destination = to_folder
|
||||||
category_label = ''
|
category_label = ''
|
||||||
for movie in library_ent.movies:
|
for movie in library_ent.movies:
|
||||||
|
|
||||||
@@ -491,7 +494,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 sp(self.conf('from')) in parent_dir:
|
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:
|
||||||
delete_folders.append(parent_dir)
|
delete_folders.append(parent_dir)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
@@ -540,7 +543,7 @@ class Renamer(Plugin):
|
|||||||
group_folder = movie_folder
|
group_folder = movie_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 = os.path.join(sp(self.conf('from')), os.path.relpath(group['parentdir'], sp(self.conf('from'))).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])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
log.info('Deleting folder: %s', group_folder)
|
log.info('Deleting folder: %s', group_folder)
|
||||||
|
|||||||
Reference in New Issue
Block a user