Skip to main content

Python API to MPV using JSON IPC

Project description

Python MPV JSONIPC

This implements an interface similar to python-mpv, but it uses the JSON IPC protocol instead of the C API. This means you can control external instances of MPV including players like SMPlayer, and it can use MPV players that are prebuilt instead of needing libmpv1. It may also be more resistant to crashes such as Segmentation Faults, but since it isn't directly communicating with MPV via the C API the performance will be worse.

Please note that this only implements the subset of python-mpv that is used by plex-mpv-shim and jellyfin-mpv-shim. Other functionality has not been implemented.

Installation

sudo pip3 install python-mpv-jsonipc

Basic usage

Create an instance of MPV. You can use an already running MPV or have the library start a managed copy of MPV. Command arguments can be specified when initializing MPV if you are starting a managed copy of MPV.

Please also see the API Documentation.

from python_mpv_jsonipc import MPV

# Uses MPV that is in the PATH.
mpv = MPV()

# Use MPV that is running and connected to /tmp/mpv-socket.
mpv = MPV(start_mpv=False, ipc_socket="/tmp/mpv-socket")

# Uses MPV that is found at /path/to/mpv.
mpv = MPV(mpv_location="/path/to/mpv")

# After you have an MPV, you can read and set (if applicable) properties.
mpv.volume # 100.0 by default
mpv.volume = 20 

# You can also send commands.
mpv.command_name(arg1, arg2)

# Bind to key press events with a decorator
@mpv.on_key_press("space")
def space_handler():
    pass

# You can also observe and wait for properties.
@mpv.property_observer("eof-reached")
def handle_eof(name, value):
    pass

# Or simply wait for the value to change once.
mpv.wait_for_property("duration")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-mpv-jsonipc-1.2.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

python_mpv_jsonipc-1.2.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file python-mpv-jsonipc-1.2.0.tar.gz.

File metadata

  • Download URL: python-mpv-jsonipc-1.2.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.9.2

File hashes

Hashes for python-mpv-jsonipc-1.2.0.tar.gz
Algorithm Hash digest
SHA256 2199beefa6643d16483dda17c976bf2bbbf5dfedb1a5ca8d7d4611527ae6ad7a
MD5 12044bfc3805d4ab48fa6074cbced092
BLAKE2b-256 6f65232563752a049831fdd6ae7b4caf8a557529d2f3c72ecbc40fb8b69e372c

See more details on using hashes here.

File details

Details for the file python_mpv_jsonipc-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: python_mpv_jsonipc-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.9.2

File hashes

Hashes for python_mpv_jsonipc-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8442175e5762e000b044c173ae47396b83228d1a47d7766fe0526b584edc6a2d
MD5 91d85e1dbadd427bcfaa82c7aa2f1191
BLAKE2b-256 a3a94665315263ff28d3de97d1ef2d019c130b557ae89643dd60d92f500c974c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page