diff --git a/couchpotato/core/downloaders/utorrent/main.py b/couchpotato/core/downloaders/utorrent/main.py index d933007..ce82c8c 100644 --- a/couchpotato/core/downloaders/utorrent/main.py +++ b/couchpotato/core/downloaders/utorrent/main.py @@ -77,7 +77,7 @@ class uTorrent(Downloader): else: info = bdecode(filedata)["info"] torrent_hash = sha1(benc(info)).hexdigest().upper() - torrent_filename = self.createFileName(data, filedata, movie) + torrent_filename = self.createFileName(data, filedata, movie) if data.get('seed_ratio'): torrent_params['seed_override'] = 1 @@ -93,7 +93,7 @@ class uTorrent(Downloader): # Send request to uTorrent if data.get('protocol') == 'torrent_magnet': - self.utorrent_api.add_torrent_uri(data.get('url')) + self.utorrent_api.add_torrent_uri(torrent_filename, data.get('url')) else: self.utorrent_api.add_torrent_file(torrent_filename, filedata) @@ -102,6 +102,39 @@ class uTorrent(Downloader): if self.conf('paused', default = 0): self.utorrent_api.pause_torrent(torrent_hash) + count = 0 + while True: + + count += 1 + # Check if torrent is saved in subfolder of torrent name + data = self.utorrent_api.get_files(torrent_hash) + + torrent_files = json.loads(data) + if torrent_files.get('error'): + log.error('Error getting data from uTorrent: %s', torrent_files.get('error')) + return False + + if (torrent_files.get('files') and len(torrent_files['files'][1]) > 0) or count > 60: + break + + time.sleep(1) + + # Torrent has only one file, so uTorrent wont create a folder for it + if len(torrent_files['files'][1]) == 1: + # Remove torrent and try again + self.utorrent_api.remove_torrent(torrent_hash, remove_data = True) + + # Send request to uTorrent + if data.get('protocol') == 'torrent_magnet': + self.utorrent_api.add_torrent_uri(torrent_filename, data.get('url'), add_folder = True) + else: + self.utorrent_api.add_torrent_file(torrent_filename, filedata, add_folder = True) + + # Change settings of added torrent + self.utorrent_api.set_torrent(torrent_hash, torrent_params) + if self.conf('paused', default = 0): + self.utorrent_api.pause_torrent(torrent_hash) + return self.downloadReturnId(torrent_hash) def getAllDownloadStatus(self): @@ -224,12 +257,16 @@ class uTorrentAPI(object): token = re.findall("