Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Mabengoogly updater thinger.
- #Lots of Googling needed because I don't know Python but it was the best for this job.
- #Inconsistent variable naming scheme ahoy because of lazy copy-pasting.
- #I like turtles. Always remember this.
- #Get some functions.
- #Nomenclature.
- import urllib.request
- import urllib.error
- import zlib
- import base64
- import json
- import os
- import sys
- #Ask the user what version of the game they want to grab info for.
- v_version = sys.argv[1]
- print("")
- #Get the manifest hashy thing for that version of the game (10200 = Mabinogi).
- v_url = 'https://download2.nexon.net/Game/nxl/games/10200/10200.' + v_version + 'R.manifest.hash'
- print(v_url)
- #Read that file to see the next filename (actual manifest).
- #Yes, the hash that shows up is the actual filename in the same directory.
- v_hashfile = urllib.request.urlopen(v_url).read()
- v_hashfile = v_hashfile.decode('utf8')
- #Grab the actual manifest now (that hash filename).
- v_url = 'https://download2.nexon.net/Game/nxl/games/10200/' + v_hashfile
- print(v_url)
- print("Manifest downloaded.")
- v_filelist = urllib.request.urlopen(v_url).read()
- #Now we need to uncompress the manifest.
- #It has the list of files, packs, mp3s, dlls, etc.
- v_manifestcontents = zlib.decompress(v_filelist)
- print("Manifest decompressed.\n")
- #Ask the user if they want to save the manifest.
- v_dumpmanifest = 'y'
- #If the user said yes, save it.
- if v_dumpmanifest in ('y', 'Y', 'yes', 'Yes'):
- with open("manifest.txt", 'wb') as f:
- f.write(v_manifestcontents)
- print("Saved as .\\manifest.txt")
- #It's JSON, so load it and junk.
- v_manifestcontents = json.loads(v_manifestcontents.decode('utf8'))
- #Use the encoding specified in the manifest file.
- #Because readable text is important.
- v_manifestencodingtype = v_manifestcontents['filepath_encoding']
- #Ask the user what they want to do with this info.
- print("")
- #If we're going to dump the filename list...
- v_filelist = []
- for encoded_filename, contents in v_manifestcontents['files'].items():
- #Gotta' decode the names.
- filename = base64.b64decode(encoded_filename).decode(v_manifestencodingtype)
- v_filelist.append(filename)
- #Sort the file list because it's in a crazy jumble normally.
- with open('filelist.txt', 'w') as f:
- f.write('\n'.join(list(sorted(v_filelist))))
- print("Saved as filelist.txt.")
- #Ask for a specific file, find it, download the parts, merge them and save it.
- v_goalfile = sys.argv[2]
- print("")
- #Loop through to get the parts.
- for encoded_filename, contents in v_manifestcontents['files'].items():
- #The filenames in the manifest are base64 encoded, gotta' deal with that.
- filename = base64.b64decode(encoded_filename).decode(v_manifestencodingtype)
- #If it's the file the user requested...
- if filename == v_goalfile:
- #Files may be split up.
- v_piecedpatch = b""
- for item in contents['objects']:
- #Construct the download URL for each part of the file.
- v_parturl = 'https://download2.nexon.net/Game/nxl/games/10200/10200/' + item[:2] + "/" + item
- print(v_parturl)
- #Download and uncompress each part, append them together (binary join like copy /b).
- v_piecedpatch += zlib.decompress(urllib.request.urlopen(v_parturl).read())
- #Make the directory if needed, save the resulting file.
- os.makedirs(os.path.dirname(filename),exist_ok=True)
- with open(filename, 'wb') as f:
- f.write(v_piecedpatch)
- print("Saved as .\\"+filename)
Add Comment
Please, Sign In to add comment