pythonlibtorrent

Move downloaded torrent after finished downloading libtorrent


I am downloading torrents using libtorrent. The torrents have different download locations (save_path). I wish to move a downloaded torrent to new location after it finishes downloading. New location depends on pre-existing save_path.

ses = lt.session()
downloads=[]
.
.
params = {"save_path": "some/path"}
downloads.append(lt.add_magnet_uri(ses,  magnet_link, params))
.
.
.

    for index, download in enumerate(downloads[:]):
        if not download.is_seed():
            s = download.status()

            /....DO SOMETHING..../

        else:
            ses.remove_torrent(download)
            downloads.remove(download)
            
            #path of downloaded file
            #download.status().save_path 

            /...MOVE FILES TO NEW LOCATION.../

            print(download.name(), "complete")
  1. How do I get save_path of downloaded torrent DONE
  2. How do I move downloaded files

Solution

  • Hi according to follwoing commit on github libtorrent or rather the test.py. I would guess that you get the save_path like this:

    s = download.status()
    s.save_path
    

    I could not test it. Hope it works.

    Move a file, is here

    import shutil
    shutil.move(s.save_path, "path/to/new/destination/")