Created
August 27, 2022 20:07
-
-
Save lambdan/bcef75377f3720c12c3764c10051feaa to your computer and use it in GitHub Desktop.
nopaystation rap/pkg bundler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# if you know you know | |
import os, shutil | |
out_folder = "./bundled/" | |
pkg_folder = "./packages/" | |
rap_folder = "./exdata/" | |
rap_files = [] | |
if not os.path.isdir(out_folder): | |
os.makedirs(out_folder) | |
# check what rap files we have | |
for f in os.listdir(rap_folder): | |
if os.path.splitext(f)[1].lower() == ".rap": | |
rap_files.append(f) | |
# parse title ID's out of the rap file names | |
title_ids = [] | |
for r in rap_files: | |
title_id = r.split("_")[0] | |
title_ids.append(title_id) | |
# read first 50 bytes of pkg files and check if any title id is in there | |
for f in os.listdir(pkg_folder): | |
if os.path.splitext(f)[1].lower() == ".pkg": | |
data = [] | |
fp = os.path.join(pkg_folder, f) | |
with open(fp, "rb") as pkg: | |
while len(data) < 100: | |
data.append(pkg.read(1)) # read 1 byte | |
s = "" | |
for d in data: | |
char = d.decode('iso-8859-1') | |
s += char | |
for t in title_ids: | |
if t in s: | |
print(f, "=", t) | |
# make destination folder | |
game_name = os.path.splitext(os.path.basename(f))[0] | |
dest_folder = os.path.join(out_folder, game_name + " [" + t + "]") | |
for d in os.listdir(out_folder): | |
if t in d: | |
dest_folder = os.path.join(out_folder, d) | |
if not os.path.isdir(dest_folder): | |
os.makedirs(dest_folder) | |
pkg_src = os.path.join(pkg_folder, f) | |
# find rap file | |
rap_src = False | |
for r in rap_files: | |
if t in r: | |
rap_src = os.path.join(rap_folder, r) | |
break | |
if t not in f: | |
new_pkg_name = os.path.splitext(f)[0] + " [" + t + "]" + os.path.splitext(f)[1] # add id to pkg name | |
else: | |
new_pkg_name = f | |
pkg_dest = os.path.join(dest_folder, new_pkg_name) | |
rap_dest = os.path.join(dest_folder, os.path.basename(rap_src)) | |
print(pkg_src, "-->", pkg_dest) | |
if not os.path.isfile(pkg_dest) and os.path.isfile(pkg_src): | |
shutil.move(pkg_src, pkg_dest) | |
print(rap_src, "-->", rap_dest) | |
if not os.path.isfile(rap_dest) and os.path.isfile(rap_src): | |
shutil.move(rap_src, rap_dest) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment