0

My problem is that I have so many torrent files that I need to attach. I have them all in a list.

torrent_list = ['file1.torrent', 'file2.torrent', etc.......]

Downloading torrents by file:

torrent_file = open('my-torrent-file.torrent', 'rb')
qb.download_from_file(torrent_file)

Downloading multiple torrents by using files:

I Am not able to get it work without writing it manually like it is shown in the example. I want to load them all from the list. can someone help with this?

torrent_file_list = [open('1.torrent', 'rb'), open('2.torrent', 'rb')]
qb.download_from_file(torrent_file_list)
0

2 Answers 2

2

Try like this:

torrent_list = ['file1.torrent', 'file2.torrent']
for myFile in torrent_list:
  with open(myFile,'rb') as torr:
    qb.download_from_file(torr)
Sign up to request clarification or add additional context in comments.

1 Comment

so, this method worked but after some time it breaks. via this examplea it was able to load 116 torrent files to my torrent client then its broke.
0

Use a list comprehension.

torrent_file_list = [open(filename, 'rb') for filename in torrent_list])
qb.download_from_file(torrent_file)
for f in torrent_file_list:
    close(f)

9 Comments

when it comes to the function open you must use it in a context manager, so the file close at the end. If you don't close the file then it could break it. And in this example you are not closing the file
I believe that the garbage collector will automatically close the files in this case.
You are right. I search for it and seems to be as you say. It is explained here Sorry 😅 and thanks, I didn't know that.
You're right that it's generally preferable to open and close explicitly or use a context manager. But for this it was simpler to do it this way.
so it is still not working for me. Traceback (most recent call last): File "D:\torrents\src\torrenthooker.py", line 15, in <module> qb.download_from_file([open(torrent_list, 'rb') for filename in torrent_list]) File "D:\torrents\src\torrenthooker.py", line 15, in <listcomp> qb.download_from_file([open(torrent_list, 'rb') for filename in torrent_list]) TypeError: expected str, bytes or os.PathLike object, not list
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.