to infinity
This commit is contained in:
parent
582bcf1813
commit
6e4e8ca7a6
4 changed files with 146 additions and 10 deletions
|
|
@ -1,8 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
import argparse
|
||||
import collections
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
import collections
|
||||
import time
|
||||
from threading import Thread
|
||||
from datetime import datetime
|
||||
|
|
@ -57,13 +58,22 @@ class Sync(Thread):
|
|||
if self.is_main:
|
||||
self.socket_enable_broadcast()
|
||||
|
||||
self.mpv = mpv.MPV(
|
||||
log_handler=mpv_log, input_default_bindings=True,
|
||||
input_vo_keyboard=True,
|
||||
sub_text_font_size=FONT_SIZE, sub_text_font=FONT,
|
||||
sub_border_size=FONT_BORDER,
|
||||
sub_margin_y=SUB_MARGIN,
|
||||
)
|
||||
if mpv.MPV_VERSION >= (2, 2):
|
||||
self.mpv = mpv.MPV(
|
||||
log_handler=mpv_log, input_default_bindings=True,
|
||||
input_vo_keyboard=True,
|
||||
sub_font_size=FONT_SIZE, sub_font=FONT,
|
||||
sub_border_size=FONT_BORDER,
|
||||
sub_margin_y=SUB_MARGIN,
|
||||
)
|
||||
else:
|
||||
self.mpv = mpv.MPV(
|
||||
log_handler=mpv_log, input_default_bindings=True,
|
||||
input_vo_keyboard=True,
|
||||
sub_text_font_size=FONT_SIZE, sub_text_font=FONT,
|
||||
sub_border_size=FONT_BORDER,
|
||||
sub_margin_y=SUB_MARGIN,
|
||||
)
|
||||
self.mpv.observe_property('time-pos', self.time_pos_cb)
|
||||
self.mpv.fullscreen = kwargs.get('fullscreen', False)
|
||||
self.mpv.loop_file = False
|
||||
|
|
@ -73,6 +83,7 @@ class Sync(Thread):
|
|||
self.playlist_mtime = os.stat(self.playlist).st_mtime
|
||||
self.mpv.loadlist(self.playlist)
|
||||
logger.error("loaded paylist: %s", self.playlist)
|
||||
logger.debug("current playlist: %s", json.dumps(self.mpv.playlist, indent=2))
|
||||
self.deviations = collections.deque(maxlen=10)
|
||||
if not self.is_main:
|
||||
self.mpv.pause = False
|
||||
|
|
@ -135,8 +146,33 @@ class Sync(Thread):
|
|||
playlist_mtime = os.stat(self.playlist).st_mtime
|
||||
if self.playlist_mtime != playlist_mtime:
|
||||
self.playlist_mtime = playlist_mtime
|
||||
self.mpv.loadlist(self.playlist)
|
||||
#self.mpv.loadlist(self.playlist)
|
||||
with open(self.playlist) as fd:
|
||||
items = fd.read().strip().split('\n')
|
||||
base = os.path.dirname(self.playlist)
|
||||
items = [os.path.join(base, item) for item in items]
|
||||
current_items = self.mpv.playlist_filenames
|
||||
for filename in items:
|
||||
if filename not in current_items:
|
||||
self.mpv.playlist_append(filename)
|
||||
logger.error("add: %s", filename)
|
||||
remove = []
|
||||
for filename in current_items:
|
||||
if filename not in items:
|
||||
remove.append(filename)
|
||||
for filename in remove:
|
||||
for idx, item in enumerate(self.mpv.playlist):
|
||||
if item["filename"] == filename:
|
||||
logger.error("remove: %s %s", idx, filename)
|
||||
self.mpv.playlist_remove(idx)
|
||||
break
|
||||
for idx, filename in enumerate(items):
|
||||
current_idx = self.mpv.playlist_filenames.index(filename)
|
||||
if idx != current_idx:
|
||||
logger.error("move item %s %s -> %s", filename, current_idx, idx)
|
||||
self.mpv.playlist_move(current_idx, idx)
|
||||
logger.error("reloaded paylist: %s", self.playlist)
|
||||
logger.debug("current playlist: %s", json.dumps(self.mpv.playlist, indent=2))
|
||||
|
||||
def init_socket(self):
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
|
||||
|
|
@ -261,7 +297,7 @@ def main():
|
|||
prefix = os.path.expanduser('~/Videos/t_for_time')
|
||||
|
||||
parser = argparse.ArgumentParser(description='t_for_time sync player')
|
||||
parser.add_argument('--mode', help='ip of peer', default="peer")
|
||||
parser.add_argument('--mode', help='peer or main', default="peer")
|
||||
parser.add_argument('--playlist', default='/srv/t_for_time/render/128/front.m3u', help="m3u")
|
||||
parser.add_argument('--prefix', help='video location', default=prefix)
|
||||
parser.add_argument('--window', action='store_true', help='run in window', default=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue