You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

117 lines
3.3 KiB

import argparse
from glob import glob
import os.path as OSPATH
import requests
from bs4 import BeautifulSoup
from subprocess import call
import os, shutil
STEAM_COLLECTION_URL = "https://steamcommunity.com/sharedfiles/filedetails/?id=2620032135"
MAPS = "../maps"
DOWNLOAD_LINE = "{client.exe} +login {client.login} +workshop_download_item {_map.app_id} {_map.map_id} +quit"
class SteamClient:
exe = "../steam/steamcmd.exe"
login = "anonymous"
class BspSrc:
java = "javaw"
jar = "../bspsrc/bspsrc.jar"
class Tf2Map:
app_id = 440
map_id = 0
def __init__(self, url, name) -> None:
self.map_id = int(url.split("?id=")[1])
self.url = url
self.name = name.replace("|", " ").replace("\\", " ").replace("/"," ")
def __str__(self):
return f'{self.name} | {self.url}'
def __repr__(self) -> str:
return self.__str__()
@property
def downloaded(self):
os.chdir(os.path.dirname(__file__))
r = f"../maps/{self.name}/*.bsp"
r = r.replace("[","*").replace("]","*")
print(f"Watch bsp in {r}")
return glob(r)
@property
def sourced(self):
os.chdir(os.path.dirname(__file__))
r = f"../maps/{self.name}/*.vmf"
r = r.replace("[","*").replace("]","*")
print(f"Watch vmf in {r}")
return glob(r)
def decompiler(self):
os.chdir(os.path.dirname(__file__))
cmd = "{amongus.java} -jar {amongus.jar} \"{0}\"".format(self.downloaded[0], amongus = BspSrc())
print(cmd)
for source in self.sourced:
os.remove(source)
call(cmd)
shutil.move(self.sourced[0], self.sourced[0].replace("_d.vmf", ".vmf"))
return self.sourced
def readme(self):
with open(os.path.dirname(self.downloaded[0]) + "/README", "w", encoding="utf8") as readme:
readme.write(self.url)
class CollectionMap:
pass
class CollectionParser:
response = None
def __init__(self, url):
self.response = requests.get(url).text
self.soup = BeautifulSoup(self.response, "html.parser")
def foundMaps(self, skip_downloaded = True) -> list[CollectionMap]:
_list = []
all = 0
download = 0
for collect in self.soup.findAll('div', class_='collectionItem'):
url = collect.find("div", class_="workshopItem").find("a")['href']
name = collect.find("div", class_="collectionItemDetails").find("div", class_="workshopItemTitle").text
_item = Tf2Map(url, name)
if _item.downloaded and skip_downloaded:
print(f"{name} already downloaded")
else:
_list.append(_item)
download += 1
all += 1
print(f"Всего карт будет загружено: {download}, всего найдено {all}")
return _list
class MapDownloader:
def process(self, _map: Tf2Map):
self.download(_map)
self.move(_map)
_map.decompiler()
_map.readme()
def download(self, _map):
os.chdir(os.path.dirname(__file__))
cmd = DOWNLOAD_LINE.format(client = SteamClient(), _map = _map)
self.call(cmd)
def move(self, _map):
os.chdir(os.path.dirname(__file__))
os.chdir("../maps")
os.mkdir(_map.name) if not OSPATH.exists(_map.name) else None
shutil.move(glob(f"../steam/steamapps/workshop/content/{_map.app_id}/{_map.map_id}/*.bsp")[0], _map.name) if glob(f"../steam/steamapps/workshop/content/{_map.app_id}/{_map.map_id}/*.bsp") else None
def call(self, cmd):
print(cmd)
call(cmd)
if __name__ == "__main__":
for _map in CollectionParser(STEAM_COLLECTION_URL).foundMaps():
MapDownloader().process(_map)