diff --git a/couchpotato/core/downloaders/deluge/main.py b/couchpotato/core/downloaders/deluge/main.py index 5cdfa2b..f65b74a 100644 --- a/couchpotato/core/downloaders/deluge/main.py +++ b/couchpotato/core/downloaders/deluge/main.py @@ -129,7 +129,7 @@ class Deluge(Downloader): 'original_status': torrent['state'], 'seed_ratio': torrent['ratio'], '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), }) diff --git a/couchpotato/core/downloaders/nzbvortex/main.py b/couchpotato/core/downloaders/nzbvortex/main.py index 4ec4586..f4e233b 100644 --- a/couchpotato/core/downloaders/nzbvortex/main.py +++ b/couchpotato/core/downloaders/nzbvortex/main.py @@ -30,7 +30,7 @@ class NZBVortex(Downloader): # Send the nzb try: 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') nzb_id = [nzb['id'] for nzb in raw_statuses.get('nzbs', []) if nzb['name'] == nzb_filename][0] diff --git a/couchpotato/core/downloaders/rtorrent/main.py b/couchpotato/core/downloaders/rtorrent/main.py index bcc92d2..d7ae589 100755 --- a/couchpotato/core/downloaders/rtorrent/main.py +++ b/couchpotato/core/downloaders/rtorrent/main.py @@ -156,7 +156,7 @@ class rTorrent(Downloader): for torrent in torrents: torrent_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' if torrent.complete: @@ -217,7 +217,7 @@ class rTorrent(Downloader): if torrent.is_multi_file() and torrent.directory.endswith(torrent.name): # Remove empty directories bottom up try: - for path, _, _ in os.walk(torrent.directory, topdown=False): + for path, _, _ in os.walk(torrent.directory, topdown = False): os.rmdir(path) except OSError: log.info('Directory "%s" contains extra files, unable to remove', torrent.directory) diff --git a/couchpotato/core/downloaders/sabnzbd/main.py b/couchpotato/core/downloaders/sabnzbd/main.py index de8ecef..aba2123 100644 --- a/couchpotato/core/downloaders/sabnzbd/main.py +++ b/couchpotato/core/downloaders/sabnzbd/main.py @@ -118,7 +118,7 @@ class Sabnzbd(Downloader): 'status': status, 'original_status': nzb['status'], '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 diff --git a/couchpotato/core/downloaders/transmission/main.py b/couchpotato/core/downloaders/transmission/main.py index a2295a0..2eabb2e 100644 --- a/couchpotato/core/downloaders/transmission/main.py +++ b/couchpotato/core/downloaders/transmission/main.py @@ -105,7 +105,7 @@ class Transmission(Downloader): 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' if torrent.get('isStalled') and self.conf('stalled_as_failed'): @@ -122,7 +122,7 @@ class Transmission(Downloader): 'original_status': torrent['status'], 'seed_ratio': torrent['uploadRatio'], '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) }) diff --git a/couchpotato/core/downloaders/utorrent/main.py b/couchpotato/core/downloaders/utorrent/main.py index 5486263..1db1b8a 100644 --- a/couchpotato/core/downloaders/utorrent/main.py +++ b/couchpotato/core/downloaders/utorrent/main.py @@ -134,7 +134,7 @@ class uTorrent(Downloader): torrent_files = [] try: 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: log.debug('Failed getting files from torrent: %s', torrent[2]) diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index b0c6f1f..649e359 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -1,7 +1,7 @@ from StringIO import StringIO from couchpotato.core.event import fireEvent, addEvent from couchpotato.core.helpers.encoding import tryUrlencode, ss, toSafeString, \ - toUnicode + toUnicode, sp from couchpotato.core.helpers.variable import getExt, md5, isLocalIP from couchpotato.core.logger import CPLog from couchpotato.environment import Env @@ -294,7 +294,7 @@ class Plugin(object): return '%s%s' % (toSafeString(toUnicode(data.get('name'))[:127 - len(tag)]), tag) 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 '' not in filedata: return '%s.%s' % (name, 'rar') return '%s.%s' % (name, data.get('protocol')) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 096c3c4..bbe79a3 100755 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -89,11 +89,14 @@ class Renamer(Plugin): log.info('Renamer is already running, if you see this often, check the logs above for errors.') return + from_folder = sp(self.conf('from')) + to_folder = sp(self.conf('to')) + # Get movie folder to process movie_folder = release_download and release_download.get('folder') # 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 [] no_process.extend([item['destination'] for item in cat_list]) try: @@ -103,12 +106,12 @@ class Renamer(Plugin): pass # 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.') return else: 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.') return @@ -118,9 +121,9 @@ class Renamer(Plugin): # Update to the from folder 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: - 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): 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, 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 [] folder_name = self.conf('folder_name') @@ -221,7 +224,7 @@ class Renamer(Plugin): movie_title = getTitle(library) # Overwrite destination when set in category - destination = sp(self.conf('to')) + destination = to_folder category_label = '' for movie in library_ent.movies: @@ -491,7 +494,7 @@ class Renamer(Plugin): os.remove(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) except: @@ -540,7 +543,7 @@ class Renamer(Plugin): group_folder = movie_folder else: # 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: log.info('Deleting folder: %s', group_folder)