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

Add web-seed(s) to magnet link #186

Merged
merged 7 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ def test_magnet_no_announce(metafile2):
magnet_link = magnet(metafile2)
assert magnet_link.startswith("magnet")

def test_magnet_web_seed(metafile2):
"""
Test create magnet function scheme.
"""
magnet_link = magnet(metafile2)
meta = pyben.load(metafile2)
web_seed = meta["web-seed"]
assert quote_plus(web_seed) in magnet_link

def test_magnet_no_web_seed(metafile2):
"""
Test create magnet function scheme.
"""
meta = pyben.load(metafile2)
del meta["web-seed"]
pyben.dump(meta, metafile2)
magnet_link = magnet(metafile2)
assert magnet_link.startswith("magnet")

def test_magnet_empty():
"""
Expand Down
11 changes: 11 additions & 0 deletions torrentfile/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,17 @@ def magnet(metafile: str, version: int = 0) -> str:

magnet += trackers if trackers != "&tr=" else ""

if "url-list" in meta:
web_sources = [
"&ws=" + quote_plus(urllist) for urllist in meta["url-list"]
]
else:
web_sources = [""]

web_seed = "".join(web_sources)
alexpdev marked this conversation as resolved.
Show resolved Hide resolved

magnet += web_seed if web_seed != "&ws=" else ""

logger.info("Created Magnet URI %s", magnet)
sys.stdout.write("\n" + magnet + "\n")
return magnet
Expand Down