def main():

    video = sys.argv[1]
    video_base = splitext(video)[0]

    if isfile(video_base + '.srt'):
        sub = Srt(video_base + '.srt')
    elif isfile(video_base + '.ass'):
        sub = Ass(video_base + '.ass')
    elif isfile(video_base + '.vtt'):
        sub = Vtt(video_base + '.vtt')
    else:
        print('no subtitles found')
        return

    mp = MpvProcess(args=['--script=~/.mpv/scripts/manual/focusplay.lua'])

    mp.commandv('loadfile', video)

    def copysub(_, t):
        if not t:
            return
        d = mp.get_property_native('sub-delay') or 0
        text = sub.get_caption(t - d)
        if text:
            #pyperclip.copy(text)
            for c in clients:
                c.write_message(text)

    mp.observe_property('time-pos', copysub)

    app = get_app()
    app.listen(9873)
    main_loop = ioloop.IOLoop.instance()
    main_loop.start()
示例#2
0
 def __init__(self):
     self.player = MpvProcess(debug=True, args=[])
     self.observe_properties([
         'media-title',
         'idle',
         'pause',
         'video-aspect',
         'sub-delay',
         'audio-delay',
         'video-params/par',
         'sid',
         'aid',
         ])
示例#3
0
                    if 'pause:Off' in rtext:
                        server_time, server_playtime = map(
                            lambda x: float(x),
                            rtext.split(':')[-2:])
                        mp.slave_command('set pause no')
                        mp.slave_command(
                            'seek %s absolute' %
                            str(nowtime - server_time + server_playtime))
                        pauseFlag = False
                    continue

    finally:
        mp.process.kill()


if __name__ == '__main__':

    with open('config.ini', 'r', encoding='utf-8') as file:
        server = file.readline().strip()[1:]  #sig问题
        HEARTTIME = eval(file.readline().strip())

    mp = MpvProcess()
    timesleep(1)

    filepath = chooseFile()
    # print(filepath)
    Id, Mateid = getusefulId(filepath)
    # print(Id,Mateid)

    keepMPVSynchronize(server, Id, Mateid, filepath, HEARTTIME)
示例#4
0
class MpvRemote(object):
    def __init__(self):
        self.player = MpvProcess(debug=True, args=[])
        self.observe_properties([
            'media-title',
            'idle',
            'pause',
            'video-aspect',
            'sub-delay',
            'audio-delay',
            'video-params/par',
            'sid',
            'aid',
            ])

    def handle_message(self, message, client):
        message = Message(message)
        response = dict(id=message.id, result=None)
        logging.info('{}: {}'.format(message.method, message.params))
        if message.method == 'mpv_command':
            response['result'] = self.mpv_command(message.params)
        elif message.method == 'folder_content':
            response['result'] = FolderContent(message.params).get()
        client.write_message(json.dumps(response))


    def mpv_command(self, cmd):
        command = cmd['method']
        params = cmd['params']
        result = None
        if command == 'commandv':
            result = self.player.commandv(*params)
        elif command == 'get_property':
            result = self.player.get_property(params[0])
        elif command == 'get_property_native':
            result = self.player.get_property_native(params[0])
        elif command == 'set_property':
            self.player.set_property(params[0], params[1])
        elif command == 'play_file':
            self.player.commandv('stop')
            self.player.set_property('pause', 'no')
            self.player.commandv('loadfile', os.path.join(*params))
        return result

    def observe_properties(self, properties):
        def property_update(prop, val):
            msg = dict(id=prop, result=val)
            msg = json.dumps(msg)
            for c in clients:
                c.write_message(msg)
        for p in properties:
            self.player.observe_property(p, property_update)