from flask import Flask, request, jsonify, render_template_string, send_from_directory import subprocess import os app = Flask(__name__) # HTML para la interfaz web html_form = """ SteamCMD Workshop Downloader

Bienvenido al descargador de la Steam Workshop con SteamCMD!




{% if output %}

Resultado:

{{ output }}
{% endif %} {% if downloads %}

Archivos descargados:

{% endif %}
""" # Ruta principal para mostrar el formulario HTML @app.route('/', methods=['GET']) def home(): return render_template_string(html_form) # Ruta para ejecutar comandos de steamcmd @app.route('/execute', methods=['POST']) def execute(): try: command = request.form.get('command') if not command: return render_template_string(html_form, output='No se proporcionó ningún comando') # Añadir el comando base para steamcmd y asegurar que se ejecuta en el directorio correcto steamcmd_command = f"cd /steamcmd && chmod -R 755 ./linux32 && ./steamcmd.sh +login anonymous {command} +quit" # Ejecutar el comando en la terminal result = subprocess.run(steamcmd_command, shell=True, capture_output=True, text=True) # Obtener la lista de archivos descargados download_path = "/steamcmd/steamapps/workshop/content" downloads = [] if os.path.exists(download_path): for root, dirs, files in os.walk(download_path): for file in files: downloads.append(os.path.relpath(os.path.join(root, file), start=download_path)) # Retornar la salida del comando y los archivos descargados if result.returncode == 0: return render_template_string(html_form, output=result.stdout, downloads=downloads) else: return render_template_string(html_form, output=result.stderr, downloads=downloads) except Exception as e: return render_template_string(html_form, output=str(e)) # Ruta para descargar los archivos @app.route('/download/', methods=['GET']) def download_file(filename): download_path = "/steamcmd/steamapps/workshop/content" return send_from_directory(download_path, filename, as_attachment=True) if __name__ == '__main__': app.run(host='0.0.0.0', port=7860)