Skip to content

Instantly share code, notes, and snippets.

@Awesomerly
Created September 3, 2022 00:34
Show Gist options
  • Select an option

  • Save Awesomerly/608791f4e2a079e2fe1dfcb27d5f0022 to your computer and use it in GitHub Desktop.

Select an option

Save Awesomerly/608791f4e2a079e2fe1dfcb27d5f0022 to your computer and use it in GitHub Desktop.
Gamebanana Mod Downloader
desc = "Simple script to download gamebanana mod categories."
import requests
import brotli
import argparse
from math import ceil
from time import sleep
def setUpArguments():
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-id', type=int, required=True, help="Mod Category ID")
parser.add_argument('-p', '--per-page', type=int, default=50, help="Number of mods per page to download")
return parser.parse_args()
def getModPage(page: int, mod_category: int, perPage: int):
data = {
"_nPage": f"{page}",
"_nPerpage": {perPage},
"_aFilters[Generic_Category]": f"{mod_category}"
}
res = requests.get("https://gamebanana.com/apiv10/Mod/Index", params=data, headers={'Accept-Encoding': 'br'})
json = res.json()
record_count = json['_aMetadata']['_nRecordCount']
record_ids = [item['_idRow'] for item in json['_aRecords']]
return record_count, record_ids
def getModCount(mod_category: int):
return getModPage(1, mod_category, 1)[0]
def getModDownloads(ids: list):
data = {
'itemtype[]': ["Mod" for x in range(len(ids))],
'itemid[]': ids,
'fields[]': ["Files().aFiles()" for x in range(len(ids))]
}
res = requests.get("https://api.gamebanana.com/Core/Item/Data", params=data, headers={'Accept-Encoding': 'br'})
json = res.json()
# https://i.stack.imgur.com/0GoV5.gif
flattened_json = [item for sublist in json for item in sublist]
downloads_dict = {}
for d in flattened_json:
downloads_dict.update(d)
return list(downloads_dict.keys())
if __name__ == "__main__":
args = setUpArguments()
mod_count = getModCount(args.id)
print(f"The category has {mod_count} mods.")
num_pages = ceil(mod_count / args.per_page)
mod_downloads = []
for cur_page in range(1, num_pages + 1):
print(f"Page {cur_page}/{num_pages}")
mod_ids = getModPage(cur_page, args.id, args.per_page)[1]
sleep(1)
print("Getting mod download links")
cur_downloads = getModDownloads(mod_ids)
mod_downloads += cur_downloads
sleep(2)
mod_downloads_2 = [f"gamebanana.com/dl/{id}" for id in mod_downloads]
file = open("downloads.txt", "w")
file.write("\r\n".join(mod_downloads_2))
file.close()
print("done")
# afterwards, run wget --content-disposition -P ./mods -t 50 -i downloads.txt --wait 5
@XxBromanFunkinxX
Copy link

what do you use?

@XxBromanFunkinxX
Copy link

How can i use it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment