-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_nopaystation_to_pkgi.py
123 lines (112 loc) · 4.61 KB
/
convert_nopaystation_to_pkgi.py
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
import requests
import csv
from pathlib import Path
# Input / Output folder
INPUT_FOLDER = Path("input")
OUTPUT_FOLDER = Path("output")
# define the downloads
# content_type : https://github.com/bucanero/pkgi-ps3?tab=readme-ov-file#content-types
downloads = {
"PS3_GAMES": {
"input": "PS3_GAMES.tsv",
"output": "pkgi_games.csv",
"content_type": "1",
"download_link": "https://nopaystation.com/tsv/PS3_GAMES.tsv"
},
"PS3_DLCS": {
"input": "PS3_DLCS.tsv",
"output": "pkgi_dlcs.csv",
"content_type": "2",
"download_link": "https://nopaystation.com/tsv/PS3_DLCS.tsv"
},
"PS3_THEMES": {
"input": "PS3_THEMES.tsv",
"output": "pkgi_themes.csv",
"content_type": "3",
"download_link": "https://nopaystation.com/tsv/PS3_THEMES.tsv"
},
"PS3_AVATARS": {
"input": "PS3_AVATARS.tsv",
"output": "pkgi_avatars.csv",
"content_type": "4",
"download_link": "https://nopaystation.com/tsv/PS3_AVATARS.tsv"
},
"PS3_DEMOS": {
"input": "PS3_DEMOS.tsv",
"output": "pkgi_demos.csv",
"content_type": "5",
"download_link": "https://nopaystation.com/tsv/PS3_DEMOS.tsv"
},
"PS3_GAMES (pending)": {
"input": "pending_PS3_GAMES.tsv",
"output": "pkgi_games_pending.csv",
"content_type": "1",
"download_link": "https://nopaystation.com/tsv/pending/PS3_GAMES.tsv"
},
"PS3_DLCS (pending)": {
"input": "pending_PS3_DLCS.tsv",
"output": "pkgi_dlcs_pending.csv",
"content_type": "2",
"download_link": "https://nopaystation.com/tsv/pending/PS3_DLCS.tsv"
},
"PS3_THEMES (pending)": {
"input": "pending_PS3_THEMES.tsv",
"output": "pkgi_themes_pending.csv",
"content_type": "3",
"download_link": "https://nopaystation.com/tsv/pending/PS3_THEMES.tsv"
},
"PS3_AVATARS (pending)": {
"input": "pending_PS3_AVATARS.tsv",
"output": "pkgi_avatars_pending.csv",
"content_type": "4",
"download_link": "https://nopaystation.com/tsv/pending/PS3_AVATARS.tsv"
},
"PS3_DEMOS (pending)": {
"input": "pending_PS3_DEMOS.tsv",
"output": "pkgi_demos_pending.csv",
"content_type": "5",
"download_link": "https://nopaystation.com/tsv/pending/PS3_DEMOS.tsv"
},
}
# Create a function to format a row as per your specifications
# Title ID Region Name PKG direct link RAP Content ID Last Modification Date Download .RAP file File Size SHA256
def format_row(row, content_type):
content_id = row['Content ID']
content_type = content_type # Set type
name = f"{row['Name']} ({row['Region']})"
description = '' # Description is empty
rap = row['RAP'] if 'RAP' in row else '' # Leave empty if rap is not needed
url = row['PKG direct link']
size = row['File Size'] if 'File Size' in row else '0' # Set size to 0 if unknown
checksum = row.get('SHA256', '') # Leave empty if checksum is not needed
date = row['Last Modification Date'] # Extract DATE from "Last Modification Date"
region = row['Region'] # Extract REGION from "Region"
formatted_row = [content_id, content_type, name, description, rap, url, size, checksum, date, region]
return formatted_row
# process a given item
def process_entries(item):
input_file = INPUT_FOLDER / item["input"]
output_file = OUTPUT_FOLDER / item["output"]
content_type = item["content_type"]
# Download file and store it in file
response = requests.get(item["download_link"], stream=True)
with open(input_file, 'wb') as out_file:
for chunk in response.iter_content(chunk_size=1024):
out_file.write(chunk)
# Read the TSV file and write to the CSV file with the specified format
with open(input_file, 'r', newline='', encoding='utf-8') as tsvfile, open(output_file, 'w', newline='', encoding='utf-8') as csvfile:
tsvreader = csv.DictReader(tsvfile, delimiter='\t')
csvwriter = csv.writer(csvfile, delimiter=';')
# Write the header row to the CSV file
# csvwriter.writerow(['contentid', 'type', 'name', 'description', 'rap', 'url', 'size', 'checksum', 'date', 'region'])
# Process and write the remaining rows
for row in tsvreader:
formatted_row = format_row(row, content_type)
csvwriter.writerow(formatted_row)
for entry in downloads.items():
(entryName, entryObj) = entry
try:
print(f"'{entryName}' - Processing ...")
process_entries(entryObj)
except Exception as error:
print("An exception occurred:", error)