mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 01:49:42 +02:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d17b4bd44a | |||
| 10c935e852 | |||
| bd8320a26c | |||
| c99ce339e0 | |||
| 1822a150d7 | |||
| 7e5e3033e6 | |||
| 1cab671a13 | |||
| 5637e80657 | |||
| 2f78b812ba | |||
| 5af9e79ecc | |||
| 4dadc9ba50 | |||
| 719c4e86e8 | |||
| 999c8e9ba4 | |||
| 3f6889da56 | |||
| 69ac739be6 |
@@ -0,0 +1,41 @@
|
|||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import requests
|
||||||
|
|
||||||
|
def scrape_monkrus_telegram(query):
|
||||||
|
post = 100
|
||||||
|
max_posts = 250
|
||||||
|
posts: list[dict] = []
|
||||||
|
added = set()
|
||||||
|
|
||||||
|
while post <= max_posts:
|
||||||
|
url = f"https://t.me/s/real_monkrus/{post}"
|
||||||
|
response = requests.get(url)
|
||||||
|
soup = BeautifulSoup(response.text, "html.parser")
|
||||||
|
bubbles = soup.find_all("div", class_="tgme_widget_message_bubble")
|
||||||
|
|
||||||
|
if not bubbles:
|
||||||
|
break
|
||||||
|
|
||||||
|
for bubble in bubbles:
|
||||||
|
post_txt = bubble.find("div", class_="tgme_widget_message_text js-message_text")
|
||||||
|
if not post_txt or not post_txt.b:
|
||||||
|
continue
|
||||||
|
|
||||||
|
title = post_txt.b.text
|
||||||
|
link = bubble.find("a", href=lambda x: x and x.startswith("https://uztracker.net"))
|
||||||
|
|
||||||
|
if query.lower() in title.lower() and link:
|
||||||
|
post_url = link["href"]
|
||||||
|
if post_url not in added:
|
||||||
|
added.add(post_url)
|
||||||
|
posts.append(dict(
|
||||||
|
author="m0nkrus",
|
||||||
|
id=len(posts) + 1,
|
||||||
|
title=title,
|
||||||
|
url=post_url
|
||||||
|
))
|
||||||
|
|
||||||
|
post += 22
|
||||||
|
|
||||||
|
posts.reverse()
|
||||||
|
return(posts)
|
||||||
@@ -4,6 +4,8 @@ from core.utils.data.state import state
|
|||||||
|
|
||||||
def scrape_rutracker(search_text):
|
def scrape_rutracker(search_text):
|
||||||
search = requests.get(f"{state.api_url}/search/{search_text}")
|
search = requests.get(f"{state.api_url}/search/{search_text}")
|
||||||
|
if state.debug:
|
||||||
|
print("Sent request to server")
|
||||||
if search:
|
if search:
|
||||||
try:
|
try:
|
||||||
return search.text
|
return search.text
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ async def init_uztracker():
|
|||||||
up = True
|
up = True
|
||||||
else:
|
else:
|
||||||
up = False
|
up = False
|
||||||
|
if state.debug:
|
||||||
print(f"Uztracker seems down, status code: {response.status_code}")
|
print(f"Uztracker seems down, status code: {response.status_code}")
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
|
if state.debug:
|
||||||
print(f"\nRequest Exception on {url_uztracker}:")
|
print(f"\nRequest Exception on {url_uztracker}:")
|
||||||
print(e)
|
print(e)
|
||||||
print("\nIs the Site down?")
|
print("\nIs the Site down?")
|
||||||
@@ -26,29 +28,23 @@ async def init_uztracker():
|
|||||||
|
|
||||||
asyncio.run(init_uztracker())
|
asyncio.run(init_uztracker())
|
||||||
|
|
||||||
async def scrape_uztracker(search, max_results=450):
|
def scrape_uztracker(search):
|
||||||
if up:
|
if up:
|
||||||
|
search_url = url_uztracker + search
|
||||||
|
if state.debug:
|
||||||
|
print(search_url)
|
||||||
result = False
|
result = False
|
||||||
global results
|
global results
|
||||||
global resulttitles
|
global resulttitles
|
||||||
results = []
|
results = []
|
||||||
resulttitles = []
|
resulttitles = []
|
||||||
|
|
||||||
per_page = 50
|
|
||||||
|
|
||||||
for start in range(0, max_results, per_page):
|
|
||||||
search_url = url_uztracker + search + f"&start={start}"
|
|
||||||
if state.debug:
|
|
||||||
print(search_url)
|
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
|
||||||
try:
|
try:
|
||||||
async with session.get(search_url) as response:
|
|
||||||
response.raise_for_status()
|
|
||||||
text = await response.text()
|
|
||||||
soup = BeautifulSoup(text, 'html.parser')
|
|
||||||
links = soup.find_all('a', class_="genmed tLink", href=lambda x: x and x.startswith('./viewtopic'))
|
|
||||||
resultCount = 0
|
resultCount = 0
|
||||||
|
response = requests.get(search_url)
|
||||||
|
response.raise_for_status()
|
||||||
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
|
links = soup.find_all('a', class_="genmed tLink", href=lambda x: x and x.startswith('./viewtopic'))
|
||||||
for link in links:
|
for link in links:
|
||||||
if link.b:
|
if link.b:
|
||||||
resultCount += 1
|
resultCount += 1
|
||||||
@@ -56,24 +52,22 @@ async def scrape_uztracker(search, max_results=450):
|
|||||||
resulttitles.append(link.b.text)
|
resulttitles.append(link.b.text)
|
||||||
result = True
|
result = True
|
||||||
|
|
||||||
if resultCount == 0:
|
|
||||||
# add popup in gui for no result
|
|
||||||
break
|
|
||||||
|
|
||||||
except aiohttp.ClientError as e:
|
|
||||||
if result:
|
if result:
|
||||||
print(f"Failed to fetch {search_url}: {e}")
|
return resulttitles, results
|
||||||
|
|
||||||
|
if not result:
|
||||||
|
# add popup in gui for no result
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
except requests.RequestException as e:
|
||||||
|
if result and state.debug:
|
||||||
|
print(f"Failed to fetch {search_url}: {e}")
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
|
if state.debug:
|
||||||
print("Error: Uztracker down")
|
print("Error: Uztracker down")
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
if not results:
|
|
||||||
return None, None
|
|
||||||
|
|
||||||
return resulttitles, results
|
|
||||||
|
|
||||||
def get_post_title(post_url):
|
def get_post_title(post_url):
|
||||||
if up:
|
if up:
|
||||||
response = requests.get(post_url)
|
response = requests.get(post_url)
|
||||||
@@ -85,6 +79,7 @@ def get_post_title(post_url):
|
|||||||
if state.debug:
|
if state.debug:
|
||||||
print("Program not found")
|
print("Program not found")
|
||||||
else:
|
else:
|
||||||
|
if state.debug:
|
||||||
print("Error: Uztracker down")
|
print("Error: Uztracker down")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ def settings_dialog(self):
|
|||||||
save_btn.clicked.connect(lambda: save_settings(thread_box.value(), close_settings, api_url.text(), download_path.text(), speed_limit.value()))
|
save_btn.clicked.connect(lambda: save_settings(thread_box.value(), close_settings, api_url.text(), download_path.text(), speed_limit.value()))
|
||||||
|
|
||||||
cancel_btn.clicked.connect(dialog.reject)
|
cancel_btn.clicked.connect(dialog.reject)
|
||||||
print(thread_box.value())
|
|
||||||
layout.addWidget(cancel_btn)
|
layout.addWidget(cancel_btn)
|
||||||
layout.addWidget(save_btn)
|
layout.addWidget(save_btn)
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
toolbar.setLayoutDirection(Qt.RightToLeft)
|
toolbar.setLayoutDirection(Qt.RightToLeft)
|
||||||
|
|
||||||
self.tracker_list = QComboBox()
|
self.tracker_list = QComboBox()
|
||||||
self.tracker_list.addItems(["rutracker", "uztracker"])
|
self.tracker_list.addItems(["rutracker", "uztracker", "m0nkrus"])
|
||||||
self.tracker_list.activated.connect(self.set_tracker)
|
self.tracker_list.activated.connect(self.set_tracker)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import asyncio
|
|
||||||
from core.data.scrapers.uztracker import scrape_uztracker
|
from core.data.scrapers.uztracker import scrape_uztracker
|
||||||
from core.data.scrapers.rutracker import scrape_rutracker
|
from core.data.scrapers.rutracker import scrape_rutracker
|
||||||
|
from core.data.scrapers.monkrus import scrape_monkrus_telegram
|
||||||
from core.utils.network.jsonhandler import split_data, format_data
|
from core.utils.network.jsonhandler import split_data, format_data
|
||||||
from core.utils.data.state import state
|
from core.utils.data.state import state
|
||||||
|
|
||||||
@@ -12,22 +12,34 @@ def return_pressed(self):
|
|||||||
return
|
return
|
||||||
if state.debug:
|
if state.debug:
|
||||||
print("User searched for:", search_text)
|
print("User searched for:", search_text)
|
||||||
|
|
||||||
if state.tracker == "uztracker":
|
if state.tracker == "uztracker":
|
||||||
response = asyncio.run(scrape_uztracker(search_text))
|
response = scrape_uztracker(search_text)
|
||||||
if state.tracker == "rutracker":
|
if response:
|
||||||
|
state.post_titles, state.post_urls = response
|
||||||
|
self.softwareList.clear()
|
||||||
|
if state.post_titles and len(state.post_titles) > 0:
|
||||||
|
self.softwareList.addItems(state.post_titles)
|
||||||
|
self.show_empty_results(False)
|
||||||
|
self.post_author_list.clear()
|
||||||
|
else:
|
||||||
|
if state.debug:
|
||||||
|
print(f"No Results for {search_text}")
|
||||||
|
self.softwareList.clear()
|
||||||
|
self.show_empty_results(True)
|
||||||
|
else:
|
||||||
|
if state.debug:
|
||||||
|
print(f"No response from uztracker")
|
||||||
|
self.softwareList.clear()
|
||||||
|
self.show_empty_results(True)
|
||||||
|
|
||||||
|
elif state.tracker == "rutracker":
|
||||||
response = scrape_rutracker(search_text)
|
response = scrape_rutracker(search_text)
|
||||||
if response:
|
if response:
|
||||||
if state.tracker == "uztracker":
|
|
||||||
state.post_titles, state.post_urls, = response
|
|
||||||
self.softwareList.clear()
|
|
||||||
if state.post_titles:
|
|
||||||
self.softwareList.addItems(state.post_titles)
|
|
||||||
self.post_author_list.addItems(state.post_author)
|
|
||||||
if state.tracker == "rutracker":
|
|
||||||
_, state.posts, _, _, cached = split_data(response)
|
_, state.posts, _, _, cached = split_data(response)
|
||||||
if state.posts == []:
|
if state.posts == []:
|
||||||
if state.debug:
|
if state.debug:
|
||||||
print(f"No Results found for \"{search_text}\"")
|
print(f"No Results for {search_text}")
|
||||||
self.softwareList.clear()
|
self.softwareList.clear()
|
||||||
self.show_empty_results(True)
|
self.show_empty_results(True)
|
||||||
else:
|
else:
|
||||||
@@ -38,5 +50,25 @@ def return_pressed(self):
|
|||||||
self.softwareList.clear()
|
self.softwareList.clear()
|
||||||
self.softwareList.addItems(state.post_titles)
|
self.softwareList.addItems(state.post_titles)
|
||||||
if state.debug == True:
|
if state.debug == True:
|
||||||
print(f"Cached: {cached}")
|
print(f"Response Cached: {cached}")
|
||||||
|
else:
|
||||||
|
if state.debug:
|
||||||
|
print(f"No response from rutracker")
|
||||||
|
self.softwareList.clear()
|
||||||
|
self.show_empty_results(True)
|
||||||
|
|
||||||
|
elif state.tracker == "m0nkrus":
|
||||||
|
state.posts = scrape_monkrus_telegram(search_text)
|
||||||
|
|
||||||
|
if state.posts == []:
|
||||||
|
if state.debug:
|
||||||
|
print(f"No Results for {search_text}")
|
||||||
|
self.softwareList.clear()
|
||||||
|
self.show_empty_results(True)
|
||||||
|
else:
|
||||||
|
state.post_titles, _, state.post_author = format_data(state.posts)
|
||||||
|
self.show_empty_results(False)
|
||||||
|
self.post_author_list.clear()
|
||||||
|
self.post_author_list.addItems(state.post_author)
|
||||||
|
self.softwareList.clear()
|
||||||
|
self.softwareList.addItems(state.post_titles)
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
from .aria2_integration import run_aria2p
|
from .aria2_integration import run_aria2p
|
||||||
|
from core.utils.data.state import state
|
||||||
|
|
||||||
def start_client():
|
def start_client():
|
||||||
global aria2
|
global aria2
|
||||||
aria2 = run_aria2p()
|
aria2 = run_aria2p()
|
||||||
|
if state.debug:
|
||||||
|
print("Started Aria2p")
|
||||||
|
|
||||||
def add_magnet(uri):
|
def add_magnet(uri):
|
||||||
aria2.add_magnet(uri)
|
aria2.add_magnet(uri)
|
||||||
|
if state.debug:
|
||||||
|
print("Magnet URI added to Aria2")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,27 @@ from core.utils.network.jsonhandler import format_data
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_item_url(item, posts, post_titles): # oftwarelist currentitem, post list (dict), post titles list
|
def get_item_url(item, posts, post_titles): # softwarelist currentitem, post list (dict), post titles list
|
||||||
post_index = post_titles.index(item)
|
post_index = post_titles.index(item)
|
||||||
if 0 <= post_index < len(post_titles):
|
if 0 <= post_index < len(post_titles):
|
||||||
if state.tracker == "uztracker":
|
if state.tracker == "uztracker":
|
||||||
item = "https://uztracker.net/" + state.post_urls[post_index].lstrip("./")
|
item = "https://uztracker.net/" + state.post_urls[post_index].lstrip("./")
|
||||||
|
if state.debug:
|
||||||
|
print("Found post URL: ", item)
|
||||||
return item
|
return item
|
||||||
if state.tracker == "rutracker":
|
if state.tracker == "rutracker":
|
||||||
item_dict = posts[post_index]
|
item_dict = posts[post_index]
|
||||||
_, post_links, _ = format_data([item_dict])
|
_, post_links, _ = format_data([item_dict])
|
||||||
|
if state.debug:
|
||||||
|
print("Found post URL: ", post_links[0])
|
||||||
return post_links[0]
|
return post_links[0]
|
||||||
|
if state.tracker == "m0nkrus":
|
||||||
|
item_dict = posts[post_index]
|
||||||
|
_, post_links, _ = format_data([item_dict])
|
||||||
|
if state.debug:
|
||||||
|
print("Found post URL: ", post_links[0])
|
||||||
|
return post_links[0]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -22,6 +33,8 @@ def get_item_url(item, posts, post_titles): # oftwarelist currentitem, post list
|
|||||||
def get_magnet_link(post_url):
|
def get_magnet_link(post_url):
|
||||||
try:
|
try:
|
||||||
response = requests.get(post_url) # eventually impl. cloudscraper
|
response = requests.get(post_url) # eventually impl. cloudscraper
|
||||||
|
if state.debug:
|
||||||
|
print("Sent Request to retrieve Magnet Link...")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
soup = BeautifulSoup(response.text, 'html.parser')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
magnet_link = soup.find('a', href=lambda x: x and x.startswith('magnet:'))
|
magnet_link = soup.find('a', href=lambda x: x and x.startswith('magnet:'))
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ def kill_aria2server():
|
|||||||
if proc.name() == process:
|
if proc.name() == process:
|
||||||
proc.kill()
|
proc.kill()
|
||||||
if state.debug:
|
if state.debug:
|
||||||
print("Killed Aria2c")
|
print(f"Killed Aria2c (PID {proc.pid})")
|
||||||
except psutil.NoSuchProcess:
|
except psutil.NoSuchProcess:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import threading
|
|||||||
def download_selected(item, posts, post_titles):
|
def download_selected(item, posts, post_titles):
|
||||||
if item is not None:
|
if item is not None:
|
||||||
if state.debug:
|
if state.debug:
|
||||||
print(f"network {item.text()}")
|
print(f"Downloading {item.text()}")
|
||||||
run_thread(threading.Thread(target=run_download, args=(item.text(), posts, post_titles)))
|
run_thread(threading.Thread(target=run_download, args=(item.text(), posts, post_titles)))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -10,11 +10,14 @@ import qdarktheme
|
|||||||
import darkdetect
|
import darkdetect
|
||||||
import threading
|
import threading
|
||||||
import signal
|
import signal
|
||||||
import atexit
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Debug Output
|
|
||||||
state.debug = True
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--debug", action="store_true")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def run_gui():
|
def run_gui():
|
||||||
@@ -36,6 +39,7 @@ def keyboardinterrupthandler(signum, frame):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
read_config()
|
read_config()
|
||||||
|
state.debug = args.debug # override of read_config
|
||||||
if state.debug:
|
if state.debug:
|
||||||
print("Starting Aria2 Server")
|
print("Starting Aria2 Server")
|
||||||
state.aria2process = run_aria2server()
|
state.aria2process = run_aria2server()
|
||||||
|
|||||||
Reference in New Issue
Block a user