Change content subcommand to use 000000xx formatting for CID

This commit is contained in:
Campbell 2024-07-10 21:59:02 +10:00
parent 1b603e94fc
commit 8599c43c2d
Signed by: NinjaCheetah
GPG Key ID: 670C282B3291D63D
2 changed files with 9 additions and 5 deletions

View File

@ -4,6 +4,7 @@
import os
import hashlib
import pathlib
import binascii
import libWiiPy
@ -146,11 +147,13 @@ def handle_nus_content(args):
else:
decrypt_content = False
content_file_name = hex(cid)[2:]
content_id = int.from_bytes(binascii.unhexlify(cid))
content_file_name = hex(content_id)[2:]
while len(content_file_name) < 8:
content_file_name = "0" + content_file_name
content_data = libWiiPy.title.download_content(tid, cid)
content_data = libWiiPy.title.download_content(tid, content_id)
if decrypt_content is True:
content_file_name = content_file_name + ".app"
@ -167,7 +170,7 @@ def handle_nus_content(args):
content_size = 0
content_index = 0
for record in tmd.content_records:
if record.content_id == cid:
if record.content_id == content_id:
content_hash = record.content_hash.decode()
content_size = record.content_size
content_index = record.index
@ -186,4 +189,4 @@ def handle_nus_content(args):
file.write(content_data)
file.close()
print("Downloaded content with Content ID \"" + str(cid) + "\"!")
print("Downloaded content with Content ID \"" + cid + "\"!")

View File

@ -53,7 +53,8 @@ if __name__ == "__main__":
description="download a specific content from the NUS")
nus_content_parser.set_defaults(func=handle_nus_content)
nus_content_parser.add_argument("tid", metavar="TID", type=str, help="Title ID the content belongs to")
nus_content_parser.add_argument("cid", metavar="CID", type=int, help="Content ID to download")
nus_content_parser.add_argument("cid", metavar="CID", type=str,
help="Content ID to download (in \"000000xx\" format)")
nus_content_parser.add_argument("-v", "--version", metavar="VERSION", type=int,
help="version this content belongs to (required for decryption)")
nus_content_parser.add_argument("-d", "--decrypt", action="store_true", help="decrypt this content")