Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shinrax2 committed Aug 26, 2019
1 parent 85c7d1b commit 1d05509
Show file tree
Hide file tree
Showing 6 changed files with 8,339 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ venv.bak/

# mypy
.mypy_cache/

/downloadedPKGs
133 changes: 133 additions & 0 deletions PS3GameUpdateDownloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
#
# PS3GameUpdateDownloader by shinrax2

import argparse
import urllib.request
import ssl
import xml.etree.ElementTree as ET
import os
import hashlib
import requests
import sys

def download_file(url, local_filename):
with requests.get(url, stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)

pars = argparse.ArgumentParser(description="Downloads Updates for PS3 Games with given ID")
pars.add_argument("gameid", metavar="gameid", type=str, nargs=1, help="ID of a PS3 Game")

args = pars.parse_args()
if args.gameid[0] and args.gameid[0] != "" and type(args.gameid[0]) == str:
#config
dldir = "./downloadedPKGs/" #target dir for downloaded updates !!!END WITH TRAILING SLASH!!!
verify = False #verify checksums of downloaded updates DOESNT WORK ATM

#load title db
with open("titledb.txt", "r", encoding="utf8") as f:
data = []
for line in f:
item = {}
item["id"], item["name"] = line.split("\t\t")
if item["name"].endswith("\n"):
item["name"] = item["name"][:-1]
data.append(item)
titledb = data
#check given id
check = False
for item in titledb:
if args.gameid[0] == item["id"]:
check = True
gameid = args.gameid[0]
print("Game is: "+item["name"])
break
if check == False:
print("given gameid is not valid")
sys.exit(0)

#check for updates
updates = []
ssl._create_default_https_context = ssl._create_unverified_context # needed for sonys self signed cert
url = "https://a0.ww.np.dl.playstation.net/tpl/np/"+gameid+"/"+gameid+"-ver.xml"
try:
resp = urllib.request.urlopen(url)
except urllib.error.HTTPError:
print("meta file for this gameid is not available")
sys.exit(0)

data = resp.read()
info = data.decode('utf-8')
#check file length for ids like BCAS20074
if len(info) == 0:
print("meta file for this gameid contains no info")
sys.exit(0)
root = ET.fromstring(info)
if root.attrib["titleid"] == gameid:
for tag in root:
for package in tag:
pack = {}
attr = package.attrib
pack["version"] = attr["version"]
pack["size"] = attr["size"]
pack["sha1"] = attr["sha1sum"]
pack["url"] = attr["url"]
pack["sysver"] = attr["ps3_system_ver"]
updates.append(pack)
#ask user which to download
if len(updates)>0:
i = 1
dllist = []
print("updates found!\n")
for pack in updates:
print("package: "+str(i))
print("version: "+pack["version"])
print("size: "+str(format(float(pack["size"])/1024/1024, '.2f'))+"MB")
print("requires ps3 firmware version: "+pack["sysver"]+"\n")
i += 1
while True:
re = input("which package you want to download? enter package number or all: ")
if re.isdigit() == True:
if int(re) < len(updates) and int(re) > 0:
re = int(re) - 1
dllist.append(re)
break
else:
print("please enter a correct number or all")
elif re == "all":
for ii in range(0, len(updates)):
dllist.append(ii)
break
else:
print("please enter a correct number or all")
print("starting download of package(s)")
i = 1
for dl in dllist:
print("starting download "+str(i)+" of "+str(len(dllist)))
url = updates[dl]["url"]
sha1 = updates[dl]["sha1"]
fname = dldir+os.path.basename(url)
download_file(url, fname)
if verify == True:
fsha = hashlib.sha1()
with open(fname, "rb") as f:
for line in iter(lambda: f.read(65536), b''):
fsha.update(line)
if sha1 == fsha.hexdigest():
print('"'+fname+'" successfully verified')
else:
print('verification of "'+fname+'" failed')
if verify == False:
print("not verifying file!")
i += 1

print("finished downloading "+str(len(dllist))+" files!")
else:
print("no updates for this title found!")

input("please press enter to exit")
11 changes: 11 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
PS3GameUpdateDownloader
meant to assist in emulator use

how to use

pip install -r requirements.txt
python3 main.py GAMEID

how to build exe for windows
pip install pyinstaller
build.bat
4 changes: 4 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
pyinstaller PS3GameUpdateDownloader.py
copy titledb.txt dist\PS3GameUpdateDownloader\titledb.txt
mkdir dist\PS3GameUpdateDownloader\downloadedPKGs
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
Loading

0 comments on commit 1d05509

Please sign in to comment.