Giter VIP home page Giter VIP logo

Comments (6)

rndusr avatar rndusr commented on June 8, 2024 1

from torf.

dvector89 avatar dvector89 commented on June 8, 2024

@rr- @sinic @PyR8zdl

from torf.

rndusr avatar rndusr commented on June 8, 2024

from torf.

dvector89 avatar dvector89 commented on June 8, 2024

You need to torrent.generate() before you can torrent.write(). Also, you can modify torrent.files like any regular list, so you can do stuff like del torrent.files[3] or torrent.files.remove("file/path").

Thanks for your reply. It seems that i have a wrong understanding for torf.

add torrent.generate

I tried torrent.generate() . But there are some errors. The code and error information are below:

from torf import Torrent

torrent = Torrent.read('./temp/old.torrent')
#torrent.files = [torrent.files[0], torrent.files[2], torrent.files[-1]]
del torrent.files[3]
torrent.generate()
torrent.write('./temp/new.torrent')

Traceback (most recent call last):
File "test.py", line 6, in
torrent.generate()
File "D:\work\02work\work\009torrent\rw-torrent\venv\lib\site-packages\torf_torrent.py", line 1016, in generate
raise RuntimeError('generate() called with no path specified')
RuntimeError: generate() called with no path specified

add path

I add a path to torrent:

from torf import Torrent

torrent = Torrent.read('./temp/old.torrent')
#torrent.files = [torrent.files[0], torrent.files[2], torrent.files[-1]]
del torrent.files[3]
torrent.path = 'temp'
torrent.generate()
print(torrent.files)
torrent.write('./temp/new.torrent')

But the new.torrent contains the files which are in my computer, instead of the files in the old.torrent. The information is below:

λ ls temp/
k old.torrent
(venv) admin@DESKTOP-ILNMBPV /d/work/02work/work/009torrent/rw-torrent
λ python test.py
[File('temp\k', size=95829), File('temp\old.torrent', size=95829)]
(venv) admin@DESKTOP-ILNMBPV /d/work/02work/work/009torrent/rw-torrent

what's more, if the path does not exist, the code and error information are below:

from torf import Torrent

torrent = Torrent.read('./temp/old.torrent')
#torrent.files = [torrent.files[0], torrent.files[2], torrent.files[-1]]
del torrent.files[3]
torrent.path = 'temp_not_exist'
torrent.generate()
print(torrent.files)
torrent.write('./temp/new.torrent')

Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\os.py", line 350, in walk
scandir_it = scandir(top)
FileNotFoundError: [WinError 3] The system cannot find the specified path: 'temp_not_exist'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "test.py", line 6, in
torrent.path = 'temp_not_exist'
File "D:\work\02work\work\009torrent\rw-torrent\venv\lib\site-packages\torf_torrent.py", line 178, in path
for fp in utils.list_files(basepath))
File "D:\work\02work\work\009torrent\rw-torrent\venv\lib\site-packages\torf_utils.py", line 138, in list_files
for dirpath, dirnames, filenames in os.walk(path, onerror=onerror):
File "C:\ProgramData\Anaconda3\lib\os.py", line 353, in walk
onerror(error)
File "D:\work\02work\work\009torrent\rw-torrent\venv\lib\site-packages\torf_utils.py", line 136, in onerror
getattr(exc, 'filename', None))
torf._errors.ReadError: temp_not_exist: No such file or directory

my goal

I want to download several files in a torrent which contains a lot of files. I want to remove some files in the torrent. So can a torrent file be modified by torf?

from torf.

dvector89 avatar dvector89 commented on June 8, 2024

Thanks @rndusr . So I can only download the specific files in the original torrent, instead of making a new torrent from the original torrent.

from torf.

rndusr avatar rndusr commented on June 8, 2024

from torf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.