54 lines
1.4 KiB
Python
Executable File
54 lines
1.4 KiB
Python
Executable File
import mpv
|
|
import pdb
|
|
import sys
|
|
import time
|
|
from mpd import MPDClient
|
|
|
|
def my_log(loglevel, component, message):
|
|
print('[{}] {}: {}'.format(loglevel, component, message))
|
|
|
|
player = mpv.MPV(log_handler=my_log, ytdl=True, input_default_bindings=True, input_vo_keyboard=True)
|
|
|
|
# Property access, these can be changed at runtime
|
|
@player.property_observer('time-pos')
|
|
def time_observer(_name, value):
|
|
# Here, _value is either None if nothing is playing or a float containing
|
|
# fractional seconds since the beginning of the file.
|
|
#print('Now playing at {:.2f}s'.format(value))
|
|
pass
|
|
|
|
#player.fullscreen = True
|
|
player.mute = True
|
|
player.loop_playlist = 'inf'
|
|
# Option access, in general these require the core to reinitialize
|
|
player['vo'] = 'opengl'
|
|
|
|
@player.on_key_press('q')
|
|
def my_q_binding():
|
|
sys.exit()
|
|
|
|
client = MPDClient()
|
|
player.play('https://www.youtube.com/watch?v=RChFX5I2dkc')
|
|
while True:
|
|
client.connect("10.42.0.3", 6600)
|
|
mpd_time = int(client.status().get("time").split(":")[0])
|
|
video_time = player.time_pos
|
|
try:
|
|
video_time = int(video_time)
|
|
except TypeError:
|
|
pass
|
|
else:
|
|
#pdb.set_trace()
|
|
delta = abs(mpd_time - video_time)
|
|
print("mpd: {}, video: {}, delta: {}".format(mpd_time, video_time, delta))
|
|
|
|
if delta > 1:
|
|
print("delta > 1s, syncing")
|
|
player.time_pos = mpd_time
|
|
|
|
client.disconnect()
|
|
|
|
time.sleep(1)
|
|
|
|
del player
|