This repository was archived by the owner on Nov 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_csv.py
More file actions
156 lines (142 loc) · 5.34 KB
/
Copy pathmain_csv.py
File metadata and controls
156 lines (142 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import requests
import csv
import json
import os
from pathlib import Path
#Empty placeholder values for url as they need to exist before they can be replaced within a for-loop
language = ""
country = ""
counter=0
with open("csv/lbp.csv", "r") as file:
csvFile = csv.reader(file)
next(csvFile)
for entries in csvFile:
counter+=1
contentID = entries[1]
serviceIDPrefix = contentID[0:6]
npTitleID = contentID[7:19]
entitlementID = contentID[20:36]
if serviceIDPrefix == "UP9000":
language = "en"
country = "us"
elif serviceIDPrefix == "EP9000":
language = "en"
country = "gb"
elif serviceIDPrefix == "HP9000":
language = "en"
country = "hk"
elif serviceIDPrefix == "JP9000":
language = "ja"
country = "jp"
url = (
"https://store.playstation.com/store/api/chihiro/00_09_000/container/"
+ country
+ "/"
+ language
+ "/999/"
+ contentID
)
# Request data from API
response = requests.get(url)
data = response.json()
# Save the data requested from API
try:
if Path("downloads/" + str(npTitleID) + "/" + str(entitlementID)).is_dir() == True:
try:
print(str(counter) + " | " + str(contentID) + " | " + data["name"] + " | Already exists")
except:
print(str(counter) + " | No available data")
continue
else:
#Create folders for entitlement ID that do not currently exist
os.makedirs(
"downloads/"
+ str(npTitleID)
+ "/"
+ str(entitlementID),
exist_ok=True
)
# Show current Content ID
print(str(counter)
+ " | "
+ data["id"]
+ " | "
+ data["name"]
)
# Output JSON data to file
json_str = json.dumps(data, indent=4)
with open(
"downloads/"
+ npTitleID
+ "/"
+ entitlementID
+ "/"
+ data["id"]
+ ".json",
"w",
) as file:
print("Saving... " + data["id"] + ".json")
file.write(json_str)
file.close()
# Output icon to file(s)
## Save icons extracted from JSON
for i in data["images"]:
if isinstance(i, dict):
for k, v in i.items():
if k == "url":
response = requests.get(v).content
with open(
"downloads/"
+ npTitleID
+ "/"
+ entitlementID
+ "/"
+ str(v[58:]),
"wb",
) as file:
print("Saving... " + str(v[58:]))
file.write(response)
file.close()
## Save icon from official API /image endpoint
response = requests.get(url + "/image").content
with open(
"downloads/"
+ npTitleID
+ "/"
+ entitlementID
+ "/"
+ data["id"]
+ ".jpg",
"wb",
) as file:
print("Saving... " + data["id"] + ".jpg")
file.write(response)
file.close()
## Save promomedia extracted from JSON
try:
for i in data["promomedia"][0]["materials"][0]["urls"]:
if isinstance(i, dict):
for k, v in i.items():
if k == "url":
response = requests.get(v).content
with open(
"downloads/"
+ npTitleID
+ "/"
+ entitlementID
+ "/"
+ str(v[49:]),
"wb",
) as file:
print("Saving... " + str(v[49:]))
file.write(response)
file.close()
except:
pass
print("\n", end="")
counter+=1
except:
os.rmdir("downloads/" + npTitleID + "/" + entitlementID)
with open("downloads/" + "errlog.log", "a") as file:
file.write(url+"\n")
file.close()