Skip to content

Commit

Permalink
Merge pull request #2 from GarnetSunset/gui
Browse files Browse the repository at this point in the history
Gui
  • Loading branch information
GarnetSunset authored Jan 25, 2022
2 parents 71a6099 + c1df6af commit 429613f
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 16 deletions.
76 changes: 60 additions & 16 deletions dlcIndex.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import sys
import requests
from datetime import datetime
from os import makedirs, system
from shutil import rmtree
from tkinter import filedialog
from urllib.request import urlretrieve
import requests


def genGP4(contentName, contentID):
def gen_gp4(content_name, full_id, pkg_location):
gp4_template = """<?xml version="1.0"?>
<psproject xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" fmt="gp4" version="1000">
<volume>
Expand All @@ -23,10 +24,10 @@ def genGP4(contentName, contentID):
</rootdir>
</psproject>""" % (
gen_time,
contentID,
full_id,
)

makedirs(f"fake_dlc_pkg/{contentID[7:16]}", exist_ok=True)
makedirs(f"{pkg_location}/{full_id[7:16]}", exist_ok=True)
makedirs("fake_dlc_temp/sce_sys", exist_ok=True)

x = open("fake_dlc_temp/fake_dlc_project.gp4", "w")
Expand All @@ -43,27 +44,30 @@ def genGP4(contentName, contentID):
)
system(
"PkgTool.exe sfo_setentry --value "
+ contentID
+ full_id
+ " --type utf8 --maxsize 48 fake_dlc_temp\sce_sys\param.sfo CONTENT_ID"
)
system(
"PkgTool.exe sfo_setentry --value obs --type utf8 --maxsize 4 fake_dlc_temp\sce_sys\param.sfo FORMAT"
)
system(
'PkgTool.exe sfo_setentry --value "'
+ contentName
+ content_name
+ '" --type utf8 --maxsize 128 fake_dlc_temp\sce_sys\param.sfo TITLE'
)
system(
"PkgTool.exe sfo_setentry --value "
+ contentID[7:16]
+ full_id[7:16]
+ " --type utf8 --maxsize 12 fake_dlc_temp\sce_sys\param.sfo TITLE_ID"
)
system(
"PkgTool.exe sfo_setentry --value 01.00 --type utf8 --maxsize 8 fake_dlc_temp\sce_sys\param.sfo VERSION"
)


URL = None
pkg_location = "fake_dlc_pkg"

store_code_mappings = {
"de-de": "DE/de",
"gb-de": "GB/en",
Expand All @@ -72,20 +76,61 @@ def genGP4(contentName, contentID):
"ja-jp": "JP/ja",
}

if len(sys.argv) == 1:
if len(sys.argv) < 2:
try:
import tkinter as tk

root = tk.Tk()
root.title("DLC Indexer")
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
root.geometry(f"{int(screen_width / 4)}x{int(screen_height / 8)}")
lbl = tk.Label(
root,
text="Input the URL of the game you want the DLC for in this "
"format:\nhttps://store.playstation.com/**-**/product/HP0700-CUSA00000_00"
"-0000ENDOFTHEURL0",
)
lbl.pack()

def get_url():
global URL
URL = text_input_field.get(1.0, "end-1c")
root.destroy()

text_input_field = tk.Text(root, height=1, width=20)
text_input_field.pack()
printButton = tk.Button(root, text="Next", command=get_url)
printButton.pack()
root.mainloop()
root = tk.Tk()
root.withdraw()
root.update()
pkg_location = filedialog.askdirectory(
title="Select the directory where you want the DLCs to be stored"
)
root.destroy()

except ModuleNotFoundError:
print("No tkinter found, proceeding in text only mode")

if len(sys.argv) == 1 and URL is None:
URL = input(
"Input the URL of the game you want the DLC for in this format:\nhttps://store.playstation.com/**-**/product/HP0700-CUSA00000_00-0000ENDOFTHEURL0\n>"
"Input the URL of the game you want the DLC for in this "
"format:\nhttps://store.playstation.com/**-**/product/HP0700-CUSA00000_00-0000ENDOFTHEURL0\n> "
)
elif len(sys.argv) > 1:
URL = sys.argv[1]
elif URL is not None:
pass
else:
exit("No URL provided")

gen_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
region = URL.split("/")[3]
contentID = URL.split("/")[5]
content_id = URL.split("/")[5]

chihiro_base_url = f"https://store.playstation.com/store/api/chihiro/00_09_000/container/{store_code_mappings[region]}/999/{contentID}?relationship=ADD-ONS%27"
chihiro_base_url = f"https://store.playstation.com/store/api/chihiro/00_09_000/container/{store_code_mappings[region]}/999/{content_id}?relationship=ADD-ONS%27"
response = requests.get(chihiro_base_url)
item = response.json()

Expand All @@ -107,11 +152,10 @@ def genGP4(contentName, contentID):
if dlcList == {}:
exit("No DLC found")

for name, contentID in dlcList.items():
genGP4(name, contentID)
for name, content_id in dlcList.items():
gen_gp4(name, content_id, pkg_location)
system(
"PkgTool.exe pkg_build fake_dlc_temp\\fake_dlc_project.gp4 fake_dlc_pkg/"
+ contentID[7:16]
f"PkgTool.exe pkg_build fake_dlc_temp\\fake_dlc_project.gp4 {pkg_location}/{content_id[7:16]}"
)
rmtree("fake_dlc_temp")
print(f"Created DLC for {name} with contentID {contentID}")
print(f"Created DLC for {name} with contentID {content_id}")
38 changes: 38 additions & 0 deletions pre-commit-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
repos:

# black code formatter
- repo: https://github.com/ambv/black
rev: 21.10b0
hooks:
- id: black
args: # arguments to configure black
- --line-length=88

# language should be local
language_version: python3.6


# flake8 pep checks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: flake8
args: # arguments to configure flake8
- "--max-line-length=88"
# These folders will be excluded
- "--exclude=build,dist,*__init__.py"
# Sometimes flake and black have conflicts
# E203 whitespace before :
# W503 line break before binary operator
- "--ignore=E203,W503"

# pytest check
- repo: local
hooks:
- id: pytest-check
name: pytest-check
entry: pytest
language: system
pass_filenames: false
always_run: true

0 comments on commit 429613f

Please sign in to comment.