Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions cinecli/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .cli import app

app()
11 changes: 6 additions & 5 deletions cinecli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def watch(movie_id: int):


default_action = config.get("default_action", "magnet")
transmission = config.get("transmission", {})
open_method = "Transmission client" if transmission.get("enable", False) else "web browser"

action = Prompt.ask(
"Choose action",
Expand All @@ -100,12 +102,11 @@ def watch(movie_id: int):
torrent["hash"],
f"{movie['title']} {torrent['quality']}",
)
open_magnet(magnet)
console.print("[green]🧲 Magnet link opened in your torrent client![/green]")
open_magnet(magnet, transmission)
console.print(f"[green]🧲 Magnet link opened in your {open_method}![/green]")
else:
download_torrent(torrent["url"])
console.print("[green]⬇ Torrent file download started in browser.[/green]")

download_torrent(torrent["url"], transmission)
console.print(f"[green]⬇ Torrent file download started in your {open_method}.[/green]")
# -------------------------------------------------
# Interactive command
# -------------------------------------------------
Expand Down
15 changes: 11 additions & 4 deletions cinecli/magnets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import webbrowser
import urllib.parse
from transmission_rpc import Client

TRACKERS = [
"udp://open.demonii.com:1337/announce",
Expand All @@ -13,11 +14,17 @@ def build_magnet(hash_: str, name: str) -> str:
dn = urllib.parse.quote(name)
return f"magnet:?xt=urn:btih:{hash_}&dn={dn}{trackers}"

def open_magnet(magnet_url: str):
webbrowser.open(magnet_url)
def open_magnet(magnet_url: str, transmission: dict = {}):
download_torrent(magnet_url, transmission)

def download_torrent(url: str, transmission: dict = {}):
if transmission.get("enable", False):
client_options = { k : v for k, v in transmission.items() if k != "enable" }
Client(**client_options).add_torrent(url)
else:
webbrowser.open(url)


def download_torrent(torrent_url: str):
webbrowser.open(torrent_url)
def select_best_torrent(torrents: list[dict]) -> dict:
"""
Pick the torrent with the highest quality and seeds.
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
requests
rich
typer
transmission-rpc
];

pyproject = true;
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ authors = [
dependencies = [
"typer>=0.9",
"rich>=13.0",
"requests>=2.28"
"requests>=2.28",
"transmission-rpc>=7.0",
]

keywords = [
Expand Down