mirror of
https://github.com/Death916/c2cscrape.git
synced 2026-04-10 03:04:40 -07:00
add logging and start qbit impl
This commit is contained in:
parent
d73b179181
commit
97df6d10d7
3 changed files with 40 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -90,3 +90,4 @@ uv.lock
|
||||||
old.pyproject.toml
|
old.pyproject.toml
|
||||||
.github
|
.github
|
||||||
.flox
|
.flox
|
||||||
|
.gitignore
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,6 @@ readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bs4>=0.0.2",
|
"bs4>=0.0.2",
|
||||||
|
"qbittorrent-api>=2025.11.1",
|
||||||
"requests>=2.32.5",
|
"requests>=2.32.5",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,22 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import qbittorrentapi as qb
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format="%(asctime)s - %(levelname)s - %(message)s",
|
||||||
|
datefmt="%Y-%m-%d %H:%M:%S",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TorrentScrape:
|
class TorrentScrape:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -31,16 +39,17 @@ class TorrentScrape:
|
||||||
try:
|
try:
|
||||||
response = requests.get(self.url, headers=self.headers)
|
response = requests.get(self.url, headers=self.headers)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
print(response)
|
logging.info(f"Page fetched successfully")
|
||||||
|
logging.debug(f"Response status code: {response.status_code}")
|
||||||
return response.text
|
return response.text
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
print(f"Error fetching page: {e}")
|
logging.error(f"Error fetching page: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_episode_info(self):
|
def get_episode_info(self):
|
||||||
page = self.get_torrent_page()
|
page = self.get_torrent_page()
|
||||||
if not page:
|
if not page:
|
||||||
print("No page found")
|
logging.error("No page found")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
soup = BeautifulSoup(page, "html.parser")
|
soup = BeautifulSoup(page, "html.parser")
|
||||||
|
|
@ -56,7 +65,7 @@ class TorrentScrape:
|
||||||
f"Found {len(episode_elems)} episode elements using selector .text-wrap.w-100"
|
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:
|
||||||
print(
|
logging.info(
|
||||||
f"Too many episodes found, only downloading last {self.download_amount}"
|
f"Too many episodes found, only downloading last {self.download_amount}"
|
||||||
)
|
)
|
||||||
episode_elems = episode_elems[: self.download_amount]
|
episode_elems = episode_elems[: self.download_amount]
|
||||||
|
|
@ -67,19 +76,38 @@ class TorrentScrape:
|
||||||
title = a.get("title") or a.get_text(strip=True)
|
title = a.get("title") or a.get_text(strip=True)
|
||||||
# skip episodes that don't start with "Coast" as sometimes they show up in search
|
# skip episodes that don't start with "Coast" as sometimes they show up in search
|
||||||
if not title.startswith("Coast"):
|
if not title.startswith("Coast"):
|
||||||
print(f"Skipping episode {title}")
|
logging.warning(
|
||||||
|
f"Skipping episode {title}, as it doesn't start with 'Coast'"
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
link = a.get("href")
|
link = a.get("href")
|
||||||
self.episodes_downloaded += 1
|
self.episodes_downloaded += 1
|
||||||
print(f"found episode {title}")
|
logging.info(f"found episode {title}")
|
||||||
# print(f"link: {link}")
|
logging.debug(f"link: {link}")
|
||||||
|
|
||||||
print("done")
|
logging.info("done")
|
||||||
return # need to return link later to qbit but need to decide logic
|
logging.info(f"Downloaded {self.episodes_downloaded} episodes")
|
||||||
|
logging.info("Returning link to qbit")
|
||||||
|
return link # need to return link later to qbit but need to decide logic
|
||||||
|
|
||||||
|
|
||||||
class Qbittorrent:
|
class Qbittorrent:
|
||||||
pass
|
def __init__(self):
|
||||||
|
self.username = ""
|
||||||
|
self.password = ""
|
||||||
|
self.host = "localhost"
|
||||||
|
self.port = 8080
|
||||||
|
|
||||||
|
def get_credentials(self):
|
||||||
|
# Get qbittorrent credentials from .env file
|
||||||
|
self.username = os.getenv("QB_USERNAME")
|
||||||
|
self.password = os.getenv("QB_PASSWORD")
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
@ -97,5 +125,3 @@ if __name__ == "__main__":
|
||||||
print("\nStopping scheduled downloads...")
|
print("\nStopping scheduled downloads...")
|
||||||
print(f"Episodes downloaded: {c2c.episodes_downloaded}")
|
print(f"Episodes downloaded: {c2c.episodes_downloaded}")
|
||||||
"""
|
"""
|
||||||
# rss = createRss()
|
|
||||||
# rss.process_episodes()
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue