anticitizn/creamlinux

DLC Fetcher and Configurator for CreamLinux

Closed this issue · 2 comments

This script helps you create a custom cream_api.ini file for CreamLinux by fetching game details and DLC information from the Steam Web API. As i have not seen any other programs floating around that does this for linux i made this script in python.

Keep in mind that this script might not fetch all DLCs because the Steam API could have limitations on visibility or access restrictions to certain content, which prevents some DLCs from being listed or detailed through API responses.

Features:

  • Fetches game details and DLC information from the Steam Web API
  • Handles rate limiting and errors
  • Downloads the latest CreamLinux package and extracts it
  • Generates a custom cream_api.ini file with the specified game and DLC information

Usage:

  • Save the script as generate_cream_api.py
  • Run the script with the desired game app ID as an argument: python generate_cream_api.py 394360
  • The script will download the latest CreamLinux package, extract it, and generate a custom cream_api.ini file in a new directory named after the game app ID
import sys
import requests
import os
import time
import zipfile

app_id = sys.argv[1]
base_url = f"https://store.steampowered.com/api/appdetails?appids={app_id}"
response = requests.get(base_url)
data = response.json()

if app_id not in data or "data" not in data[app_id]:
    print("Error: Unable to fetch game details.")
    sys.exit(1)

game_data = data[app_id]["data"]
dlcs = game_data.get("dlc", [])
print("DLC IDs found:", dlcs)

dlc_details = []
for dlc_id in dlcs:
    try:
        time.sleep(0.3)
        dlc_url = f"https://store.steampowered.com/api/appdetails?appids={dlc_id}"
        dlc_response = requests.get(dlc_url)
        if dlc_response.status_code == 200:
            dlc_data = dlc_response.json()
            if str(dlc_id) in dlc_data and "data" in dlc_data[str(dlc_id)]:
                dlc_name = dlc_data[str(dlc_id)]["data"].get("name", "Unknown DLC")
                dlc_details.append({"appid": dlc_id, "name": dlc_name})
                print(f"Successfully fetched DLC {dlc_id} - {dlc_name}")
            else:
                print(f"Data missing for DLC {dlc_id}")
        elif dlc_response.status_code == 429:
            print("Rate limited! Please wait before trying again.")
            time.sleep(10)  # Wait longer if rate limited
        else:
            print(f"Failed to fetch details for DLC {dlc_id}, Status Code: {dlc_response.status_code}")
    except Exception as e:
        print(f"Exception for DLC {dlc_id}: {str(e)}")

dlc_list = "\n".join([f"{dlc['appid']} = {dlc['name']}" for dlc in dlc_details])


directory_name = f"{app_id}"
if not os.path.exists(directory_name):
    os.makedirs(directory_name)


zip_url = "https://github.com/anticitizn/creamlinux/releases/latest/download/creamlinux.zip"
zip_path = f"{directory_name}/creamlinux.zip"
response = requests.get(zip_url)
if response.status_code == 200:
    with open(zip_path, "wb") as f:
        f.write(response.content)
    print("Downloaded ZIP file successfully.")


    with zipfile.ZipFile(zip_path, 'r') as zip_ref:
        zip_ref.extractall(directory_name)
    

    os.remove(zip_path)


    unwanted_file = f"{directory_name}/cream_api.ini"
    if os.path.exists(unwanted_file):
        os.remove(unwanted_file)
        print(f"Removed unwanted file: {unwanted_file}")

else:
    print(f"Failed to download the ZIP file. Status Code: {response.status_code}")


output_filename = f"{directory_name}/cream_api.ini"
with open(output_filename, "w") as file:
    file.write(f"""APPID = {app_id}
[config]
issubscribedapp_on_false_use_real = true

[methods]
disable_steamapps_issubscribedapp = false

[dlc]
{dlc_list}
""")
    print(f"Custom cream_api.ini has been written to {output_filename}")

Wow, great job! I'll play around with it a bit later today and integrate it within creamlinux if you don't mind, this would save a lot of headaches.

Wow, great job! I'll play around with it a bit later today and integrate it within creamlinux if you don't mind, this would save a lot of headaches.

No problem! :)