tttool_handler Module

Interface to tttool for GME file operations.

Key Functions

make_gme(album_id, db_handler, config): Create GME file from audio files

generate_codes_yaml(yaml_file, db_handler): Generate OID code mappings (1001-14999)

create_oids(codes, size, db_handler): Generate OID code PNG images

copy_gme(album_oid, tiptoi_dir, db_handler): Copy GME to TipToi pen

delete_gme_tiptoi(album_oid, tiptoi_dir): Delete GME from pen

get_sorted_tracks(album): Sort tracks by track number

OID Code Ranges

  • 1-999: Album OIDs (product IDs)

  • 1001-14999: Script codes (play, pause, tracks, etc.)

  • Codes cached in database for reuse

Usage

from ttmp32gme.tttool_handler import make_gme, copy_gme, create_oids

# Create GME
result = make_gme(123, db, config)
if result['success']:
    print(f"GME: {result['gme_file']}")

# Copy to TipToi
tiptoi_dir = get_tiptoi_dir()
if tiptoi_dir:
    copy_gme(123, tiptoi_dir, db)

# Generate OID images
images = create_oids([2001, 2002], 24, db)

GME creation takes 1-5 minutes depending on album size and format.

TtTool handling module for ttmp32gme - creates GME files.

ttmp32gme.tttool_handler.generate_codes_yaml(yaml_file, db_handler)[source]

Generate script codes YAML file with OID code mappings.

Reads script names from the main YAML file and assigns OID codes to each script. Reuses existing codes from database when available, assigns new codes otherwise.

Parameters:
  • yaml_file (Path) – Path to main album YAML file

  • db_handler (DBHandler) – Database handler instance for accessing and storing script codes

Return type:

Path

Returns:

Path to generated codes YAML file (.codes.yaml)

Raises:

RuntimeError – If all script codes (1001-14999) are exhausted

ttmp32gme.tttool_handler.convert_tracks(album, yaml_file, config, db_handler)[source]

Convert audio tracks to appropriate format and generate TipToi scripts.

Converts tracks to OGG (if configured) or copies MP3 files to audio directory. Generates play, next, prev, and individual track control scripts for TipToi.

Parameters:
  • album (Dict[str, Any]) – Album dictionary containing tracks and metadata

  • yaml_file (Path) – Path to album YAML file where scripts will be appended

  • config (Dict[str, Any]) – Configuration dictionary with audio_format and other settings

  • db_handler (DBHandler) – Database handler instance for updating track scripts

Return type:

Path

Returns:

Path to media directory containing converted audio files

Raises:

RuntimeError – If ffmpeg is not found when OGG conversion is requested

ttmp32gme.tttool_handler.get_tttool_parameters(db_handler)[source]

Get tttool parameters from database configuration.

Retrieves all configuration parameters that start with tt_ prefix and returns them with the prefix removed.

Parameters:

db_handler (DBHandler) – Database handler instance for accessing configuration

Returns:

‘1200’, ‘pixel-size’: ‘2’})

Return type:

Dictionary mapping parameter names to values (e.g., {‘dpi’

ttmp32gme.tttool_handler.get_tttool_command(db_handler)[source]

Build tttool command with configuration parameters.

Parameters:

db_handler (DBHandler) – Database handler instance for accessing configuration

Return type:

List[str]

Returns:

Command as list of arguments ready for subprocess execution

Raises:

RuntimeError – If tttool executable is not found in system PATH

ttmp32gme.tttool_handler.run_tttool(arguments, path, db_handler)[source]

Run tttool command with specified arguments.

Changes to the specified directory (if provided), executes tttool with arguments, and returns to the original directory.

Parameters:
  • arguments (str) – Space-separated command arguments to pass to tttool

  • path (Optional[Path]) – Working directory for command execution (None to use current directory)

  • db_handler (DBHandler) – Database handler instance for building tttool command

Return type:

bool

Returns:

True if command executed successfully, False if it failed

ttmp32gme.tttool_handler.get_sorted_tracks(album)[source]

Get sorted list of track keys.

Parameters:

album (Dict[str, Any]) – Album dictionary

Return type:

List[str]

Returns:

List of track keys (e.g., [‘track_1’, ‘track_2’, …])

ttmp32gme.tttool_handler.make_gme(oid, config, db_handler)[source]

Create GME file for an album using tttool.

Generates YAML configuration, converts audio tracks, creates script codes, and assembles the final GME file.

Parameters:
  • oid (int) – Album OID identifier

  • config (Dict[str, Any]) – Configuration dictionary with audio_format, pen_language, etc.

  • db_handler (DBHandler) – Database handler instance for accessing album data

Return type:

int

Returns:

Album OID

Raises:
  • ValueError – If album with specified OID is not found

  • RuntimeError – If required tools (tttool, ffmpeg) are not found

ttmp32gme.tttool_handler.create_oids(oids, size, db_handler)[source]

Create OID code images.

Parameters:
  • oids (List[int]) – List of OID codes to generate images for

  • size (int) – Size of OID code in millimeters

  • db_handler (DBHandler) – Database handler instance for configuration access

Return type:

List[Path]

Returns:

List of paths to generated OID image files

ttmp32gme.tttool_handler.copy_gme(oid, config, db_handler)[source]

Copy GME file to TipToi device.

Parameters:
  • oid (int) – Album OID identifier

  • config (Dict[str, Any]) – Configuration dictionary (unused, kept for API compatibility)

  • db_handler (DBHandler) – Database handler instance for accessing album data

Return type:

int

Returns:

Album OID

ttmp32gme.tttool_handler.delete_gme_tiptoi(uid, db_handler)[source]

Delete GME file from TipToi device.

Parameters:
  • uid (int) – Album OID

  • db_handler (DBHandler) – Database handler instance

Return type:

int

Returns:

Album OID