API Documentation

ps3iso package

ps3iso.game module

class ps3iso.game.Game(iso_path)

Bases: object

Class representing a set of files making up a Playstation 3 game An existing .iso file 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 .iso file

See also

SfoFile.parse()

Parameters

iso_path (Union[str, Path]) – Path to the .iso file to read

Return type

SfoFile

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

SfoFile.format()

Parameters
  • f (Union[str, Path]) – Path to an existing file

  • fmt (str) – Formatting string to use for new file name

  • fill – 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

SfoFile.format()

Parameters

fmt (str) – Formatting string to use for output

Return type

None

classmethod search(path)

Search for .iso files in the given path. Non-recursive and case-insensitive

Param

Path to search

Return type

Iterator[Game]

static rename_all(games, fmt)

Rename all files for the given games according to the formatting string

See also

SfoFile.format()

Parameters
  • games (List[Game]) – List of games to rename

  • fmt (str) – Formatting string to use as file name template

Return type

int

ps3iso.sfo package

ps3iso.sfo.errors module

exception ps3iso.sfo.errors.SfoUnknownParameterError

Bases: Exception

Named Exception raised when a reference to an invalid parameter name is encountered

exception ps3iso.sfo.errors.SfoMissingParameterError

Bases: Exception

Named Exception raised when an SfoFile is missing a required parameter

exception ps3iso.sfo.errors.SfoDuplicateParameterError

Bases: Exception

Named Exception raised when a duplicate SFO parameter is encountered in an SfoFile

exception ps3iso.sfo.errors.SfoParameterNotFoundError

Bases: Exception

Named Exception raised when a user-supplied attribute is not found

exception ps3iso.sfo.errors.SfoParseError(message, filepath=None)

Bases: Exception

Named Exception raised when a general parsing error occurs

exception ps3iso.sfo.errors.SfoIndexTableParseError(message, filepath=None)

Bases: SfoParseError

Named Exception raised when an parsing an invalid SfoIndexTable is attempted

exception ps3iso.sfo.errors.SfoIndexTableEntryParseError(message, filepath=None)

Bases: SfoParseError

Named Exception raised when an parsing an invalid SfoIndexTableEntry is attempted

exception ps3iso.sfo.errors.SfoHeaderParseError(message, filepath=None)

Bases: SfoParseError

Named Exception raised when an parsing an invalid SfoHeader is attempted

ps3iso.sfo.file module

class ps3iso.sfo.file.SfoFile

Bases: object

The main object representing an SFO file.

Use the parse_file() method to create an object from an existing file, or use parse() directly on a seekable object such as io.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
classmethod parse(fp)

Read a seekable binary IO stream containing an SFO file’s bytes

Parameters

fp (BinaryIO) – Stream or resource pointer

Return type

SfoFile

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

SfoFile

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 SfoParameter object. If the parameter does not exist, an SfoParameterNotFoundError is raised.

Parameters

name (str) – Parameter name. Must be a valid SFO parameter as found in ps3iso.sfo.parameters.VALID_SFO_PARAMETERS

Return type

SfoParameter

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')
add_parameter(name, value=None)

Add a new parameter to the SfoFile. Raises a SfoDuplicateError if the parameter already exists.

Parameters
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
set_parameter(name, value)

Set the value of a parameter in the current SfoFile, creating it if it does not exist.

Parameters
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'
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'
verify_parameters(category)

Verify that all required parameters exist for the given SfoCategory, and raise a SfoMissingParameterException if 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

SfoCategory

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: object

This 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

SfoParameterFormat

class ps3iso.sfo.parameters.SfoCategory(value)

Bases: IntFlag

Enum 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

class ps3iso.sfo.parameters.SfoParameter(name, fmt=SfoParameterFormat.int32, length=None, maxlength=None, required=None, optional=None, variable_key_range=None, value=None)

Bases: object

Class representing an SFO parameter.

All valid parameters are defined in VALID_SFO_PARAMETERS

Paran str name

Parameter name

Parameters
  • fmt (SfoParameterFormat) – Parameter type, see SfoParameterFormat

  • length (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

Return type

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=SfoPar...
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 docstring of ps3iso.sfo.parameters.VALID_SFO_PARAMETERS:9:

No module named ‘tabulate’