0
votes

I've searched all around the web on how to download torrent files via python. The only thing I've managed to find was libtorrent, the problem with it, is that there is no clear documentation.

My initial goal is at least to connect the stream while it's downloading, to a cv2 window, to stream it.

I've managed to do it with youtube, and to transfer the mp4 file to the window, and to stream it (using Pyfy), is there a way to do it with python?

or I'm going too far, and it's possible to download the torrent content using requests or something?

1
If you are interested in torrent streaming, there a few great libraries in NodeJS, like github.com/KiraLT/torrent-stream-server and webtorrent.io. Unfortunately, python doesn't have something like that (I searched a while back but did not find any decent library).KiraLT
That's the thing, I wanted to build something like Stremio, which is build using NodeJS. Well, guess Ill have to study Node first.Slava Bugz
If you have a lot of patience, you can still try using python. I found some libraries, but they didn't have any documentation. I tried reading source code, but I lost patience and moved to NodeJS. In the future, I am planning to go back & try using python, unless I will solve all NodeJS performance issues. In any case, you can join on github.com/KiraLT/torrent-stream-server project, any help would be appreciated.KiraLT

1 Answers

1
votes

BitTorrent isn't like HTTP. Files are downloaded and uploaded out of order. Files need to be saved to disk, partly to be able to upload it later, and partly because files (generally) aren't useful until the whole file has been downloaded. The files are reconstructed on disk.

If you want to stream content from a torrent, you have to do some extra steps yourself.

libtorrent has set_piece_deadline() (docs) to indicate that you want a piece soon, it will affect the piece picker to prioritize that piece. You can also set a flag (alert_when_available) to indicate that you want a notification (alert) when the data is available, along with the buffer.