API Documentation¶
ps3iso package¶
ps3iso.game module¶
- class ps3iso.game.Game(iso_path)¶
Bases:
objectClass representing a set of files making up a Playstation 3 game An existing
.isofile must be passed, files with any extension matching the base name will be found and included in all operations- Parameters:
iso_path (Path or str) – Path to an existing .iso file
- classmethod extract_sfo(iso_path)¶
Read the PARAM.SFO data from an
.isofileSee also
- Parameters:
iso_path (
Union[str,Path]) – Path to the .iso file to read- Return type:
- format_file(f, fmt, fill='')¶
Return a new path for an input file, formatted according to the SFO data and format string. The existing file extension will be preserved.
See also
- Parameters:
f (
Union[str,Path]) – Path to an existing filefmt (
str) – Formatting string to use for new file namefill – String to use for replacing invalid characters
- Return type:
Path
- print_info(fmt=None)¶
Print information about the current game set. Accepts a custom output formatting string with SFO parameter variable expansion support
In addition to the variables described by
SfoFile.format(), the following will be also expanded:Variable
Parameter
%p
Full path of the existing file
%f
File name of the existing file
\n
Newline character
\t
Tab character
See also
- Parameters:
fmt (str) – Formatting string to use for output
- Return type:
None
- classmethod search(path)¶
Search for
.isofiles in the given path. Non-recursive and case-insensitive- Param:
Path to search
- Return type:
Iterator[Game]
ps3iso.sfo package¶
ps3iso.sfo.errors module¶
- exception ps3iso.sfo.errors.SfoUnknownParameterError¶
Bases:
ExceptionNamed Exception raised when a reference to an invalid parameter name is encountered
- exception ps3iso.sfo.errors.SfoMissingParameterError¶
Bases:
ExceptionNamed Exception raised when an SfoFile is missing a required parameter
- exception ps3iso.sfo.errors.SfoDuplicateParameterError¶
Bases:
ExceptionNamed Exception raised when a duplicate SFO parameter is encountered in an SfoFile
- exception ps3iso.sfo.errors.SfoParameterNotFoundError¶
Bases:
ExceptionNamed Exception raised when a user-supplied attribute is not found
- exception ps3iso.sfo.errors.SfoParseError(message, filepath=None)¶
Bases:
ExceptionNamed Exception raised when a general parsing error occurs
- exception ps3iso.sfo.errors.SfoIndexTableParseError(message, filepath=None)¶
Bases:
SfoParseErrorNamed Exception raised when an parsing an invalid SfoIndexTable is attempted
- exception ps3iso.sfo.errors.SfoIndexTableEntryParseError(message, filepath=None)¶
Bases:
SfoParseErrorNamed Exception raised when an parsing an invalid SfoIndexTableEntry is attempted
- exception ps3iso.sfo.errors.SfoHeaderParseError(message, filepath=None)¶
Bases:
SfoParseErrorNamed Exception raised when an parsing an invalid SfoHeader is attempted
ps3iso.sfo.file module¶
- class ps3iso.sfo.file.SfoFile¶
Bases:
objectThe main object representing an SFO file.
Use the
parse_file()method to create an object from an existing file, or useparse()directly on a seekable object such asio.BytesIO>>> sfo = SfoFile.parse_file('tests/data/PARAM.SFO') >>> sfo <SfoFile parameters=12 size=1041>
>>> sfo.parameters SfoParameters(APP_VER='01.00', ATTRIBUTE=32, BOOTABLE=1, CATEGORY='DG', LICENSE='Some example license text, Supports UTF8 glyphs like ©and ®.', PARENTAL_LEVEL=5, PS3_SYSTEM_VER='02.5200', RESOLUTION=63, SOUND_FORMAT=1, TITLE='Example PS3ISO Game Title', TITLE_ID='BLES00000', VERSION='01.00')
>>> for name, value in sfo: ... print('%s=%s' % (name, value)) APP_VER=01.00 ATTRIBUTE=32 BOOTABLE=1 CATEGORY=DG LICENSE=Some example license text, Supports UTF8 glyphs like ©and ®. PARENTAL_LEVEL=5 PS3_SYSTEM_VER=02.5200 RESOLUTION=63 SOUND_FORMAT=1 TITLE=Example PS3ISO Game Title TITLE_ID=BLES00000 VERSION=01.00
See also
- classmethod parse(fp)¶
Read a seekable binary IO stream containing an SFO file’s bytes
- Parameters:
fp (
BinaryIO) – Stream or resource pointer- Return type:
- Example:
>>> with open('tests/data/PARAM.SFO', 'rb') as f: ... sfo = SfoFile.parse(f) >>> print(sfo) <SfoFile parameters=12 size=1041>
- classmethod parse_file(path)¶
Create a new SfoFile object from an existing SFO file
- Parameters:
path (
Union[str,Path]) – Path to the source file- Return type:
- Example:
>>> SfoFile.parse_file('tests/data/PARAM.SFO') <SfoFile parameters=12 size=1041>
- property keys: List[str]¶
List of available parameter keys in the current
SfoFile- Return type:
List[str]
- Example:
>>> sfo = SfoFile.parse_file('tests/data/PARAM.SFO') >>> sfo.keys ['APP_VER', 'ATTRIBUTE', 'BOOTABLE', 'CATEGORY', 'LICENSE', 'PARENTAL_LEVEL', 'PS3_SYSTEM_VER', 'RESOLUTION', 'SOUND_FORMAT', 'TITLE', 'TITLE_ID', 'VERSION']
- property parameters: NamedTuple¶
NamedTuple of all SFO parameter values
- Return type:
NamedTuple
- Example:
>>> sfo = SfoFile.parse_file('tests/data/PARAM.SFO') >>> sfo.parameters SfoParameters(APP_VER='01.00', ATTRIBUTE=32, BOOTABLE=1, CATEGORY='DG', LICENSE='Some example license text, Supports UTF8 glyphs like ©and ®.', PARENTAL_LEVEL=5, PS3_SYSTEM_VER='02.5200', RESOLUTION=63, SOUND_FORMAT=1, TITLE='Example PS3ISO Game Title', TITLE_ID='BLES00000', VERSION='01.00')
>>> sfo.parameters.TITLE 'Example PS3ISO Game Title'
- get_parameter(name)¶
Retrieve an underlying
SfoParameterobject. If the parameter does not exist, anSfoParameterNotFoundErroris raised.- Parameters:
name (
str) – Parameter name. Must be a valid SFO parameter as found inps3iso.sfo.parameters.VALID_SFO_PARAMETERS- Return type:
- Example:
>>> sfo = SfoFile.parse_file('tests/data/PARAM.SFO') >>> sfo.get_parameter('TITLE') SfoParameter('TITLE', fmt=SfoParameterFormat.utf8, length=None, maxlength=128, required=[SfoCategory.PS3, SfoCategory.PS1, SfoCategory.PSP], optional=[], value='Example PS3ISO Game Title')
See also
- add_parameter(name, value=None)¶
Add a new parameter to the
SfoFile. Raises aSfoDuplicateErrorif the parameter already exists.- Parameters:
name (
str) – Parameter name. Must be a valid SFO parameter as found inps3iso.sfo.parameters.VALID_SFO_PARAMETERSvalue – Optionally set a value for the new parameter
- Return type:
None
- Example:
>>> sfo = SfoFile.parse_file('tests/data/PARAM.SFO') >>> sfo.parameters.REGION_DENY Traceback (most recent call last): AttributeError: 'SfoParameters' object has no attribute 'REGION_DENY' >>> sfo.add_parameter('REGION_DENY', 42) >>> sfo.parameters.REGION_DENY 42
See also
- set_parameter(name, value)¶
Set the value of a parameter in the current
SfoFile, creating it if it does not exist.- Parameters:
name (
str) – Parameter name. Must be a valid SFO parameter as found inps3iso.sfo.parameters.VALID_SFO_PARAMETERSvalue (
str) – New parameter value
- Return type:
None
- Example:
>>> sfo = SfoFile.parse_file('tests/data/PARAM.SFO') >>> sfo.parameters.TITLE_ID 'BLES00000' >>> sfo.set_parameter('TITLE_ID', 'BLES11111') >>> sfo.parameters.TITLE_ID 'BLES11111'
See also
- remove_parameter(name)¶
Remove a parameter from the current
SfoFile- Parameters:
name (
str) – Parameter name- Return type:
None
- Example:
>>> sfo = SfoFile.parse_file('tests/data/PARAM.SFO') >>> sfo.parameters.TITLE_ID 'BLES00000' >>> sfo.remove_parameter('TITLE_ID') >>> sfo.parameters.TITLE_ID Traceback (most recent call last): AttributeError: 'SfoParameters' object has no attribute 'TITLE_ID'
See also
- verify_parameters(category)¶
Verify that all required parameters exist for the given
SfoCategory, and raise aSfoMissingParameterExceptionif any are missing.- Parameters:
category (
SfoCategory) – SFO file category to use for required parameters- Return type:
None
- Example:
>>> sfo = SfoFile.parse_file('tests/data/PARAM.SFO') >>> sfo.verify_parameters(SfoCategory.PS3) >>> sfo.remove_parameter('TITLE') >>> sfo.verify_parameters(SfoCategory.PS3) Traceback (most recent call last): ps3iso.sfo.errors.SfoMissingParameterError: Not a valid SFO File for SfoCategory.PS3. Missing Required parameters: {'TITLE'}
See also
- format(fmt)¶
Return a string representing the PARAM.SFO data contained in the current object. Variables in the formatting string are replaced with the corresponding SFO data.
Variable
Parameter
%a
APP_VER
%a
ATTRIBUTE
%C
CATEGORY
%L
LICENSE
%P
PARENTAL_LEVEL
%R
RESOLUTION
%S
SOUND_FORMAT
%T
TITLE
%I
TITLE_ID
%V
VERSION
%v
PS3_SYSTEM_VER
- Parameters:
fmt (
str) – Formatting string- Return type:
str
- Example:
>>> sfo = SfoFile.parse_file('tests/data/PARAM.SFO') >>> sfo.format('[%I]_(%T).iso') '[BLES00000]_(Example PS3ISO Game Title).iso'
- write(dst)¶
Write the SFO object to a stream such as
io.BytesIO- Parameters:
dst (
BinaryIO) – Destination output stream- Returns:
Number of bytes written
- Return type:
int
- Example:
>>> import io >>> sfo = SfoFile.parse_file('tests/data/PARAM.SFO') >>> sfo.set_parameter('TITLE', 'NewTitle') >>> bio = io.BytesIO() >>> sfo.write(bio) 1041
- write_file(path)¶
Write the SFO object to a file
- Parameters:
path (
str) – Destination file path- Returns:
Number of bytes written
- Return type:
int
- Example:
>>> sfo = SfoFile.parse_file('tests/data/PARAM.SFO') >>> sfo.set_parameter('TITLE', 'NewTitle') >>> sfo.write_file('NewTitle.SFO') 1041
ps3iso.sfo.parameters module¶
- class ps3iso.sfo.parameters.SfoParameterFormat(name)¶
Bases:
objectThis class represents the valid SFO parameter types
Member
Description
SfoParameterFormat.int32
32-bit Integer
SfoParameterFormat.utf8
UTF-8 String (NULL terminated)
SfoParameterFormat.utf8s
UTF-8 String
- classmethod from_bytes(b)¶
Parse bytes and return the corresponding SfoParameterFormat. Raises ValueError if none is found
- Parameters:
b (
bytes) – Bytes to parse- Return type:
- class ps3iso.sfo.parameters.SfoCategory(value)¶
Bases:
IntFlagEnum representing valid SFO file categories
Member
Description
SfoCategory.PSP
PSP Bootable Image
SfoCategory.PS1
PS1 Bootable Image
SfoCategory.PS2
PS2 Bootable Image
SfoCategory.PS3
PS3 Bootable Image
SfoCategory.PSPData
PSP Data Image
SfoCategory.PS1Data
PS1 Data Image
SfoCategory.PS2Data
PS2 Data Image
SfoCategory.PS3Data
PS3 Data Image
See also
- class ps3iso.sfo.parameters.SfoParameter(name, fmt=SfoParameterFormat.int32, length=None, maxlength=None, required=None, optional=None, variable_key_range=None, value=None)¶
Bases:
objectClass representing an SFO parameter.
All valid parameters are defined in
VALID_SFO_PARAMETERS- Paran str name:
Parameter name
- Parameters:
fmt (SfoParameterFormat) – Parameter type, see
SfoParameterFormatlength (int) – Initial length of the parameter value
maxlength (int) – Maximum length of the parameter value
required (list) – Categories for which this parameter is required
optional (list) – Categories for which this parameter is optional
value – Set the initial parameter value
- property name¶
Parameter name
- property size¶
Number of bytes the parameter value will occupy when writtern
- property value¶
Current parameter value
- copy(value=None)¶
Create a copy of the SfoParameter, optionally setting it’s initial value.
- Example:
>>> p = SfoParameter('TITLE', fmt=SfoParameterFormat.utf8, maxlength=1024) >>> p.copy('NewValue') SfoParameter('TITLE', fmt=SfoParameterFormat.utf8, length=None, maxlength=1024, required=[], optional=[], value='NewValue')
- classmethod new(name, value=None)¶
Create a new SFO Parameter. ‘name’ must be a valid parameter name. Optionally set the initial value :rtype:
SfoParameter>>> SfoParameter.new('TITLE', 'NewValue') SfoParameter('TITLE', fmt=SfoParameterFormat.utf8, length=None, maxlength=128, required=[SfoCategory.PS3, SfoCategory.PS1, SfoCategory.PSP], optional=[], value='NewValue')
- ps3iso.sfo.parameters.VALID_SFO_PARAMETERS = {'ACCOUNTID': SfoParameter('ACCOUNTID', fmt=SfoParameterFormat.utf8, length=16, maxlength=16, required=[], optional=[], value=''), 'ACCOUNT_ID': SfoParameter('ACCOUNT_ID', fmt=SfoParameterFormat.utf8s, length=16, maxlength=16, required=[], optional=[], value=''), 'ANALOG_MODE': SfoParameter('ANALOG_MODE', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[SfoCategory.PS1], optional=[], value=0), 'APP_VER': SfoParameter('APP_VER', fmt=SfoParameterFormat.utf8, length=6, maxlength=8, required=[], optional=[SfoCategory.PS3, SfoCategory.PSP], value=''), 'ATTRIBUTE': SfoParameter('ATTRIBUTE', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[SfoCategory.PS1, SfoCategory.PSP], optional=[SfoCategory.PS3], value=0), 'BOOTABLE': SfoParameter('BOOTABLE', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[SfoCategory.PS3, SfoCategory.PS1, SfoCategory.PSP], optional=[], value=0), 'CATEGORY': SfoParameter('CATEGORY', fmt=SfoParameterFormat.utf8, length=3, maxlength=4, required=[SfoCategory.PS3, SfoCategory.PS1, SfoCategory.PSP], optional=[], value=''), 'CONTENT_ID': SfoParameter('CONTENT_ID', fmt=SfoParameterFormat.utf8, length=37, maxlength=48, required=[], optional=[SfoCategory.PS3], value=''), 'DETAIL': SfoParameter('DETAIL', fmt=SfoParameterFormat.utf8, length=None, maxlength=1024, required=[], optional=[], value=''), 'DISC_ID': SfoParameter('DISC_ID', fmt=SfoParameterFormat.utf8, length=16, maxlength=16, required=[SfoCategory.PSP], optional=[], value=''), 'DISC_NUMBER': SfoParameter('DISC_NUMBER', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[], optional=[SfoCategory.PSP], value=0), 'DISC_TOTAL': SfoParameter('DISC_TOTAL', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[], optional=[SfoCategory.PSP], value=0), 'DISC_VERSION': SfoParameter('DISC_VERSION', fmt=SfoParameterFormat.utf8, length=4, maxlength=8, required=[SfoCategory.PSP], optional=[], value=''), 'DRIVER_PATH': SfoParameter('DRIVER_PATH', fmt=SfoParameterFormat.utf8, length=None, maxlength=64, required=[], optional=[SfoCategory.PSP], value=''), 'GAMEDATA_ID': SfoParameter('GAMEDATA_ID', fmt=SfoParameterFormat.utf8, length=None, maxlength=32, required=[], optional=[], value=''), 'HRKGMP_VER': SfoParameter('HRKGMP_VER', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[], optional=[SfoCategory.PSP], value=0), 'ITEM_PRIORITY': SfoParameter('ITEM_PRIORITY', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[], optional=[], value=0), 'LANG': SfoParameter('LANG', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[], optional=[], value=0), 'LICENSE': SfoParameter('LICENSE', fmt=SfoParameterFormat.utf8, length=None, maxlength=512, required=[SfoCategory.PS3], optional=[], value=''), 'MEMSIZE': SfoParameter('MEMSIZE', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[], optional=[SfoCategory.PSP], value=0), 'NPCOMMID': SfoParameter('NPCOMMID', fmt=SfoParameterFormat.utf8, length=12, maxlength=16, required=[], optional=[], value=''), 'NP_COMMUNICATION_ID': SfoParameter('NP_COMMUNICATION_ID', fmt=SfoParameterFormat.utf8, length=13, maxlength=16, required=[], optional=[SfoCategory.PS3], value=''), 'PADDING': SfoParameter('PADDING', fmt=SfoParameterFormat.utf8s, length=0, maxlength=8, required=[], optional=[], value=''), 'PARAMS': SfoParameter('PARAMS', fmt=SfoParameterFormat.utf8s, length=1024, maxlength=1024, required=[], optional=[], value=''), 'PARAMS2': SfoParameter('PARAMS2', fmt=SfoParameterFormat.utf8s, length=12, maxlength=12, required=[], optional=[], value=''), 'PARENTALLEVEL': SfoParameter('PARENTALLEVEL', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[SfoCategory.PS1], optional=[], value=0), 'PARENTAL_LEVEL': SfoParameter('PARENTAL_LEVEL', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[SfoCategory.PS3, SfoCategory.PSP], optional=[], value=0), 'PARENTAL_LEVEL_x': SfoParameter('PARENTAL_LEVEL_x', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[], optional=[SfoCategory.PS3], value=0), 'PATCH_FILE': SfoParameter('PATCH_FILE', fmt=SfoParameterFormat.utf8, length=None, maxlength=32, required=[], optional=[], value=''), 'PBOOT_TITLE': SfoParameter('PBOOT_TITLE', fmt=SfoParameterFormat.utf8, length=None, maxlength=128, required=[], optional=[SfoCategory.PSP], value=''), 'PS3_SYSTEM_VER': SfoParameter('PS3_SYSTEM_VER', fmt=SfoParameterFormat.utf8, length=8, maxlength=8, required=[SfoCategory.PS3, SfoCategory.PS1], optional=[], value=''), 'PSP_SYSTEM_VER': SfoParameter('PSP_SYSTEM_VER', fmt=SfoParameterFormat.utf8, length=8, maxlength=8, required=[SfoCategory.PSP], optional=[], value=''), 'REGION': SfoParameter('REGION', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[], optional=[SfoCategory.PS1, SfoCategory.PS3, SfoCategory.PSP], value=0), 'REGION_DENY': SfoParameter('REGION_DENY', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[], optional=[SfoCategory.PS3], value=0), 'RESOLUTION': SfoParameter('RESOLUTION', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[SfoCategory.PS3, SfoCategory.PS1], optional=[], value=0), 'SAVEDATA_DETAIL': SfoParameter('SAVEDATA_DETAIL', fmt=SfoParameterFormat.utf8, length=None, maxlength=1024, required=[], optional=[], value=''), 'SAVEDATA_DIRECTORY': SfoParameter('SAVEDATA_DIRECTORY', fmt=SfoParameterFormat.utf8, length=None, maxlength=64, required=[], optional=[], value=''), 'SAVEDATA_FILE_LIST': SfoParameter('SAVEDATA_FILE_LIST', fmt=SfoParameterFormat.utf8s, length=3168, maxlength=3168, required=[], optional=[], value=''), 'SAVEDATA_LIST_PARAM': SfoParameter('SAVEDATA_LIST_PARAM', fmt=SfoParameterFormat.utf8, length=None, maxlength=8, required=[], optional=[], value=''), 'SAVEDATA_PARAMS': SfoParameter('SAVEDATA_PARAMS', fmt=SfoParameterFormat.utf8s, length=128, maxlength=128, required=[], optional=[], value=''), 'SAVEDATA_TITLE': SfoParameter('SAVEDATA_TITLE', fmt=SfoParameterFormat.utf8, length=None, maxlength=128, required=[], optional=[], value=''), 'SOUND_FORMAT': SfoParameter('SOUND_FORMAT', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[SfoCategory.PS3, SfoCategory.PS1], optional=[], value=0), 'SOURCE': SfoParameter('SOURCE', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[], optional=[], value=0), 'SUB_TITLE': SfoParameter('SUB_TITLE', fmt=SfoParameterFormat.utf8, length=None, maxlength=128, required=[], optional=[], value=''), 'TARGET_APP_VER': SfoParameter('TARGET_APP_VER', fmt=SfoParameterFormat.utf8, length=6, maxlength=8, required=[], optional=[], value=''), 'TITLE': SfoParameter('TITLE', fmt=SfoParameterFormat.utf8, length=None, maxlength=128, required=[SfoCategory.PS3, SfoCategory.PS1, SfoCategory.PSP], optional=[], value=''), 'TITLEID0xx': SfoParameter('TITLEID0xx', fmt=SfoParameterFormat.utf8, length=9, maxlength=16, required=[], optional=[SfoCategory.PS3], value=''), 'TITLE_ID': SfoParameter('TITLE_ID', fmt=SfoParameterFormat.utf8, length=10, maxlength=16, required=[SfoCategory.PS3, SfoCategory.PS1], optional=[], value=''), 'TITLE_xx': SfoParameter('TITLE_xx', fmt=SfoParameterFormat.utf8, length=None, maxlength=128, required=[], optional=[SfoCategory.PSP], value=''), 'UPDATER_VER': SfoParameter('UPDATER_VER', fmt=SfoParameterFormat.utf8, length=4, maxlength=8, required=[], optional=[SfoCategory.PSP], value=''), 'USE_USB': SfoParameter('USE_USB', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[], optional=[SfoCategory.PSP], value=0), 'VERSION': SfoParameter('VERSION', fmt=SfoParameterFormat.utf8, length=6, maxlength=8, required=[SfoCategory.PS3, SfoCategory.PS1], optional=[], value=''), 'XMB_APPS': SfoParameter('XMB_APPS', fmt=SfoParameterFormat.int32, length=None, maxlength=4, required=[], optional=[], value=0)}¶
- Type:
Dict[str, SfoParameter]
- Annotation:
This data is taken from the parameter table at https://psdevwiki.com/ps3/PARAM.SFO Each entry describes a valid SFO parameter, it’s type, and length constraints. Each parameter can be made ‘optional’ or ‘required’ for any SfoCategory’s.
Error
Unable to execute python code at parameters.py:docstring of ps3iso.sfo.parameters.VALID_SFO_PARAMETERS:145:
No module named ‘tabulate’