Add folder_rename to the core
This commit is contained in:
parent
0365ae00c0
commit
793e138d11
|
@ -122,6 +122,11 @@ class Torrent:
|
|||
# Let's us know if we're waiting on a lt alert
|
||||
self.waiting_on_resume_data = False
|
||||
|
||||
# Keep a list of file indexes we're waiting for file_rename alerts on
|
||||
# This is so we can send one folder_renamed signal instead of multiple
|
||||
# file_renamed signals.
|
||||
self.waiting_on_folder_rename = []
|
||||
|
||||
# We store the filename just in case we need to make a copy of the torrentfile
|
||||
if not filename:
|
||||
# If no filename was provided, then just use the infohash
|
||||
|
@ -795,3 +800,12 @@ class Torrent:
|
|||
for index, filename in filenames:
|
||||
self.handle.rename_file(index, filename)
|
||||
|
||||
def rename_folder(self, folder, new_folder):
|
||||
"""Renames a folder within a torrent. This basically does a file rename
|
||||
on all of the folders children."""
|
||||
for f in self.get_files():
|
||||
if f["path"].startswith(folder):
|
||||
# Keep a list of filerenames we're waiting on
|
||||
self.waiting_on_folder_rename.append(f["index"])
|
||||
self.handle.rename_file(f["index"], f["path"].replace(folder, new_folder, 1))
|
||||
|
||||
|
|
|
@ -758,8 +758,18 @@ class TorrentManager(component.Component):
|
|||
log.debug("index: %s name: %s", alert.index, alert.name)
|
||||
torrent_id = str(alert.handle.info_hash())
|
||||
torrent = self.torrents[torrent_id]
|
||||
old_folder = os.path.split(torrent.files[alert.index]["path"])[0]
|
||||
new_folder = os.path.split(alert.name)[0]
|
||||
torrent.files[alert.index]["path"] = alert.name
|
||||
component.get("SignalManager").emit("torrent_file_renamed", torrent_id, alert.index, alert.name)
|
||||
|
||||
if alert.index in torrent.waiting_on_folder_rename:
|
||||
if torrent.waiting_on_folder_rename == [alert.index]:
|
||||
# This is the last alert we were waiting for, time to send signal
|
||||
component.get("SignalManager").emit("torrent_folder_renamed", torrent_id, old_folder, new_folder)
|
||||
torrent.waiting_on_folder_rename.remove(alert.index)
|
||||
else:
|
||||
# This is just a regular file rename so send the signal
|
||||
component.get("SignalManager").emit("torrent_file_renamed", torrent_id, alert.index, alert.name)
|
||||
|
||||
def on_alert_metadata_received(self, alert):
|
||||
log.debug("on_alert_metadata_received")
|
||||
|
|
Loading…
Reference in New Issue