jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
543 stars 68 forks source link

pympv compatibility #176

Closed sosie-js closed 3 years ago

sosie-js commented 3 years ago

Hello Jaseg

I wondered if your pympv context matches yours, it seems not supposing we wrap all to extend the module with Context like in pympv

import sys
import mpv as pvthonmpv

class MPVError(Exception):
    code = None

    def __init__(self, e):
       self.code = e
       Exception.__init__(self, e)

class mpv():
     def __init__(self):
       self.mpv=pvthonmpv.MPV()
       self.MPVError=MPVError

     def Context(self):
       return self.mpv

mpv=mpv()

def main(*args):
    if len(args) != 1:
        print('pass a single media file as argument')
        return 1

    try:
        m = mpv.Context()
    except mpv.MPVError:
        print('failed creating context')
        return 1

    m.set_option('input-default-bindings')
    m.set_option('osc')
    m.set_option('input-vo-keyboard')
    m.initialize()

    m.command('loadfile', args[0])

    while True:
        event = m.wait_event(.01)
        if event.id == mpv.Events.none:
            continue
        print(event.name)
        if event.id in [mpv.Events.end_file, mpv.Events.shutdown]:
            break

if __name__ == '__main__':
    try:
        exit(main(sys.argv[1:]) or 0)
    except mpv.MPVError as e:
        print(str(e))
        exit(1)

the command python3 ./mpv-client.py test.webm gives a `AttributeError: ('mpv property does not exist', -8, (<MpvHandle object at 0x7f4815d74540>, b'set-option', 6, <ctypes.c_char_Array_16 object at 0x7f48159457c0>))

sosie-js commented 3 years ago

I asked this question knowing that set_option is not in the documentation. I don't know your api and this lead to the rereflexion of could this be nice if python follows the mpv lua scripting so we can think porting users-scripts on python side