1

I have a .torrent file that contains a .bz2 file. I am sure that such a file is actually in the .torrent because I extracted the .bz2 with utorrent.

How can I do the same thing in python instead of using utorrent?

I have seen a lot of libraries for dealing with .torrent files in python but apparently none does what I need. Among my unsuccessful attempts I can mention:

import torrent_parser as tp
file_cont = tp.parse_torrent_file('RC_2015-01.bz2.torrent')

file_cont is now a dictionary and file_cont['info']['name']='RC_2015-01.bz2' but if I try to open the file, i.e.

from bz2 import BZ2File
with BZ2File(file_cont['info']['name']) as f:
    what_I_want = f.read() 

then the content of the dictionary is (obviously, I'd say) interpreted as a path, and I get

No such file or directory: 'RC_2015-01.bz2'

Other attempts have been even more ruinous.

GRquanti
  • 527
  • 8
  • 23
  • 1
    You realize `.torrent` files don't contain the file itself, right? You need to download (via the BitTorrent protocol) the file before a file with such a name exists. – ShadowRanger Feb 19 '19 at 21:46
  • And python doesn't allow to do so? – GRquanti Feb 19 '19 at 21:50
  • You could use (or write) a library to actually perform the download, but Python doesn't magically do it for you. It's magic, but not *that* magic. – ShadowRanger Feb 19 '19 at 23:47
  • Yeah, I strongly relies on python being magic and on other people (WAY better than me with python) writing libraries. – GRquanti Feb 20 '19 at 03:47

1 Answers1

1

A .torrent file is just a metadata file, indicating where to get the data and the filename of the file. You can't get the file contents from that file.

Only once you have successfully downloaded this torrent file to disk (using torrent software) you can then use BZ2File to open it (if it is .bz2 format).

If you want to perform the actual download with Python, the only option I found was torrent-dl which hasn't been updated for 2 years.

mfitzp
  • 15,275
  • 7
  • 50
  • 70