Giter Site home page Giter Site logo

python-mpv-jsonipc's Introduction

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")

python-mpv-jsonipc's People

Contributors

iwalton3 avatar neraste avatar pjeanjean avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.