sync to hour, play sax inline, add s/p keybindings
This commit is contained in:
parent
438108a8f9
commit
ed03c7026a
2 changed files with 51 additions and 1 deletions
|
@ -8,6 +8,7 @@ import time
|
|||
from threading import Thread
|
||||
from datetime import datetime
|
||||
|
||||
import ox
|
||||
import mpv
|
||||
|
||||
|
||||
|
@ -53,11 +54,22 @@ class Sync(Thread):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.is_main = kwargs.get('mode', 'main') == 'main'
|
||||
self.start_at_hour = kwargs.get("hour", False)
|
||||
self.sock = self.init_socket()
|
||||
self.main = Main()
|
||||
if self.is_main:
|
||||
self.socket_enable_broadcast()
|
||||
|
||||
if kwargs.get("sax"):
|
||||
self.sax = mpv.MPV(
|
||||
log_handler=mpv_log, input_default_bindings=True,
|
||||
input_vo_keyboard=True,
|
||||
)
|
||||
self.sax.loop_file = True
|
||||
self.sax.play("/srv/t_for_time/render/Saxophone-5.1.mp4")
|
||||
else:
|
||||
self.sax = None
|
||||
|
||||
if mpv.MPV_VERSION >= (2, 2):
|
||||
self.mpv = mpv.MPV(
|
||||
log_handler=mpv_log, input_default_bindings=True,
|
||||
|
@ -79,6 +91,8 @@ class Sync(Thread):
|
|||
self.mpv.loop_file = False
|
||||
self.mpv.loop_playlist = True
|
||||
self.mpv.register_key_binding('q', self.q_binding)
|
||||
self.mpv.register_key_binding('s', self.s_binding)
|
||||
self.mpv.register_key_binding('p', self.p_binding)
|
||||
self.playlist = kwargs['playlist']
|
||||
self.playlist_mtime = os.stat(self.playlist).st_mtime
|
||||
self.mpv.loadlist(self.playlist)
|
||||
|
@ -90,6 +104,30 @@ class Sync(Thread):
|
|||
time.sleep(0.1)
|
||||
self.mpv.pause = True
|
||||
self.sync_to_main()
|
||||
elif self.start_at_hour:
|
||||
self.mpv.pause = True
|
||||
fmt = '%Y-%m-%d %H'
|
||||
now = datetime.now()
|
||||
offset = (now - datetime.strptime(now.strftime(fmt), fmt)).total_seconds()
|
||||
if self.sax:
|
||||
self.sax.seek(offset, 'absolute', 'exact')
|
||||
self.sax.pause = True
|
||||
position = 0
|
||||
for idx, item in enumerate(self.mpv.playlist):
|
||||
duration = ox.avinfo(item['filename'])['duration']
|
||||
if position + duration > offset:
|
||||
pos = offset - position
|
||||
self.mpv.playlist_play_index(idx)
|
||||
self.mpv.pause = False
|
||||
self.mpv.wait_until_playing()
|
||||
self.mpv.seek(pos, 'absolute', 'exact')
|
||||
time.sleep(0.1)
|
||||
break
|
||||
else:
|
||||
position += duration
|
||||
if self.sax:
|
||||
self.sax.pause = False
|
||||
|
||||
self.ready = True
|
||||
Thread.__init__(self)
|
||||
self.start()
|
||||
|
@ -116,6 +154,16 @@ class Sync(Thread):
|
|||
self.stop()
|
||||
self.mpv.stop()
|
||||
|
||||
def s_binding(self, *args):
|
||||
self.mpv.pause = True
|
||||
if self.sax:
|
||||
self.sax.pause = True
|
||||
|
||||
def p_binding(self, *args):
|
||||
self.mpv.pause = False
|
||||
if self.sax:
|
||||
self.sax.pause = False
|
||||
|
||||
def stop(self, *args):
|
||||
self.active = False
|
||||
if self.sock:
|
||||
|
@ -302,6 +350,8 @@ def main():
|
|||
parser.add_argument('--prefix', help='video location', default=prefix)
|
||||
parser.add_argument('--window', action='store_true', help='run in window', default=False)
|
||||
parser.add_argument('--debug', action='store_true', help='debug', default=False)
|
||||
parser.add_argument('--hour', action='store_true', help='hour', default=False)
|
||||
parser.add_argument('--sax', action='store_true', help='hour', default=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
DEBUG = args.debug
|
||||
|
@ -311,7 +361,7 @@ def main():
|
|||
base = os.path.dirname(os.path.abspath(__file__))
|
||||
#os.chdir(base)
|
||||
|
||||
player = Sync(mode=args.mode, playlist=args.playlist, fullscreen=not args.window)
|
||||
player = Sync(mode=args.mode, playlist=args.playlist, fullscreen=not args.window, hour=args.hour, sax=args.sax)
|
||||
while player.active:
|
||||
try:
|
||||
player.mpv.wait_for_playback()
|
||||
|
|
BIN
title.png
Normal file
BIN
title.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.1 KiB |
Loading…
Reference in a new issue