Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop non critical metainfo instead of erroring? #41

Open
Ravencentric opened this issue Apr 6, 2024 · 2 comments
Open

Drop non critical metainfo instead of erroring? #41

Ravencentric opened this issue Apr 6, 2024 · 2 comments

Comments

@Ravencentric
Copy link
Contributor

I recently encountered this torrent file in the wild and it has one invalid tracker url out of many.

Trying to read it raises a metainfo error

Traceback (most recent call last):
  File "C:\Users\raven\Documents\GitHub\TEST\test.py", line 10, in <module>
    torrent = Torrent.read_stream(BytesIO(open(path, "rb").read()))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\raven\Documents\GitHub\TEST\.venv\Lib\site-packages\torf\_torrent.py", line 1632, in read_stream
    torrent.validate()
  File "c:\Users\raven\Documents\GitHub\TEST\.venv\Lib\site-packages\torf\_torrent.py", line 1388, in validate
    utils.assert_type(md, ('announce-list', i, j), (str,), check=utils.is_url)
  File "c:\Users\raven\Documents\GitHub\TEST\.venv\Lib\site-packages\torf\_utils.py", line 727, in assert_type
    raise error.MetainfoError(f"{keychain_str}[{key!r}] is invalid: {obj[key]!r}")
torf._errors.MetainfoError: Invalid metainfo: ['announce-list'][4][0] is invalid: '*udp://9.rarbg.to:2710/announce'

I understand this is an invalid URL but is it possible to drop invalid metainfo instead of erroring? especially non critical ones like this where there are several more working trackers. This is a perfectly downloadable torrent and clients like Qbit simply report it as unsupported while continuing to download it

image

Possibly a strict: bool = True flag in read() and read_stream() where:

  • True behaves like the current behavior, erroring at any metainfo error
  • False drops non critical info instead of erroring

Thank you

@Ravencentric
Copy link
Contributor Author

Ravencentric commented Apr 6, 2024

Using https://torf.readthedocs.io/en/latest/#torf.Torrent.validate is an option but it's not exactly the same. validate=False will no longer error but it'll still end up with an invalid torrent file while my proposal basically means torf will attempt to get a valid file out of a invalid one by dropping non critical invalid data. Torf should raise an error if the torrent file is still invalid after dropping as many non critical data as it could

I've also noticed that despite validate=False, property access still errors:

from torf import Torrent

path = r"C:\Users\raven\Downloads\[New-raws] Bucchigiri - 12 END [1080p] [AMZN].mkv.torrent"

torrent = Torrent.read(path, validate=False)

print(torrent.trackers) # Errors
print(torrent.infohash) # Errors

@rndusr
Copy link
Owner

rndusr commented Apr 6, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants