Browse Source

Include files from downloader in renamer

pull/2269/head
mano3m 12 years ago
parent
commit
54c7aad57a
  1. 1
      couchpotato/core/downloaders/base.py
  2. 42
      couchpotato/core/downloaders/utorrent/main.py
  3. 7
      couchpotato/core/plugins/renamer/main.py

1
couchpotato/core/downloaders/base.py

@ -190,6 +190,7 @@ class StatusList(list):
'status': 'busy', 'status': 'busy',
'downloader': self.provider.getName(), 'downloader': self.provider.getName(),
'folder': '', 'folder': '',
'files': '',
} }
return mergeDicts(defaults, result) return mergeDicts(defaults, result)

42
couchpotato/core/downloaders/utorrent/main.py

@ -102,39 +102,6 @@ class uTorrent(Downloader):
if self.conf('paused', default = 0): if self.conf('paused', default = 0):
self.utorrent_api.pause_torrent(torrent_hash) self.utorrent_api.pause_torrent(torrent_hash)
count = 0
while True:
count += 1
# Check if torrent is saved in subfolder of torrent name
getfiles_data = self.utorrent_api.get_files(torrent_hash)
torrent_files = json.loads(getfiles_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) return self.downloadReturnId(torrent_hash)
def getAllDownloadStatus(self): def getAllDownloadStatus(self):
@ -172,6 +139,14 @@ class uTorrent(Downloader):
status = 'seeding' status = 'seeding'
self.removeReadOnly(item[26]) self.removeReadOnly(item[26])
#Get files of the torrent
torrent_files = ''
try:
torrent_files = json.loads(self.utorrent_api.get_files(item[0]))
torrent_files = [os.path.join(item[26], torrent_file[0]) for torrent_file in torrent_files['files'][1]]
except:
log.debug('Failed getting files from torrent: %s', item[2])
statuses.append({ statuses.append({
'id': item[0], 'id': item[0],
'name': item[2], 'name': item[2],
@ -180,6 +155,7 @@ class uTorrent(Downloader):
'original_status': item[1], 'original_status': item[1],
'timeleft': str(timedelta(seconds = item[10])), 'timeleft': str(timedelta(seconds = item[10])),
'folder': ss(item[26]), 'folder': ss(item[26]),
'files': ss('|'.join(torrent_files))
}) })
return statuses return statuses

7
couchpotato/core/plugins/renamer/main.py

@ -115,6 +115,13 @@ class Renamer(Plugin):
movie_folder = movie_folder.rstrip(os.path.sep) movie_folder = movie_folder.rstrip(os.path.sep)
folder = os.path.dirname(movie_folder) folder = os.path.dirname(movie_folder)
if download_info['files']:
files = download_info['files'].split('|')
# If there is only one file in the torrent, the downloader did not create a subfolder
if len(files) == 1:
folder = movie_folder
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(movie_folder):

Loading…
Cancel
Save