mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-06 19:45:24 +00:00
78 lines
2.1 KiB
Python
78 lines
2.1 KiB
Python
# 02.07.24
|
|
|
|
import sys
|
|
import logging
|
|
|
|
|
|
# External libraries
|
|
import httpx
|
|
from bs4 import BeautifulSoup
|
|
from unidecode import unidecode
|
|
|
|
|
|
# Internal utilities
|
|
from Src.Util.headers import get_headers
|
|
from Src.Util.table import TVShowManager
|
|
from ..Template import search_domain, get_select_title
|
|
|
|
|
|
# Logic class
|
|
from .Core.Class.SearchType import MediaManager
|
|
|
|
|
|
# Variable
|
|
from .costant import SITE_NAME
|
|
media_search_manager = MediaManager()
|
|
table_show_manager = TVShowManager()
|
|
|
|
|
|
|
|
def title_search(word_to_search: str) -> int:
|
|
"""
|
|
Search for titles based on a search query.
|
|
|
|
Args:
|
|
- title_search (str): The title to search for.
|
|
|
|
Returns:
|
|
int: The number of titles found.
|
|
"""
|
|
|
|
# Find new domain if prev dont work
|
|
domain_to_use, _ = search_domain(SITE_NAME, '<meta name="description" content="1337x', f"https://{SITE_NAME}")
|
|
|
|
# Construct the full site URL and load the search page
|
|
response = httpx.get(f"https://{SITE_NAME}.{domain_to_use}/search/{unidecode(word_to_search)}/1/", headers={'user-agent': get_headers()}, follow_redirects=True)
|
|
response.raise_for_status()
|
|
|
|
# Create soup and find table
|
|
soup = BeautifulSoup(response.text, "html.parser")
|
|
|
|
# Scrape div film in table on single page
|
|
for tr in soup.find_all('tr'):
|
|
|
|
try:
|
|
|
|
title_info = {
|
|
'title': tr.find_all("a")[1].get_text(strip=True),
|
|
'link': tr.find_all("a")[1].get("href"),
|
|
'seader': tr.find_all("td")[-5].get_text(strip=True),
|
|
'leacher': tr.find_all("td")[-4].get_text(strip=True),
|
|
'date': tr.find_all("td")[-3].get_text(strip=True).replace("'", ""),
|
|
'size': tr.find_all("td")[-2].get_text(strip=True)
|
|
}
|
|
|
|
media_search_manager.add_media(title_info)
|
|
|
|
except:
|
|
continue
|
|
|
|
# Return the number of titles found
|
|
return media_search_manager.get_length()
|
|
|
|
|
|
def run_get_select_title():
|
|
"""
|
|
Display a selection of titles and prompt the user to choose one.
|
|
"""
|
|
return get_select_title(table_show_manager, media_search_manager) |