Created
December 12, 2019 01:18
-
-
Save pxdl/880380e4647b1d94359824264d8ce6f1 to your computer and use it in GitHub Desktop.
Converts the NoPayStation TSV for PS3 Games to pkgi-ps3 format (needs "raps" folder with corresponding rap files)
This file contains hidden or 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
import csv | |
import urllib.request | |
import binascii | |
from pathlib import Path | |
def downloadTSV(): | |
print('Downloading PS3_GAMES.tsv...') | |
url = "http://nopaystation.com/tsv/PS3_GAMES.tsv" | |
urllib.request.urlretrieve(url, 'PS3_GAMES.tsv') | |
return 1 | |
def buildDict(): | |
# Build rap dict | |
print('Building rap dict...') | |
rapdict = {} | |
raplist = Path('./raps').glob('*.rap') | |
for rap in raplist: | |
with open(str(rap), 'rb') as rapfile: | |
rr = rapfile.read(16) | |
bytestring = binascii.hexlify(rr).decode('utf-8') | |
rapdict[rap.stem] = bytestring | |
return rapdict | |
def openTSV(): | |
# Open and rearrange rows | |
try: | |
oldlist = [] | |
with open('PS3_GAMES.tsv', newline='', encoding="utf8") as csvfile: | |
csvfile.readline() # Skip first line | |
listreader = csv.reader(csvfile, delimiter=' ', quotechar='"') | |
for row in listreader: | |
oldlist.append(row) | |
return oldlist | |
except FileNotFoundError: | |
if(downloadTSV()): | |
print('TSV Downloaded Successfully') | |
openTSV() | |
def rearrangeRows(rapdict): | |
newlist = [] | |
oldlist = openTSV() | |
#missingkeys = 0 | |
print("Rearranging list...") | |
for row in oldlist: | |
newrow = [] | |
newrow.append(row[5]) # Content ID | |
newrow.append('0') # Flags (unused) | |
newrow.append(row[2].replace(",","")) # Name | |
newrow.append('') # Description (unused) | |
try: | |
newrow.append(rapdict[row[5]]) # RAP file in HEX (16 bytes) | |
except KeyError: | |
# print('{} rap not found.'.format(row[5])) | |
#missingkeys = missingkeys + 1 | |
continue | |
newrow.append(row[3]) # PKG Download Link | |
newrow.append(row[8]) # Filesize | |
newrow.append(row[9]) # Checksum | |
newlist.append(newrow) | |
print('Found {} matching raps.'.format(len(newlist))) | |
return newlist | |
def saveList(newlist): | |
# Save new list | |
with open('pkgi.txt', 'w', newline='', encoding="utf8") as csvfile: | |
listwriter = csv.writer(csvfile, delimiter=',', | |
quotechar='"', quoting=csv.QUOTE_MINIMAL) | |
print('Saving pkgi.txt...') | |
for newrow in newlist: | |
listwriter.writerow(newrow) | |
rapdict = buildDict() | |
newlist = rearrangeRows(rapdict) | |
saveList(newlist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment