Skip to content
Ysn4IrixPublic

About

Interactive Python CLI for searching movies and TV series magnet links via apibay.org

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

16 Commits

Folders and files

Repository files navigation

tpb-cli πŸ΄β€β˜ οΈ

Python License Tests Code Style

A fast, interactive Python CLI and automation tool for searching movies and TV series, selecting episodes/seasons across quality releases, and batch-exporting magnet links via the apibay.org (The Pirate Bay) backend.


✨ Features

  • πŸ” Immediate Search & Discovery:
    • Automatically queries the backend immediately after you enter a show title.
    • Scans results upfront to determine total releases, codecs, and qualities.
  • πŸ“Ί Auto-Detected Season Selector:
    • Analyzes search results to detect all available seasons.
    • Displays episode counts and complete pack counts for each season (e.g., Season 1 (10 episodes, 3 packs)), eliminating guesswork.
  • 🌐 Series Disambiguation:
    • Automatically identifies regional variants (e.g., The Office US vs The Office UK) and prompts you to select the exact version you want.
  • πŸŽ›οΈ Multi-Quality Episode Picker:
    • Groups results by episode number (E01, E02, ...).
    • Pre-selects the healthiest release per episode by default.
    • Allows switching or selecting alternate qualities (1080p, 720p, 2160p / 4K, SD, x265, x264) directly from an interactive checklist.
  • πŸ“¦ Season Packs vs Individual Episodes:
    • Detects full season packs and lets you grab a complete pack in one click or pick and choose individual episodes.
  • 🎬 Movie Search & High-Quality Filters:
    • Fast search with rich metadata tables (seeders, leechers, file size, codec, VIP/Trusted uploader tags).
  • ⚑ Zero-Lag Back Navigation:
    • Press Esc, b, q, or ← at any step to instantly return to the previous screen (configured with sub-10ms key sequence timeouts).
    • In-memory query caching ensures backing up doesn't repeat slow network requests.
  • πŸ’Ύ Smart Export Workflows:
    • Save magnet links to text files (.txt) with pre-filled smart filenames (e.g., breaking_bad_S01_magnets.txt).
    • File collision resolution: overwrite or append to existing link lists.
    • Print links directly to the terminal or both save and print.
    • High-reliability public trackers are automatically embedded in generated magnet links.
  • πŸ›‘οΈ Scriptable & Resilient:
    • Run interactively (TUI) or automate batch exports using CLI flags.
    • Custom proxy support (HTTP / SOCKS5) and custom API base URLs.
    • CP1252-safe console rendering for Windows terminals.

πŸš€ Installation

Prerequisites

  • Python 3.10 or higher
  • Git

Option 1: Direct Install via pip (Recommended)

Install the lightweight CLI directly from GitHub:

pip install git+https://github.com/Ysn4Irix/tpb-cli.git

Or include the optional PySide6 Desktop GUI ([gui] extra):

pip install "tpb-cli[gui] @ git+https://github.com/Ysn4Irix/tpb-cli.git"

Or install from a pre-built wheel:

pip install tpb_cli-0.3.0-py3-none-any.whl

Option 2: Local / Development Install

# Clone the repository
git clone https://github.com/Ysn4Irix/tpb-cli.git
cd tpb-cli

# Install CLI + GUI + dev/packaging dependencies in editable mode
pip install -e ".[gui,dev]"

After installation, tpb (CLI) and tpb-gui (Desktop GUI, when [gui] is installed) are available in your terminal.


πŸ–₯️ Desktop GUI Mode

Launch the native desktop window (PySide6):

tpb-gui
# or via CLI flag:
tpb --gui

Desktop GUI Highlights

  • TV Series Browser: Regional disambiguation chips (US, UK, All), auto-detected Season list with episode & pack counts, Season Packs table, and an interactive Episode Quality Matrix (all results start unchecked by default, with a one-click Select Recommended action and automatic single-quality switching per episode).
  • Movies & General Search: Live-filterable and numerically sortable release table with VIP/Trusted uploader tags and resolution/codec indicators.
  • Torrent File Inspector: Click any release to asynchronously fetch and inspect internal file paths and sizes (ApibayClient.get_files).
  • Batch Magnet Handoff: Copy selected magnets to clipboard, launch staggered magnet: URIs in your default torrent client (with safety confirmation for large batches > 5), or export .txt with Overwrite/Append prompt.
  • Library & Settings: Dark Mode (default) / Light Mode toggle (Ctrl+T), persistent search history & bookmarks sidebar, and Apibay mirror / HTTP & SOCKS5 proxy configuration (Ctrl+,).

Building a Standalone Windows .exe

.\packaging\build_exe.ps1

This bundles dist\tpb-gui.exe using PyInstaller with console suppression (--windowed).


πŸ“– Usage

1. Interactive Mode (Default)

Simply run tpb without arguments:

tpb

Or via Python module:

python -m tpb.cli

Step-by-Step Flow:

  1. Choose Category: Select between TV Series, Movies, or General Search.
  2. Enter Title: Type in the show or movie title (e.g., Severance, The Office).
  3. Disambiguation (if applicable): If multiple series versions exist (e.g., US vs UK), choose your preferred version.
  4. Select Season: Pick from auto-detected seasons with release statistics.
  5. Quality Filter: Filter by 1080p, 720p, 2160p, or Any.
  6. Pack or Episodes: Grab a complete Season Pack or select individual episodes.
  7. Episode Checklist: Use [Space] to toggle, [a] to select all, and [Enter] to confirm.
  8. Export: Save to file and/or print magnet links to the terminal.

πŸ’‘ Navigation Tip: Press Esc, b, q, or ← anytime to jump back to the previous menu step.


2. Scriptable CLI Mode

You can automate search and export directly using CLI flags:

Download complete season to a text file:

tpb "Severance" -s 1 -q 1080p -o severance_s1.txt

Prefer complete season pack if available:

tpb "Breaking Bad" -s 1 --pack -o bb_s1.txt

Search movie and print top magnet link to console:

tpb "Inception" -q 1080p --print

Append search results to an existing link file:

tpb "Better Call Saul" -s 1 -q 720p -o series_links.txt

Use a custom mirror or SOCKS5 proxy:

tpb "The Matrix" --proxy "socks5://127.0.0.1:9050" --api-url "https://apibay.org"

πŸ› οΈ CLI Options Reference

Flag Long Flag Description
query Search query string (movie or TV title). Omit to launch interactive mode.
-s --season TV Show season number (e.g. 1, 2).
-q --quality Resolution preference: 2160p, 1080p, 720p, 480p, or any.
-o --output Destination file path to save magnet links (.txt).
-p --print Print magnet links to terminal stdout.
--pack Prefer complete season pack over individual episodes.
-i --interactive Force interactive TUI even if a query argument was passed.
--gui Launch the PySide6 desktop GUI (tpb-cli[gui]).
--api-url Custom Apibay backend URL (Default: https://apibay.org).
--proxy HTTP or SOCKS5 proxy URL (e.g. socks5://127.0.0.1:9050).
-v --version Display program version and exit.
-h --help Show command line options and help message.

πŸ“ Project Architecture

tpb-cli/
β”œβ”€β”€ .github/workflows/
β”‚   β”œβ”€β”€ ci.yml             # Lint, format, typecheck, security, cross-OS tests & build
β”‚   └── release.yml        # Tagged release automation (.whl, .tar.gz & tpb-gui.exe)
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ tpb-cli.md         # CLI design notes
β”‚   └── tpb-desktop-gui.md # Desktop GUI implementation plan & checklist
β”œβ”€β”€ tpb/
β”‚   β”œβ”€β”€ __init__.py        # Package initialization & version metadata
β”‚   β”œβ”€β”€ api.py             # ApibayClient, URL/proxy validation, cache lock & file normalization
β”‚   β”œβ”€β”€ cli.py             # Argument parsing, --gui launcher & headless automation
β”‚   β”œβ”€β”€ exporter.py        # File export, magnet formatters & Rich tables
β”‚   β”œβ”€β”€ interactive.py     # Interactive TUI, state machine & 0ms back navigation
β”‚   β”œβ”€β”€ models.py          # Torrent/TorrentFile dataclasses, formatting & coercion
β”‚   β”œβ”€β”€ parser.py          # Regex parsers for seasons, episodes, quality & codecs
β”‚   └── gui/               # Optional PySide6 desktop interface (pip install tpb-cli[gui])
β”‚       β”œβ”€β”€ assets/        # Multi-resolution Cyan Vector Magnet PNG/ICO icons & loader
β”‚       β”œβ”€β”€ app.py         # QApplication bootstrap & tpb-gui entrypoint
β”‚       β”œβ”€β”€ column_state.py# Persistent interactive table & tree column widths
β”‚       β”œβ”€β”€ main_window.py # Desktop window shell, search bar, loading & workspace states
β”‚       β”œβ”€β”€ state.py       # Persistent settings, dark/light theme, history & bookmarks
β”‚       β”œβ”€β”€ theme.py       # Dark & Light QSS stylesheets and palette tokens
β”‚       β”œβ”€β”€ workers.py     # QThreadPool async workers with cancellation & stale guards
β”‚       β”œβ”€β”€ views/         # TV Series browser & Movie/General sortable results table
β”‚       └── widgets/       # File Inspector, Magnet ActionBar, Library drawer & Settings
β”œβ”€β”€ packaging/
β”‚   β”œβ”€β”€ tpb-gui.spec       # PyInstaller Windows --windowed spec
β”‚   └── build_exe.ps1      # Standalone .exe build script
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ conftest.py        # Headless QT_QPA_PLATFORM=offscreen setup
β”‚   β”œβ”€β”€ test_api.py        # API client and response mocking tests
β”‚   β”œβ”€β”€ test_exporter.py   # File writer & dict resilience tests
β”‚   β”œβ”€β”€ test_gui_state.py  # GUI settings, URL validation, history, bookmarks & CLI --gui tests
β”‚   β”œβ”€β”€ test_gui_views.py  # Offscreen Qt widget/view/action-bar tests
β”‚   β”œβ”€β”€ test_gui_workers.py# Async worker fallback, cancellation & stale-request tests
β”‚   β”œβ”€β”€ test_interactive.py# Navigation, series disambiguation & prompt tests
β”‚   β”œβ”€β”€ test_models.py     # Dataclass properties & tracker verification
β”‚   └── test_parser.py     # TV metadata extraction & episode grouping tests
β”œβ”€β”€ AGENTS.md              # Project engineering, security, UI & CI/CD rules
β”œβ”€β”€ CHANGELOG.md           # Keep-a-Changelog release history (SemVer)
β”œβ”€β”€ pyproject.toml         # Build configuration, [gui]/[dev] extras & tool settings
β”œβ”€β”€ MANIFEST.in            # Distribution manifest rules
β”œβ”€β”€ requirements.txt       # Direct core runtime dependencies
└── README.md              # Project documentation

πŸ§ͺ Running Tests & Quality Checks

The test suite covers API queries, metadata parsing, interactive TUI navigation, file exports, and offscreen PySide6 GUI workflows:

# Run full test suite
pytest -v

# Linting, formatting, and type checks
ruff check tpb tests
ruff format --check tpb tests
mypy tpb

# Security & dependency vulnerability scans
bandit -r tpb -ll
pip-audit --skip-editable

πŸ”„ CI/CD Pipeline & Release Process

This repository includes GitHub Actions workflows in .github/workflows/:

  1. Continuous Integration (ci.yml):
    • Triggered automatically on pushes and pull requests to master/main.
    • Enforces least-privilege contents: read permissions and pip caching.
    • Fails fast across sequential gates:
      • Quality: ruff format --check, ruff check, and mypy.
      • Security: bandit -r tpb -ll static analysis and pip-audit dependency scan.
      • Test Matrix: pytest -v with QT_QPA_PLATFORM=offscreen across Ubuntu & Windows (Python 3.10–3.14).
      • Package Build: python -m build and twine check dist/*.
  2. Release Automation (release.yml):
    • Triggered on SemVer tags matching v*.*.* (for example v0.3.0).
    • Re-runs full lint, formatting, type, security, and cross-platform test verification before building release binaries (tpb_cli-*.whl, tpb_cli-*.tar.gz, and Windows standalone tpb-gui.exe).
    • Extracts matching version notes from CHANGELOG.md and publishes the GitHub Release under scoped contents: write permission.
    • Local release checklist before tagging:
      1. Bump version in pyproject.toml and __version__ in tpb/__init__.py (MAJOR.MINOR.PATCH).
      2. Update CHANGELOG.md and commit with a Conventional Commit (e.g., chore(release): prepare v0.3.0).
      3. Wait for all CI checks to pass before creating and pushing a vX.Y.Z tag.

🀝 Contributing

Contributions, issues, and feature requests are welcome!

  1. Fork the project.
  2. Create your feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes (git commit -m "feat: add amazing feature").
  4. Run tests (pytest -v).
  5. Push to the branch (git push origin feature/amazing-feature).
  6. Open a Pull Request.

πŸ“„ License

This project is licensed under the MIT License.

About

Interactive Python CLI for searching movies and TV series magnet links via apibay.org

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages