import requests
import urllib
if __name__ == '__main__':
#go here: https://library.playstation.com/recently-purchased?smcid=web-store%3Aen-us%3Aweb-toolbar-my-playstation%3Agame%20library
#in dev tools should see a get to something like:
#https://web.np.playstation.com/api/graphql/v1/op?operationName=backwardCompatibility...
#copy the cookies here:
cookies = 'cookies go here'
cookies = cookies.split(';')
cookies = [c.split('=') for c in cookies]
cookies ={c[0]:c[1] for c in cookies}
session = requests.Session()
#Copy that https://web.np.playstation.com/api/graphql/v1/op?operationName=backwardCompatibility... link from above
#and replace the title ids list after 'variables=' with {}, leave the other params (extensions, version, persistedQuery, etc..)
url = 'https://web.np.playstation.com/api/graphql/v1/op?operationName=backwardCompatibility&variables={}&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%22hashgoeshere%22%7D%7D'
bootables = []
#I'm doing this in 250 title chunks at a time, only did first 1000 to test.
for i in range(1, 1000, 250):
ids = ['CUSA{}'.format(str(j).rjust(5, '0')) for j in range(i, i+250)]
titleIds = '{{"titleIds":"{}"}}'.format(','.join(ids))
urlWithIds = url.format(urllib.parse.quote(titleIds))
r = session.get(urlWithIds, cookies=cookies)
j = r.json()
data = j['data']['backwardsCompatibilityRetrieve']['titleBackwardsCompatibilityList']
for title in data:
if title['category'] == 'BOOTABLE':
bootables.append(title['titleId'])
#https://ps4database.io can give the title from the title id
#note that requests are limited to 500/hr
names = []
for b in bootables:
try:
r = session.get('https://ps4database.io/dataApi?id={}_00&env=NP&method=meta'.format(b))
j = r.json()
name = j['names'][0]['name']
names.append(name)
except Exception:
print('could not get data for {}'.format(b))
continue
#There are different title ids per region remove duplicates
names = set(names)
names = sorted(names, key=lambda x: x.lower())
#write to file
with open('bootableTitles.txt', 'w', encoding='utf-16') as f:
f.write('\n'.join(names))