From c1266a36e4c526017958b76c41973707f54c1b65 Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 10 Feb 2015 13:15:08 +0100 Subject: [PATCH] Re-use resursion code --- couchpotato/core/downloaders/putio/main.py | 26 ++++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/couchpotato/core/downloaders/putio/main.py b/couchpotato/core/downloaders/putio/main.py index 478d15c9..c5685821 100644 --- a/couchpotato/core/downloaders/putio/main.py +++ b/couchpotato/core/downloaders/putio/main.py @@ -29,15 +29,16 @@ class PutIO(DownloaderBase): return super(PutIO, self).__init__() # This is a recusive function to check for the folders - def recursionFolder(self, client, folder, tfolder): + def recursionFolder(self, client, folder = 0, tfolder = ''): files = client.File.list(folder) for f in files: - if f.name == tfolder and f.content_type == "application/x-directory": - return f.id - elif f.content_type == "application/x-directory": - result = self.recursionFolder(client, f.id, tfolder) - if result != 0: - return result + if f.content_type == 'application/x-directory': + if f.name == tfolder: + return f.id + else: + result = self.recursionFolder(client, f.id, tfolder) + if result != 0: + return result return 0 # This will check the root for the folder, and kick of recusively checking sub folder @@ -45,16 +46,7 @@ class PutIO(DownloaderBase): if folder == 0: return 0 else: - files = client.File.list() - for f in files: - if f.name == folder and f.content_type == "application/x-directory": - return f.id - elif f.content_type == "application/x-directory": - result = self.recursionFolder(client, f.id, folder) - if result != 0: - return result - #If we get through the whole list and don't get a match we will use the root - return 0 + return self.recursionFolder(client, 0, folder) def download(self, data = None, media = None, filedata = None): if not media: media = {}