Code Monkey home page Code Monkey logo

demagnetize's Introduction

Project Status: Active — The project has reached a stable, usable state and is being actively developed. CI Status coverage pyversions MIT License

GitHub | PyPI | Issues | Changelog

demagnetize is a Python program for converting one or more BitTorrent magnet links into .torrent files by downloading the torrent info from active peers.

At the moment, demagnetize only supports basic features of the BitTorrent protocol. The following notable features are supported:

  • BitTorrent protocol v1
  • HTTP (including compact and IPv6 extensions) and UDP trackers
  • magnet URIs with info hashes encoded in either hexadecimal or base32
  • Fast extension (BEP 6)
  • UDP tracker protocol extensions (BEP 41)

The following features are not currently supported but are planned, in no particular order:

  • Encryption
  • Distributed hash tables
  • BitTorrent protocol v2
  • x.pe parameters in magnet links
  • uTP

demagnetize has also been translated by the author into Rust; you can find the Rust version at <https://github.com/jwodder/demagnetize-rs>.

Installation

demagnetize requires Python 3.10 or higher. Just use pip for Python 3 (You have pip, right?) to install it:

python3 -m pip install demagnetize

Usage

demagnetize [<global options>] <subcommand> ...

The demagnetize command has two subcommands, get (for converting a single magnet link) and batch (for converting a file of magnet links), both detailed below.

Global Options

-l LEVEL, --log-level LEVEL
 Set the log level to the given value. Possible values are "CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", and "TRACE" (all case-insensitive). [default value: INFO]

demagnetize get

demagnetize [<global options>] get [<options>] <magnet-link>

Convert a single magnet link specified on the command line to a .torrent file. (Note that you will likely have to quote the link in order to prevent it from being interpreted by the shell.) By default, the file is saved at {name}.torrent, where {name} is replaced by the value of the name field from the torrent info, but a different path can be set via the --outfile option.

Options

-o PATH, --outfile PATH
 Save the .torrent file to the given path. The path may contain a {name} placeholder, which will be replaced by the (sanitized) name of the torrent, and/or a {hash} placeholder, which will be replaced by the torrent's info hash in hexadecimal. Specifying - will cause the torrent to be written to standard output. [default: {name}.torrent]

demagnetize batch

demagnetize [<global options>] batch [<options>] <file>

Read magnet links from <file>, one per line (ignoring empty lines and lines that start with #), and convert each one to a .torrent file. By default, each file is saved at {name}.torrent, where {name} is replaced by the value of the name field from the torrent info, but a different path can be set via the --outfile option.

Options

-o PATH, --outfile PATH
 Save the .torrent files to the given path. The path may contain a {name} placeholder, which will be replaced by the (sanitized) name of each torrent, and/or a {hash} placeholder, which will be replaced by each torrent's info hash in hexadecimal. [default: {name}.torrent]

demagnetize's People

Contributors

dependabot[bot] avatar jwodder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

demagnetize's Issues

Support distributed hash tables

See BEP 5 et alii.

Use DHT if (and only if?) there are no trackers in a magnet URL.

It should be possible to specify the set of starting nodes for DHT in the configuration file (#1).

Support Maximum timeout for a magnet & Handle/Ignore the exception on bulk magnets

Hi @jwodder. Thanks for the wonderful implementation. I had an implementation to find the torrent information from magnet. i have used your library to implement that. It's working perfectly however for my custom requirement. I just only want to get the torrent information rather than creating torrent files. So I made custom changes to be able to work.

Implementation usage: https://github.com/mhdzumair/MediaFusion/blob/develop/utils/torrent.py#L92-L150

I would like to request for creating functions to use this as library which can be used for other project rather than only focusing cli usage.

Add a configuration file

demagnetize should be configurable via a TOML configuration file containing the following settings:

  • local port or port range to report to trackers
  • whether to actually listen on (and reject incoming connections to) the local port
  • the numwant value to send to trackers
  • local bind address
  • whether to use IPv4
  • whether to use IPv6
  • maximum number of magnet links to process at once in batch mode
  • maximum number of trackers to connect to at once per magnet link
  • maximum number of peers to connect to at once per magnet link
  • tracker timeouts
  • general peer interaction timeout?
  • maximum size of incoming packets to accept from peers?

The CLI should also have a dump-config subcommand for outputting the current configuration with explanatory comments above each field (good for creating a new config file).

Use asyncio directly to align some of the behavior with the Rust version

  • Fetch data from a limited number of peers at once

    • Use asyncio.wait(..., return_when=FIRST_COMPLETED) to run up to <limit> peer tasks at once, adding a new peer whenever a previous one errors
      • Use a similar strategy to replace/rewrite acollect()
      • Would this implementation strategy have the same issues as those motivating jwodder/demagnetize-rs#65?
  • Spawn tasks for independently sending "stopped" announcements to trackers

    • How can I ensure that the event loop waits "on drop" for these to complete? Would I have to pass the tracker a task group in which to run the "stop" announcements?

Obviously, this will mean dropping support for trio.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.