mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
from core.utils.data.tracker import get_magnet_link
|
|
from core.utils.logging.logs import consoleLog
|
|
from core.utils.data.state import state
|
|
from urllib.parse import urljoin
|
|
from bs4 import BeautifulSoup
|
|
from typing import Dict
|
|
import requests
|
|
|
|
|
|
def scrape_uztracker(query):
|
|
base_url="https://uztracker.net/"
|
|
search_url = f"{base_url.rstrip('/')}/tracker.php?nm={query}"
|
|
consoleLog(search_url)
|
|
posts = []
|
|
|
|
try:
|
|
response = requests.get(search_url)
|
|
response.raise_for_status()
|
|
soup = BeautifulSoup(response.text, 'html.parser')
|
|
links = soup.find_all('tr', class_="tCenter hl-tr", id=lambda x: x and x.startswith('tor_'))
|
|
for link in links:
|
|
|
|
theme_link = link.find('a', class_="genmed tLink", href=lambda x: x and x.startswith('./viewtopic'))
|
|
if not theme_link or not theme_link.b:
|
|
continue
|
|
url = urljoin(base_url, theme_link['href'])
|
|
title = theme_link.b.text
|
|
author_link = link.find('a', class_="med")
|
|
author = author_link.text.strip() if author_link else "Unknown"
|
|
|
|
posts.append(dict(
|
|
title=title,
|
|
author=author,
|
|
url=url,
|
|
))
|
|
|
|
return posts
|
|
|
|
except requests.RequestException as e:
|
|
consoleLog(f"Failed to fetch {search_url}: {e}")
|
|
return None
|
|
|
|
def get_magnet(post: Dict):
|
|
return get_magnet_link(post["url"])
|
|
|
|
Metadata = {
|
|
"name" : "uztracker",
|
|
"headers" : ["Post Title", "Author"],
|
|
"scrapeFunc" : scrape_uztracker,
|
|
"linkFunc" : get_magnet,
|
|
"isMagnet" : True,
|
|
}
|
|
|
|
def init_uztracker():
|
|
state.trackers.update({Metadata["name"] : Metadata})
|