sweetbbak / toru

Bittorrent streaming CLI tool. Stream anime torrents, real-time with no waiting for downloads.
MIT License
281 stars 8 forks source link
anime bittorrent cli torrent webrtc




Toru: Stream Torrents instantly, straight from the Command Line

Toru, the command line tool designed for anime enthusiasts. Browse the latest releases on nyaa.si or search for specific titles with Toru's intuitive interface. Stream episodes directly from the command line using MPV or your favorite video player or browser. Toru serves the selected anime over localhost, making it as accessible as any HTTP link. It also functions as a convenient torrent client for magnet links. Simplify your streaming and torrenting with Toru.

https://github.com/sweetbbak/toru/assets/75046310/4a2a8c2e-3a11-4771-b79e-66e4de77a8b8

Table of Contents

Install

Quick install a pre-built binary

export PREFIX="$HOME/bin"
wget "https://github.com/sweetbbak/toru/releases/download/v0.1/toru_$(uname -s)_$(uname -m).tar.gz" -O - | tar -xz
mv toru "${PREFIX}"

on Windows

iwr -Uri "https://github.com/sweetbbak/toru/releases/download/v0.1/toru_Windows_x86_64.zip" -OutFile toru_Windows_x86_64.zip

With Nix

nix profile install github:sweetbbak/toru
Install Go Install go This project requires go 1.21.7 or higher.
go install github.com/sweetbbak/toru/cmd/toru@latest
Build from source using Go is recommended alongside `gup` so that it can be easily updated ```sh git clone https://github.com/sweetbbak/toru.git && cd toru go build -o toru ./cmd/toru ``` you can also use the justfile ```sh git clone https://github.com/sweetbbak/toru.git && cd toru just ``` or the makefile ```sh git clone https://github.com/sweetbbak/toru.git && cd toru make build ``` Using `docker`, `podman` with the `shell.nix` file on non-nixOS distros this will automatically pull the correct version of Go and install `just` so that building is easy. ```sh git clone https://github.com/sweetbbak/toru.git && cd toru # mount the project directory inside the container podman run --volume $(pwd):/toru -ti docker.io/nixos/nix:latest # inside the container run: cd /toru nix-shell just ``` ### Building for different platforms and architectures Run to find your target architecture and platform: ```sh go tool dist list ``` then use the environment variables `GOOS` and `GOARCH` before using the build command. Example: ```sh GOOS=linux GOARCH=arm64 go build -o toru ./cmd/toru ``` _If you do this_ feel free to create an issue for a platform reporting how it went So far there is an issue with android and termux as well as arm 6.

if you are on nix or have nix installed you can just use the shell.nix directly and run just or make

Examples

Search for an anime:

toru search -j "one piece" # outputs json
toru search -i "one piece" # search interactively with fzf

example of toru in progress

the selected torrent will begin playing and once the video player is closed you will have the option to select another episode, make another search query, or to exit.

View the latest anime on nyaa.si in an interactive fzf session

toru search --latest

Search for a specific keyword or series

toru search "Akuyaku"

If you know the magnet link for the content you can directly download or stream it

toru stream --magnet 'magnet:?xt=urn:btih:1...announce'
toru download --magnet 'magnet:?xt=urn:btih:1...announce'

All of the above outputs a link that you can use to stream the torrent 'http://localhost:8080/stream?ep=torrent_info_hash' you can treat this link like any other http link and stream it with mpv or vlc, download it, use yt-dlp, or open it in the browser etc...

Use a proxy Nyaa site

this can be helpful for geoblocking and for browsing "special" Nyaa sites

toru search --proxy="https://sukebei.nyaa.si" -i
toru search --proxy="https://nyaa.ink.iss" -i

Handling input and output

You can use toru to search for anime and other media types and then output the results in multiple formats. Output in Json and parsing that output with jq:

toru search --latest --json | jq -r '.[]|.Name,.Magnet'

Open a cached search session from a json file

toru search --json "one piece" > cache.json
toru search --from-json cache.json --interactive

Output in a human readable format:

toru search "akuyaku 99 1080p"
# Outputs:
[Erai-raws] Akuyaku Reijou Level 99 - 01 [1080p][Multiple Subtitle] [ENG][POR-BR][SPA-LA][SPA][ARA][FRE][GER][ITA][RUS]
2024-01-09 07:36:29
Downloads: 1203
[33|0]
Size: 727 MB
magnet:... [ magnet link here ]

Creating your own CLI tool using toru

# Create a JSON file using toru
toru search --latest --json > out.json
# Here is a simple example of using fzf and toru to create a simple interace to select and play torrents
# you can also replace toru with any CLI bittorrent client
cat out.json | jq '.[].Name' | \
fzf --preview='cat out.json | jq -r ".[{n}]"' \
  --bind "enter:become(cat out.json | jq -r '.[{n}].Magnet')" | \
  xargs toru stream --magnet

Shell completions

ZSH

installing bash completions

source <(toru init --zsh)

BASH

installing bash completions

source <(toru init --bash)

[!IMPORTANT]\ toru is in a very early development phase! In order to provide a consistent and smooth experience the CLI interface is subject to change. PR's and advice on project sturcture, pkg organization and feedback on the UI of toru is much appreciated.

Currently tested on Linux, Mac and Windows I would much appreciate someone reporting on the functionality on any BSD, or any other niche device or architecture Android with termux currently has UDP issues. Idk much about how android works

Features

Changelog

2024-05-21

2024-03-1

Good issues to work on

Roadmap

Contributing

Fork it!
Create your feature branch: git checkout -b my-new-feature
Commit your changes: git commit -m 'Add some feature'
Push to the branch: git push origin my-new-feature
Submit a pull request 🤘

PR's welcome! This project currently uses Golang 1.22.2 make sure to format go files using gofmt and alejandra for nix. I'm likely to reject PR's that are directly to main unless they are small or are regarding typos, the readme or documentation.

Why though?

Because scraping is annoying af and it constantly breaks. On top of that, someone is paying for those servers. Torrents are more resistant to takedowns and hopefully will have more longevity.

Credits

torrenting library: anacrolix/torrent

Nyaa package is modified from here: Feyko/nyaa-go

Support

Consider creating a PR, taking up a minor issue on the TODO list, leaving an issue to help improve functionality or buy me a coffee!

moe-visitor-counter moe