2018-07-07 00:38:10 +02:00
#!/usr/bin/env python3
# -*- coding: utf8 -*-
# libray - Libre Blu-Ray PS3 ISO Tool
2026-05-18 16:31:58 +02:00
# Copyright © 2018 - 2024 Nichlas Severinsen
2019-05-16 10:37:28 +02:00
#
2018-07-07 00:38:10 +02:00
# This file is part of libray.
2019-05-16 10:37:28 +02:00
#
2018-07-07 00:38:10 +02:00
# libray is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
2019-05-16 10:37:28 +02:00
#
2018-07-07 00:38:10 +02:00
# libray is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
2019-05-16 10:37:28 +02:00
#
2018-07-07 00:38:10 +02:00
# You should have received a copy of the GNU General Public License
# along with libray. If not, see <https://www.gnu.org/licenses/>.
2026-05-21 09:14:20 +02:00
import multiprocessing
2018-07-09 07:40:41 +02:00
2026-05-21 09:14:20 +02:00
try :
multiprocessing . set_start_method ( ' spawn ' )
except RuntimeError :
pass
2026-05-19 17:41:17 +02:00
2018-07-07 00:38:10 +02:00
import argparse
2026-05-19 17:41:17 +02:00
import sys
2018-07-07 00:38:10 +02:00
2019-06-07 09:00:03 +02:00
2018-07-07 00:38:10 +02:00
try :
2026-05-18 16:31:58 +02:00
from libray import core
2018-07-07 00:38:10 +02:00
except ImportError :
2026-05-18 16:31:58 +02:00
import core
2018-07-07 00:38:10 +02:00
2026-05-19 17:41:17 +02:00
def main ( ) :
2026-05-18 16:31:58 +02:00
parser = argparse . ArgumentParser (
description = ' A Libre (FLOSS) Python application for unencrypting, extracting, repackaging, and encrypting PS3 ISOs ' )
2019-11-03 14:49:24 +01:00
2026-05-18 16:31:58 +02:00
required = parser . add_mutually_exclusive_group ( required = True )
required . add_argument ( ' -i ' , ' --iso ' , dest = ' iso ' , type = str , help = ' Path to .iso file or stream ' )
required . add_argument ( ' -k ' , ' --ird ' , dest = ' ird ' , type = str , help = ' Path to .ird file ' , default = ' ' )
2019-11-03 14:49:24 +01:00
2026-05-18 16:31:58 +02:00
optional = parser . add_argument_group ( ' optional arguments ' )
optional . add_argument ( ' -o ' , ' --output ' , dest = ' output ' , type = str , help = ' Output filename ' , default = ' ' )
optional . add_argument ( ' -d ' , ' --decryption-key ' , dest = ' decryption_key ' , type = str , help = ' Manually specify key ' , default = ' ' )
optional . add_argument ( ' -v ' , ' --verbose ' , dest = ' verbose ' , help = ' Increase verbosity ' , action = ' count ' )
optional . add_argument ( ' -q ' , ' --quiet ' , dest = ' quiet ' , help = ' Quiet mode, only prints on error ' , action = ' store_true ' )
# -e is reserved for "extract" so re-encrypt is "-r"
optional . add_argument ( ' -r ' , ' --re-encrypt ' , dest = ' reencrypt ' , help = ' Re-encrypt .iso ' , action = ' store_true ' )
optional . add_argument ( ' -c ' , ' --checksum ' , dest = ' checksum ' , help = ' Allow fallback to CRC32 checksum (disabled by default) ' , action = ' store_true ' )
optional . add_argument ( ' -t ' , ' --checksum-timeout ' , dest = ' checksum_timeout ' , type = int , help = ' How many seconds to wait for CRC32 checksum (default 15) ' , default = 15 )
2026-05-19 17:41:17 +02:00
optional . add_argument ( ' -p ' , ' --threads ' , dest = ' threads ' , type = int , help = ' Number of threads for parallel decryption/encryption (default: number of CPU cores) ' , default = 0 )
2026-05-18 16:31:58 +02:00
optional . add_argument ( ' --info ' , dest = ' info ' , action = ' store_true ' , help = ' Print info about .iso or .ird, then quit. ' )
2021-06-02 17:20:01 +02:00
2026-05-18 16:31:58 +02:00
args = parser . parse_args ( )
2018-07-07 00:38:10 +02:00
2026-05-18 16:31:58 +02:00
if args . info :
core . info ( args )
2021-06-02 20:25:49 +02:00
2026-05-18 16:31:58 +02:00
if not args . iso :
core . error ( ' No .iso file given. Use -i/--iso path/to/file.iso ' )
2021-06-02 20:25:49 +02:00
2026-05-18 16:31:58 +02:00
if args . reencrypt :
core . encrypt ( args )
else :
core . decrypt ( args )
2026-05-19 17:41:17 +02:00
if __name__ == ' __main__ ' :
main ( )