aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mods.txt4
-rw-r--r--readme.md14
-rwxr-xr-xupdate.py49
-rw-r--r--version.txt6
4 files changed, 63 insertions, 10 deletions
diff --git a/mods.txt b/mods.txt
index e608825..91f5d9e 100644
--- a/mods.txt
+++ b/mods.txt
@@ -1,4 +1,4 @@
# fill this file with the same as downloads.txt but with links to the latest urls instead
# e.g.
-thaumcraft.jar https://minecraft.curseforge.com/projects/thaumcraft/files/latest
-baubles.jar https://minecraft.curseforge.com/projects/baubles/files/latest
+thaumcraft.jar https://www.curseforge.com/minecraft/mc-mods/thaumcraft
+baubles.jar https://www.curseforge.com/minecraft/mc-mods/baubles
diff --git a/readme.md b/readme.md
index 80f43cd..13282e9 100644
--- a/readme.md
+++ b/readme.md
@@ -5,4 +5,18 @@ Script to update modpacks automatically
#### To Use
+First, install [Python 3](https://www.python.org/downloads/) and [Git](https://git-scm.com/downloads) and add them to your `$PATH`.
+Then, run `pip install requests` to install the Python Requests module (required to run the script).
+
Simply put the location of your `mods` folder in `pack-location.txt` and run `python update.py install`
+
+#### Maintenance:
+
+To check `version.txt` modlist for updates against `mods.txt` modlist, run `python update.py check_updates`.
+
+To automatically populate `version.txt` with the most recent versions of mods listed in `mods.txt` run `python update.py apply_updates`.
+
+Finally, to actually install mods from the list in `version.txt`, run `python update.py install`
+
+
+***NOTE***: `check_updates` and `apply_updates` require you have the `selenium` module installed
diff --git a/update.py b/update.py
index 3404175..2727306 100755
--- a/update.py
+++ b/update.py
@@ -5,6 +5,7 @@ import os
import sys
import hashlib
import shutil
+import regex as re
import requests
@@ -91,21 +92,26 @@ def apply_updates(args):
print("Populating version File...")
mods = read_file(args.filename)
print("Getting new versions of all mods...")
+ ffx = firefox()
with open(args.version_file, 'w') as f:
f.write('# Format: <jarname> <hex digested sha1> <direct download url>\n')
f.write("#VERSION " + str(VERSION + 1) + "\n")
for mod in mods:
print("Fetching {mod[0]}...".format(mod=mod))
- resp = requests.get(mod[1])
+ url = find_cdn(ffx, mod[1])
+ if url is None:
+ print('Failed to fetch {mod[0]}!'.format(mod=mod))
+ continue
+ resp = requests.get(url)
hsh = hashlib.sha1(resp.content).hexdigest()
f.write('{mod[0]} {hsh} {resp.url}\n'.format(mod=mod, hsh=hsh, resp=resp))
+ ffx.close()
print()
print("Done!")
print("Updates applied to {args.version_file}".format(args=args))
print("New pack version is " + str(VERSION + 1))
print("[!] No mods were installed. To update your mods folder, run 'update.py install'")
-
# Find if any updates are available
def check_updates(args):
print("Checking for updates to version " + str(VERSION) + "...")
@@ -115,20 +121,53 @@ def check_updates(args):
num_updates = 0
print("Checking updates...")
+ ffx = firefox()
+
for mod in latest:
print("Checking for updates to {mod[0]}...".format(mod=mod), end="")
sys.stdout.flush() # takes care of line-buffered terminals
- resp = requests.get(mod[1])
- if resp.url in old_urls:
+ url = find_cdn(ffx, mod[1])
+ if url in old_urls:
print(" No updates")
else:
- print(" Found update: " + resp.url.split('/')[-1])
+ print(" Found update: " + url.split('/')[-1])
num_updates += 1
+ ffx.close()
print("Finished checking for updates. {num} mods can be updated".format(num=num_updates))
if num_updates >= 0:
print("Run 'python update.py apply_updates' to create a new version with these updates applied.")
+# Use selenium to find curseforge CDN links around cloudflare
+def find_cdn(ffx, url):
+ try:
+ ffx.get(url + '/download')
+ page_src = ffx.page_source
+ dl = re.search('Elerium.PublicProjectDownload.countdown\(".*?"\);', page_src)
+ if not dl:
+ return None
+ dl = re.search('\d+', dl.group(0).split('"')[1])
+ dl = dl.group(0)
+ four = str(int(dl[:4]))
+ three = str(int(dl[4:]))
+
+ ffx.get(url + '/files')
+ elements = ffx.find_elements_by_tag_name('tr')
+ file_name = elements[1].find_element_by_tag_name('a').text
+ return 'https://media.forgecdn.net/files/{four}/{three}/{jar}'.format(four=four,three=three,jar=file_name)
+
+ except:
+ return None
+
+def firefox():
+ print("Starting Selenium...")
+ try:
+ from selenium.webdriver import Firefox
+ except:
+ print("Applying updates requires the `selenium` package")
+ os.exit(0)
+ return Firefox()
+
COMMAND_MAP = {
'install': install,
'apply_updates': apply_updates,
diff --git a/version.txt b/version.txt
index eb901a8..710d578 100644
--- a/version.txt
+++ b/version.txt
@@ -1,4 +1,4 @@
# Format: <jarname> <hex digested sha1> <direct download url>
-#VERSION 16
-thaumcraft.jar ef9f8aaf4a4bfe29afb9ebc0fb90b15f2a62a0fb https://minecraft.curseforge.com/projects/thaumcraft/files/latest
-baubles.jar 498452d113a210bda499c49b650b4eae57866a19 https://minecraft.curseforge.com/projects/baubles/files/latest
+#VERSION 32
+thaumcraft.jar fe0899048f1796df04e9727bbf1898df30492a00 https://media.forgecdn.net/files/2629/23/Thaumcraft-1.12.2-6.1.BETA26.jar
+baubles.jar cb13fcfb18a9cb0cbd825fd5fe8d813c77368549 https://media.forgecdn.net/files/2518/667/Baubles-1.12-1.5.2.jar