reload subtitles too

This commit is contained in:
j 2017-10-13 09:33:29 +02:00
parent 34f447b42d
commit 64718a7c61
2 changed files with 39 additions and 8 deletions

View File

@ -47,11 +47,12 @@ def main():
update_playlist(args.playlist, args.prefix, shift=False)
player.loadlist(args.playlist)
player.pause = True
sub.load_playlist(args.playlist)
player.register_key_binding('r', restart)
update_playlist(args.playlist, args.prefix, shift=shift)
sub = SubtitleServer(player, args.playlist)
player.loadlist(args.playlist)
sub = SubtitleServer(player, args.playlist)
if not shift:
player.pause = True

View File

@ -33,9 +33,24 @@ class Subtitles():
def __init__(self, player, playlist):
self.player = player
self.load_playlist(playlist)
self.player.observe_property('time-pos', self.update)
def load_playlist(self, playlist):
with open(playlist, 'r') as fd:
self.playlist = fd.read().strip().split('\n')
self.player.observe_property('time-pos', self.update)
self.path = None
self.next_path = None
if self.player.path:
path = self.player.path.decode()
self.path = path
self.update_next()
self.load_subtitles()
data = {}
data['subtitles'] = {}
data['subtitles'][os.path.basename(self.path)] = self.current
data['subtitles'][os.path.basename(self.next_path)] = self.next
self.trigger(data)
def update(self, pos):
if pos is None:
@ -70,10 +85,16 @@ class Subtitles():
self.next_path = self.playlist[index]
def load_subtitles(self):
srt = self.path.replace('.mp4', '.srt')
self.current = ox.srt.load(srt)
srt = self.next_path.replace('.mp4', '.srt')
self.next = ox.srt.load(srt)
if 'png' in self.path:
self.current = []
else:
srt = self.path.replace('.mp4', '.srt')
self.current = ox.srt.load(srt)
if 'png' in self.next_path:
self.next = []
else:
srt = self.next_path.replace('.mp4', '.srt')
self.next = ox.srt.load(srt)
def trigger(self, data):
logger.debug('trigger %s', data)
@ -188,6 +209,7 @@ class NotFoundHandler(RequestHandler):
class SubtitleServer(Thread):
sub = None
def __init__(self, player, playlist):
Thread.__init__(self)
@ -197,15 +219,21 @@ class SubtitleServer(Thread):
self.start()
def run(self):
main(self.player, self.playlist)
main(self.player, self.playlist, self)
def join(self):
IOLoop.instance().stop()
return Thread.join(self)
def load_playlist(self, playlist):
if self.sub:
self.sub.load_playlist(playlist)
def main(player, playlist):
def main(player, playlist, parent=None):
sub = Subtitles(player, playlist)
if parent:
parent.sub = sub
options = {
'debug': DEBUG,
@ -221,6 +249,8 @@ def main(player, playlist):
log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
logging.basicConfig(level=logging.DEBUG, format=log_format)
http_server = HTTPServer(Application(handlers, **options))
if parent:
parent.server = http_server
main = IOLoop.instance()
def shutdown():