Add first PoC
This commit is contained in:
commit
8f8e1a318f
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
python-mpd2==1.0.0
|
||||
python-mpv==0.3.8
|
53
video-sync.py
Executable file
53
video-sync.py
Executable file
|
@ -0,0 +1,53 @@
|
|||
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
|
Loading…
Reference in a new issue