CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-mpv

A python interface to the mpv media player

Pending
Overview
Eval results
Files

property-management.mddocs/

Property Management

Complete access to mpv's property system with observation capabilities, specialized accessors, and type conversion. The property system provides the primary interface for configuring and monitoring all aspects of mpv's behavior.

Capabilities

Property Access

Direct access to mpv properties using attribute syntax, dictionary-like access, or specialized property proxies.

class MPV:
    def __getattr__(self, name):
        """Get property value using attribute access (e.g., player.volume)."""

    def __setattr__(self, name, value):
        """Set property value using attribute access (e.g., player.volume = 50)."""

    def __getitem__(self, name: str, file_local: bool = False):
        """
        Get property value using dictionary-like access.

        Parameters:
        - name: Property name
        - file_local: Whether to access file-local variant
        """

    def __setitem__(self, name: str, value, file_local: bool = False):
        """
        Set property value using dictionary-like access.

        Parameters:
        - name: Property name
        - value: Property value
        - file_local: Whether to set file-local variant
        """

    def __iter__(self):
        """Iterate over all available property names."""

    def __dir__(self):
        """List all available properties for tab completion."""

    @property
    def properties(self) -> dict:
        """Dictionary containing all current property values."""

Property Proxies

Specialized property accessors for different use cases and data formatting.

@property
def osd(self) -> 'PropertyProxy':
    """Property proxy that formats values for OSD display."""

@property
def file_local(self) -> 'PropertyProxy':
    """Property proxy for file-local property variants."""

@property
def raw(self) -> 'PropertyProxy':
    """Property proxy that returns raw property values without type conversion."""

@property
def strict(self) -> 'PropertyProxy':
    """Property proxy with strict type checking and error handling."""

@property
def lazy(self) -> 'PropertyProxy':
    """Property proxy with lazy evaluation and error tolerance."""

Property Observation

Monitor property changes with callback functions and decorators.

def observe_property(self, name: str, handler):
    """
    Register a callback to monitor property changes.

    Parameters:
    - name: Property name to observe
    - handler: Callback function(name, value)
    """

def property_observer(self, name: str):
    """
    Decorator for registering property change observers.

    Parameters:
    - name: Property name to observe

    Returns:
    Decorator function for callback registration
    """

def unobserve_property(self, name: str, handler):
    """
    Remove a property change observer.

    Parameters:
    - name: Property name
    - handler: Handler function to remove
    """

def unobserve_all_properties(self, handler):
    """
    Remove a handler from all observed properties.

    Parameters:
    - handler: Handler function to remove from all properties
    """

@property
def property_list(self) -> list:
    """List of all available property names."""

@property
def options(self) -> list:
    """List of all available option names."""

Property Operations

Advanced property manipulation including arithmetic operations and cycling.

def property_add(self, name: str, value: float = 1):
    """
    Add a value to a numeric property.

    Parameters:
    - name: Property name
    - value: Value to add (default: 1)
    """

def property_multiply(self, name: str, factor: float):
    """
    Multiply a numeric property by a factor.

    Parameters:
    - name: Property name
    - factor: Multiplication factor
    """

def cycle(self, name: str, direction: str = 'up'):
    """
    Cycle through property values.

    Parameters:
    - name: Property name
    - direction: Cycle direction ('up' or 'down')
    """

Property Information

Access metadata about available properties and their characteristics.

def option_info(self, name: str) -> dict:
    """
    Get detailed information about a property/option.

    Parameters:
    - name: Property name

    Returns:
    Dictionary with property metadata including type, range, default value
    """

Common Properties

Playback Properties

# Playback control
pause: bool                    # Pause state
time_pos: float               # Current position in seconds
duration: float               # Total duration in seconds
percent_pos: float            # Position as percentage (0-100)
speed: float                  # Playback speed multiplier
loop_file: str               # File looping mode ('no', 'inf', or number)
loop_playlist: str           # Playlist looping mode

# Chapter navigation
chapter: int                 # Current chapter number (0-based)
chapters: int               # Total number of chapters
chapter_list: list          # List of chapter information

# Seeking behavior
hr_seek: str                # High-resolution seek mode
hr_seek_framedrop: bool     # Frame dropping during seeks

Audio Properties

# Audio control
volume: float               # Volume level (0-100)
volume_max: float          # Maximum volume limit
mute: bool                 # Mute state
audio_delay: float         # Audio delay in seconds
speed: float              # Audio/video speed

# Audio track selection
aid: int                  # Active audio track ID
audio: int               # Audio track by index
audio_device: str        # Audio output device
af: str                  # Audio filter chain

# Audio information
audio_bitrate: float     # Current audio bitrate
audio_channels: int      # Number of audio channels
audio_codec: str         # Audio codec name

Video Properties

# Video control
brightness: int           # Video brightness (-100 to 100)
contrast: int            # Video contrast (-100 to 100)
saturation: int          # Video saturation (-100 to 100)
gamma: int               # Video gamma (-100 to 100)
hue: int                 # Video hue (-100 to 100)

# Video track selection
vid: int                 # Active video track ID
video: int              # Video track by index
vf: str                 # Video filter chain

# Video information
video_bitrate: float    # Current video bitrate
width: int              # Video width in pixels
height: int             # Video height in pixels
fps: float              # Video frame rate
video_codec: str        # Video codec name

Subtitle Properties

# Subtitle control
sid: int                # Active subtitle track ID
sub: int               # Subtitle track by index
sub_visibility: bool   # Subtitle visibility
sub_delay: float       # Subtitle delay in seconds
sub_scale: float       # Subtitle scaling factor

# Subtitle positioning
sub_pos: int           # Subtitle position (0-100)
sub_align_x: str       # Horizontal alignment
sub_align_y: str       # Vertical alignment

# Subtitle information
sub_text: str          # Current subtitle text

Window and Display Properties

# Window control
fullscreen: bool        # Fullscreen mode
window_scale: float     # Window scaling factor
window_minimized: bool  # Window minimized state
window_maximized: bool  # Window maximized state
ontop: bool            # Always on top

# Display information
display_fps: float      # Display refresh rate
display_width: int      # Display width
display_height: int     # Display height

Usage Examples

Basic Property Access

import mpv

player = mpv.MPV()
player.play('/path/to/video.mp4')

# Attribute-style access
print(f"Volume: {player.volume}")
player.volume = 75
player.pause = True

# Dictionary-style access
print(f"Duration: {player['duration']}")
player['speed'] = 1.5

# Using property proxies
player.osd.volume = 80  # Shows volume in OSD
player.file_local.speed = 2.0  # File-local speed setting

Property Observation

# Using decorator
@player.property_observer('time-pos')
def position_changed(name, value):
    if value is not None:
        print(f"Position: {value:.2f} seconds")

# Using method
def volume_changed(name, value):
    print(f"Volume changed to: {value}")

player.observe_property('volume', volume_changed)

# Multiple properties with one handler
def media_info_changed(name, value):
    print(f"{name}: {value}")

for prop in ['width', 'height', 'fps', 'video-codec']:
    player.observe_property(prop, media_info_changed)

Advanced Property Operations

# Arithmetic operations
player.property_add('volume', 10)      # Increase volume by 10
player.property_add('volume', -5)      # Decrease volume by 5
player.property_multiply('speed', 1.5) # 1.5x speed

# Cycling through values
player.cycle('fullscreen')    # Toggle fullscreen
player.cycle('mute')          # Toggle mute
player.cycle('audio')         # Switch audio track

# Property information
volume_info = player.option_info('volume')
print(f"Volume range: {volume_info['min']} - {volume_info['max']}")
print(f"Default volume: {volume_info['default']}")

Property Monitoring

# Monitor multiple properties
@player.property_observer('pause')
def pause_handler(name, value):
    state = "paused" if value else "playing"
    print(f"Playback {state}")

@player.property_observer('eof-reached')
def eof_handler(name, value):
    if value:
        print("End of file reached")

# Get all properties
all_props = dict(player.properties)
print(f"Total properties: {len(all_props)}")

# List available properties
available = list(player)
print(f"Available properties: {len(available)}")

File-Local Properties

# Set properties that only apply to current file
player.file_local.volume = 80        # Volume for this file only
player.file_local.brightness = 10    # Brightness for this file only

# Access file-local variants
print(f"File-local volume: {player.file_local.volume}")
print(f"Global volume: {player.volume}")

Install with Tessl CLI

npx tessl i tessl/pypi-mpv@1.0.2

docs

advanced-rendering.md

core-playback.md

event-handling.md

index.md

input-keybinding.md

playlist-media.md

property-management.md

screenshots-overlays.md

streaming.md

tile.json