aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Hayden <alexhayden25@gmail.com>2020-01-06 13:22:44 -0500
committerAlexander Hayden <alexhayden25@gmail.com>2020-01-06 13:22:44 -0500
commit4e71cec0538cba9566103092aadeb8c1ecdd77ed (patch)
tree5ff1f8d0891bdb4ccdf2bf87cf362a167c50b8fc
parentf2e28a205b2534492381eb8e630cf2706eadbc16 (diff)
downloadmodpackman-4e71cec0538cba9566103092aadeb8c1ecdd77ed.tar.gz
modpackman-4e71cec0538cba9566103092aadeb8c1ecdd77ed.zip
update update.py to match master branch
-rwxr-xr-xupdate.py60
1 files changed, 54 insertions, 6 deletions
diff --git a/update.py b/update.py
index 3404175..a7d3ab2 100755
--- a/update.py
+++ b/update.py
@@ -5,6 +5,7 @@ import os
import sys
import hashlib
import shutil
+import re
import requests
@@ -63,17 +64,20 @@ def install(args):
# whitelist client mods (e.g. optifine)
names += [line[0] for line in read_file(args.whitelist_file)]
+ i = 0
for mod in mods:
mod_path = os.path.join(args.pack_location, mod[0])
+ i += 1
if os.path.exists(mod_path) and os.path.isfile(mod_path) and \
hashlib.sha1(open(mod_path, 'rb').read()).hexdigest() == mod[1]:
print("Skipping {mod[0]}, already up to date".format(mod=mod))
else:
print('Installing {mod[0]} from {mod[2]}...'.format(mod=mod))
+ print(' ({i} of {x})'.format(i=i,x=len(mods)), end='\r')
download_obj = requests.get(mod[2], stream=True)
with open(mod_path, "wb") as write_file:
shutil.copyfileobj(download_obj.raw, write_file)
- print("Done!")
+ print("Done!" + " " * 8)
print()
print("Removing old mods...")
@@ -91,21 +95,29 @@ 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])
+ if 'curseforge' in mod[1]:
+ url = find_cdn(ffx, mod[1])
+ else:
+ url = requests.get(mod[1]).url
+ 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 +127,56 @@ 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:
+ if 'curseforge' in mod[1]:
+ url = find_cdn(ffx, mod[1])
+ else:
+ url = requests.get(mod[1]).url
+ 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')
+ ffx.get(url + '/files')
+ #page_src = ffx.page_source
+ #dl = re.search('Elerium.PublicProjectDownload.countdown\(".*?"\);', page_src)
+ #if not dl:
+ # return None
+ dl = ffx.find_element_by_xpath("html/body/div/main/div/div/section/div/div/div/section/article/div/div/a").get_attribute("href")
+ dl = re.search('\d{7}', dl)
+ dl = dl.group(0)
+ four = str(int(dl[:4]))
+ three = str(int(dl[4:]))
+
+ file_name = ffx.find_elements_by_xpath("html/body/div/main/div/div/section/div/div/div/section/article/div/div/span[contains(@class, 'text-sm')]")[1].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,