From f79c54f9938a8dbc5be066a1d84aaf066fe3528e Mon Sep 17 00:00:00 2001 From: death916 Date: Wed, 17 Dec 2025 05:09:33 -0800 Subject: [PATCH] added dotenv lib to get from file --- pyproject.toml | 1 + shell.nix | 1 + src/c2cscrape.py | 39 ++++++++++++++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5fa48f7..99ddbaf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ readme = "README.md" requires-python = ">=3.13" dependencies = [ "bs4>=0.0.2", + "python-dotenv>=1.2.1", "qbittorrent-api>=2025.11.1", "requests>=2.32.5", ] diff --git a/shell.nix b/shell.nix index 52b6715..aab6af8 100644 --- a/shell.nix +++ b/shell.nix @@ -8,6 +8,7 @@ pkgs.mkShell { python313Packages.uv python313Packages.ninja python313Packages.numpy + python313Packages.ipython bun ]; diff --git a/src/c2cscrape.py b/src/c2cscrape.py index a022b91..e2f2093 100644 --- a/src/c2cscrape.py +++ b/src/c2cscrape.py @@ -7,9 +7,10 @@ import random import re import time -import qbittorrentapi as qb +import qbittorrentapi as qbapi import requests from bs4 import BeautifulSoup +from dotenv import load_dotenv logging.basicConfig( level=logging.INFO, @@ -46,7 +47,7 @@ class TorrentScrape: logging.error(f"Error fetching page: {e}") return None - def get_episode_info(self): + def get_torrent_link(self): page = self.get_torrent_page() if not page: logging.error("No page found") @@ -100,19 +101,47 @@ class Qbittorrent: def get_credentials(self): # Get qbittorrent credentials from .env file + load_dotenv() # gets credentials from env file self.username = os.getenv("QB_USERNAME") self.password = os.getenv("QB_PASSWORD") + self.host = os.getenv("QB_HOST") + self.port = os.getenv("QB_PORT") if not self.username or not self.password: raise ValueError("QB_USERNAME and QB_PASSWORD must be set in .env file") def add_torrent(self, link): - # Add torrent to qbittorrent - pass + conn_info = dict( + host=self.host, + port=self.port, + username=self.username, + password=self.password, + ) + torrent = qbapi.Client(**conn_info) + try: + torrent.auth_log_in() + logging.info("Logged in to qbittorrent") + + except qbapi.LoginFailed: + logging.error("Failed to login to qbittorrent") + raise + except Exception as e: + logging.error(f"Error adding torrent to qbittorrent: {e}") + raise + + +def main(): + qbit = Qbittorrent() + qbit.get_credentials() + qbit.add_torrent(link) if __name__ == "__main__": c2c = TorrentScrape() - c2c.get_episode_info() + # c2c.get_torrent_link() + link = c2c.get_torrent_link() + torrent = Qbittorrent() + torrent.get_credentials() + torrent.add_torrent(link) # Keep main thread alive with minimal resource usage """ try: