changed few functions to use api instead of bs4
This commit is contained in:
parent
59905f7e34
commit
f3d412bcb3
@ -171,20 +171,10 @@ def initialize_steam(master):
|
|||||||
|
|
||||||
@if_internet_available
|
@if_internet_available
|
||||||
def valid_id(workshop_id):
|
def valid_id(workshop_id):
|
||||||
url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={workshop_id}"
|
data = item_steam_api(workshop_id)
|
||||||
response = requests.get(url)
|
if "consumer_app_id" in data['response']['publishedfiledetails'][0]:
|
||||||
response.raise_for_status()
|
|
||||||
content = response.text
|
|
||||||
soup = BeautifulSoup(content, "html.parser")
|
|
||||||
|
|
||||||
try:
|
|
||||||
soup.find("div", class_="rightDetailsBlock").text.strip()
|
|
||||||
soup.find("div", class_="workshopItemTitle").text.strip()
|
|
||||||
soup.find("div", class_="detailsStatRight").text.strip()
|
|
||||||
stars_div = soup.find("div", class_="fileRatingDetails")
|
|
||||||
stars_div.find("img")["src"]
|
|
||||||
return True
|
return True
|
||||||
except:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def convert_speed(speed_bytes):
|
def convert_speed(speed_bytes):
|
||||||
@ -227,26 +217,13 @@ def convert_bytes_to_readable(size_in_bytes, no_symb=None):
|
|||||||
size_in_bytes /= 1024.0
|
size_in_bytes /= 1024.0
|
||||||
|
|
||||||
def get_workshop_file_size(workshop_id, raw=None):
|
def get_workshop_file_size(workshop_id, raw=None):
|
||||||
url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={workshop_id}&searchtext="
|
data = item_steam_api(workshop_id)
|
||||||
response = requests.get(url)
|
|
||||||
soup = BeautifulSoup(response.text, "html.parser")
|
|
||||||
file_size_element = soup.find("div", class_="detailsStatRight")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
file_size_in_bytes = data['response']['publishedfiledetails'][0]['file_size']
|
||||||
if raw:
|
if raw:
|
||||||
file_size_text = file_size_element.get_text(strip=True)
|
|
||||||
file_size_text = file_size_text.replace(",", "")
|
|
||||||
file_size_in_mb = float(file_size_text.replace(" MB", ""))
|
|
||||||
file_size_in_bytes = int(file_size_in_mb * 1024 * 1024)
|
|
||||||
return convert_bytes_to_readable(file_size_in_bytes)
|
return convert_bytes_to_readable(file_size_in_bytes)
|
||||||
|
else:
|
||||||
if file_size_element:
|
|
||||||
file_size_text = file_size_element.get_text(strip=True)
|
|
||||||
file_size_text = file_size_text.replace(",", "")
|
|
||||||
file_size_in_mb = float(file_size_text.replace(" MB", ""))
|
|
||||||
file_size_in_bytes = int(file_size_in_mb * 1024 * 1024)
|
|
||||||
return file_size_in_bytes
|
return file_size_in_bytes
|
||||||
return None
|
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -351,16 +328,9 @@ def reset_steamcmd(no_warn=None):
|
|||||||
|
|
||||||
def get_item_name(id):
|
def get_item_name(id):
|
||||||
try:
|
try:
|
||||||
url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={id}"
|
data = item_steam_api(id)
|
||||||
response = requests.get(url)
|
|
||||||
response.raise_for_status()
|
|
||||||
content = response.text
|
|
||||||
|
|
||||||
soup = BeautifulSoup(content, "html.parser")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
map_name = soup.find("div", class_="workshopItemTitle").text.strip()
|
name = data['response']['publishedfiledetails'][0]['title']
|
||||||
name = map_name[:32] + "..." if len(map_name) > 32 else map_name
|
|
||||||
return name
|
return name
|
||||||
except:
|
except:
|
||||||
return True
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user