cleanup and works. adds torrents to client

This commit is contained in:
death916 2025-12-23 03:39:16 -08:00
parent 60a7d441f6
commit 83e53bba5c

View file

@ -1,11 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import datetime
import logging import logging
import os import os
import random
import re
import time
import qbittorrentapi as qbapi import qbittorrentapi as qbapi
import requests import requests
@ -32,10 +28,6 @@ class TorrentScrape:
self.episodes_downloaded = 0 self.episodes_downloaded = 0
self.download_location = "/downloads" self.download_location = "/downloads"
def sanitize_filename(self, filename):
# Remove or replace invalid filename characters
return re.sub(r'[<>:"/\\|?*]', "-", filename)
def get_torrent_page(self): def get_torrent_page(self):
try: try:
response = requests.get(self.url, headers=self.headers) response = requests.get(self.url, headers=self.headers)
@ -63,9 +55,7 @@ class TorrentScrape:
episode_elems = main_class.select(".text-wrap.w-100") episode_elems = main_class.select(".text-wrap.w-100")
if episode_elems: if episode_elems:
print( print(f"Found {len(episode_elems)} episodes")
f"Found {len(episode_elems)} episode elements using selector .text-wrap.w-100"
)
if len(episode_elems) > self.download_amount: if len(episode_elems) > self.download_amount:
logging.info( logging.info(
f"Too many episodes found, only downloading last {self.download_amount}" f"Too many episodes found, only downloading last {self.download_amount}"
@ -125,6 +115,8 @@ class Qbittorrent:
torrent.auth_log_in() torrent.auth_log_in()
logging.info("Logged in to qbittorrent") logging.info("Logged in to qbittorrent")
logging.info(f"qbittorrent version: {torrent.app.version}") logging.info(f"qbittorrent version: {torrent.app.version}")
torrent.auth_log_out()
logging.info("Logged out of qbittorrent")
except qbapi.LoginFailed: except qbapi.LoginFailed:
logging.error("Failed to login to qbittorrent") logging.error("Failed to login to qbittorrent")
@ -133,7 +125,7 @@ class Qbittorrent:
for link in links: for link in links:
try: try:
torrent.torrents_add(urls=link, save_path=self.download_path) torrent.torrents_add(urls=link, save_path=self.download_path)
logging.info(f"Added torrent {link} to qbittorrent") logging.info(f"Added torrent {link} to qbittorrent")
except Exception as e: except Exception as e:
logging.error(f"Error adding torrent {link} to qbittorrent: {e}") logging.error(f"Error adding torrent {link} to qbittorrent: {e}")
raise raise
@ -150,7 +142,6 @@ if __name__ == "__main__":
torrent = Qbittorrent() torrent = Qbittorrent()
torrent.get_credentials() torrent.get_credentials()
torrent.add_torrent(link) torrent.add_torrent(link)
# Keep main thread alive with minimal resource usage
""" """
try: try:
while True: while True: