torrentool

repository·master·Indexed 41 days ago

https://github.com/idlesign/torrentool

A Python tool and API for creating, reading, and modifying torrent files and handling bencoding. It includes a CLI for generating torrents from files or directories, inspecting .torrent metadata, and managing trackers and caching.

Tokens
1.1K
Snippets
6
Records
6
Agent score
1%

What's inside torrentool

  1. Install torrentool and its dependencies

    master

    To use the command line interface (CLI), you must install the click package. You can do this automatically using the [cli] extra with pip. Note that some commands may also require the requests package to be installed.

    pip install torrentool[cli]
  2. Create a new torrent from a directory or file with the Python API

    master

    Use Torrent.create_from(path) to generate a new torrent object from a single file or an entire directory. You can then configure properties like announce_urls before saving the result with .to_file(path).

    from torrentool.api import Torrent
    
    # Create a new torrent from a directory or single file
    new_torrent = Torrent.create_from('/home/idle/my_stuff/')
    new_torrent.announce_urls = 'udp://tracker.openbittorrent.com:80'
    new_torrent.to_file('/home/idle/another.torrent')
  3. Read and modify an existing torrent file with the Python API

    master

    Use the Torrent.from_file() method to load an existing torrent. You can access properties like total_size and magnet_link, or modify metadata like comment. Call .to_file() to persist changes.

    from torrentool.api import Torrent
    
    # Reading and modifying an existing file.
    my_torrent = Torrent.from_file('/home/idle/some.torrent')
    print(my_torrent.total_size)  # Total files size in bytes.
    print(my_torrent.magnet_link)  # Magnet link
    
    my_torrent.comment = 'Your torrents are mine.'  # Set a comment.
    my_torrent.to_file()  # Save changes.
  4. Use the torrentool CLI

    master

    The CLI provides commands to create torrents from files or directories, inspect existing torrent files, and manage trackers/caching.

    Common commands:

    • torrent create <path>: Creates a torrent from a file or directory.
    • torrent create <path> --open_trackers --cache: Creates a torrent with open trackers and publishes it to a torrent caching service.
    • torrent info <path>: Prints information about an existing .torrent file.

    Use the --help flag with any command to see more options.

    # Make .torrent out of `video.mkv`
    torrentool torrent create /home/my/files_here/video.mkv
    
    # Make .torrent out of a directory with open trackers and caching
    torrentool torrent create /home/my/files_here --open_trackers --cache
    
    # Print out existing file info
    torrentool torrent info /home/my/some.torrent
  5. Create a torrent file from a file or directory

    master

    Use the torrent create command to generate a new .torrent file from a single file or an entire directory.

    Arguments:

    • source: The path to the file or directory you want to turn into a torrent.

    Options:

    • --dest: The destination directory where the .torrent file will be saved. Defaults to the current working directory.
    • --tracker: A comma-separated list of tracker announce URLs to include.
    • --open_trackers: A flag that automatically adds a list of open tracker announce URLs to the torrent.
    • --comment: An arbitrary string to add as a comment to the torrent.
    • --cache: A flag that uploads the resulting .torrent file to torrent cache services after creation.

    Usage Example:

    torrentool torrent create /path/to/source --tracker "http://tracker1.com,http://tracker2.com" --comment "My new torrent" --cache
    torrentool torrent create /path/to/source --tracker "http://tracker1.com,http://tracker2.com" --comment "My new torrent" --cache
  6. Inspect a .torrent file with the info command

    master

    Use the torrent info command to print metadata from an existing .torrent file, including the name, file list, info hash, total size, and magnet link.

    Usage:

    torrentool torrent info <torrent_path>
    torrentool torrent info path/to/file.torrent