Advertisement
TheWhiteTyger

Python Script for PS4 DLC

Apr 19th, 2019
1,463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.91 KB | None | 0 0
  1. #HOW TO USE
  2. #INSTALL PYTHON (TESTED WITH 3.6)
  3. #NAVIGATE TO PYTHON INSTALLATION'S SCRIPTS FOLDER
  4. #USE THE COMMAND 'pip install requests' IN THIS FOLDER VIA COMMAND LINE
  5. #COPY THIS ENTIRE TEXT
  6. #SAVE IT AS "mydlc.py" ANYWHERE YOU LIKE
  7. #DOUBLE CLICK "mydlc.py"
  8. #THE PROGRAM WILL BEGIN RUNNING
  9. #READ ALL PROMPTS. ADDITIONAL STEPS ARE REQUIRED.
  10. #INSTALL ALL CREATED PKGS
  11.  
  12. #This script contains no content which in any way
  13. #Infringes on the Intellectual Property of Sony.
  14.  
  15. #Package creation is done solely through a third
  16. #party tool that the user may choose to download.
  17.  
  18. #This script seeks to read publicly viewable
  19. #PSN Storepages and parse the publicly available
  20. #DLC names and IDs.
  21.  
  22. #Absolutely no ownership of this script is claimed by the uploader.
  23.  
  24. import os
  25. import re
  26. import sys
  27. import time
  28.  
  29. try:
  30. import requests
  31. except:
  32. print("Required library \"requests\" could not be loaded\nPlease perform a 'pip install requests'\nin your Python's \"Scripts\" folder.")
  33. input("Press enter to close this program")
  34. sys.exit()
  35.  
  36. s = requests.Session() #Global requests session for all future network activity
  37. waittime = 2
  38.  
  39. def download(url, fname):
  40. r = s.get(url)
  41. with open(fname, 'wb') as f:
  42. for chunk in r.iter_content(chunk_size=1024):
  43. if chunk:
  44. f.write(chunk)
  45. print("Download Complete!")
  46. return 1
  47.  
  48. def textReplace(fname, look4, replacement):
  49. with open(fname, 'r') as file :
  50. filedata = file.read()
  51.  
  52. if look4 in filedata:
  53. print("Replacing \"", look4, "\" with '", replacement, "' in ", fname)
  54. filedata = filedata.replace(look4, replacement)
  55. with open(fname, 'w') as file:
  56. file.write(filedata)
  57. return 1
  58. return 0
  59.  
  60. def prerequisite():
  61. psxhaxurl = "https://www.psxhax.com/threads/fake-pkg-generator-for-ps4-to-generate-fake-packages-for-homebrew.3444/"
  62. pastebinurl = "https://pastebin.com/raw/amqJduwg"
  63. if not os.path.exists('ez_dlc.py'):
  64. print("Downloading \'ez_dlc.py\' from pastebin.\n", pastebinurl)
  65. try:
  66. download( pastebinurl, "ez_dlc.py" )
  67. except:
  68. print("Downloading ez_dlc.py from ", pastebinurl, " failed")
  69. input("Press enter to close this program")
  70. sys.exit()
  71. if not os.path.exists('orbis-pub-cmd.exe'):
  72. print("Please read the \"readme.txt\".\norbis-pub-cmd.exe must be in the same folder as this python script\n\nDownload from\n", psxhaxurl)
  73. input("Press enter to close this program")
  74. sys.exit()
  75.  
  76. textReplace("ez_dlc.py", "return open(path, 'w')", "return open(path, 'w', encoding=\"utf-8\")") #FIX ENCODING ISSUE WITH EZ_DLC.PY
  77. return 1
  78.  
  79. def downloadDLC(inputstorepage):
  80. fulltitleID = inputstorepage.split('/')[-1]
  81. region = inputstorepage.split('/')[-3]
  82. addonpage = "https://store.playstation.com/" + region + "/grid/" + str(fulltitleID) + "/" + str(1) + "?relationship=add-ons?platform=ps4"
  83. print("TITLE_ID: ", fulltitleID)
  84. print("ADDON_PAGE: ", addonpage)
  85.  
  86. r = s.get(addonpage)
  87.  
  88. numofpages = 1
  89. try:
  90. numofpages = int(max(re.findall("\w\w-\w\w/grid/\w\w\d+-\wUSA\d+_\d+-.*?/(\d+)", r.text)))
  91. except:
  92. numofpages = 1
  93. print("Found ", numofpages, " pages of content.")
  94.  
  95. for i in range(1, numofpages+1):
  96. print("Handling Page ", i, "\n")
  97. r = s.get( "https://store.playstation.com/" + region + "/grid/" + fulltitleID + "/" + str(i) + "?relationship=add-ons" )
  98. DLClist = re.findall("\"Product\",\"name\":\"(.*?)\".*?sku\":\"(.*?)\"", r.text)
  99. for DLC in DLClist:
  100. print(DLC[0], DLC[1])
  101. command = "ez_dlc.py " + DLC[1] + " \"" + DLC[0] + "\""
  102. print("Running Command: ", command)
  103. os.system(command)
  104. print("\n")
  105.  
  106. print("Waiting 2 seconds between DLCs.")
  107. time.sleep(waittime)
  108.  
  109. if i < numofpages:
  110. print("Waiting ", waittime, " seconds between processing pages.")
  111. time.sleep(waittime)
  112. try:
  113. os.rename("fake_dlc_pkg", fulltitleID[7:])
  114. except:
  115. pass
  116.  
  117. return 1
  118.  
  119. def regURL(url, regexp):
  120. r = s.get(url)
  121. pattern = re.findall(regexp, r.text)
  122. return pattern
  123.  
  124. def getpkglist(inputdir):
  125. pkglist = []
  126. for path, subdirs, files in os.walk(inputdir):
  127. for name in files:
  128. if ".pkg" in name:
  129. pkglist.append(os.path.join(path, name))
  130. return pkglist
  131.  
  132. def determinepkgid(inputfpath): #Tries to read 36 character TITLEID from beginning of PKG #0x40 - 0x64
  133. mystr = ""
  134. print(inputfpath)
  135. with open(inputfpath, "rb") as input:
  136. data = input.read(128)
  137. for i in range (64, 100+1):
  138. mystr+= (str(chr(data[i])))
  139. return mystr.replace(" ", "")
  140.  
  141. prerequisite()
  142.  
  143. #USER PASTES A SINGLE PSN STORE PAGE. ALL DLC ON PAGE DOWNLOADED
  144. userinput = True
  145.  
  146. #USER PASTES A DIRECTORY CONTAINING PKG (ALSO SCANS SUBDIRECTORIES). ATTEMPTS TO DOWNLOAD DLC FOR ALL PKGS
  147. dirscan = False
  148.  
  149. #SIMPLE TEST ON SINGLE PRE-DEFINED PSN STORE PAGE
  150. performtest = False
  151.  
  152. if(dirscan):
  153. inputdir = input("Paste a directory containing pkgs: ")
  154. mypkglist = getpkglist(inputdir)
  155. for pkg in mypkglist:
  156. pkgid = determinepkgid(pkg)
  157. psnpage = ""
  158. pkgregion = pkgid[:2]
  159. if(pkgregion == "UP"):
  160. psnpage = "https://store.playstation.com/en-us/product/" + pkgid
  161. elif(pkgregion == "EP"):
  162. psnpage = "https://store.playstation.com/en-gb/product/" + pkgid
  163. elif(pkgregion == "HP"):
  164. psnpage = "https://store.playstation.com/en-hk/product/" + pkgid
  165. elif(pkgregion == "JP"):
  166. psnpage = "https://store.playstation.com/ja-jp/product/" + pkgid
  167. else:
  168. psnpage = "error!"
  169.  
  170. psnpage = psnpage[:-1]
  171.  
  172. print(psnpage)
  173. try:
  174. print(" ")
  175. downloadDLC(psnpage)
  176. except:
  177. pass
  178.  
  179. if(performtest):
  180. storepage = "https://store.playstation.com/en-gb/product/UP9000-CUSA03694_00-GRAVITYRUSH20000" #WORKS
  181. downloadDLC(storepage)
  182.  
  183. if(userinput):
  184. print("Please paste a link to a PSN game store page which contains \"add-on\" content.\nExample: https://store.playstation.com/en-us/product/UP8802-CUSA02084_00-RBEXPANSIONPACK1\n")
  185. storepage = input("PASTE HERE: ")
  186. downloadDLC(storepage)
  187.  
  188. print("Program Completed.")
  189. input("Press enter to close this program")
  190. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement