reload subtitles too
This commit is contained in:
parent
34f447b42d
commit
64718a7c61
2 changed files with 39 additions and 8 deletions
|
@ -47,11 +47,12 @@ def main():
|
||||||
update_playlist(args.playlist, args.prefix, shift=False)
|
update_playlist(args.playlist, args.prefix, shift=False)
|
||||||
player.loadlist(args.playlist)
|
player.loadlist(args.playlist)
|
||||||
player.pause = True
|
player.pause = True
|
||||||
|
sub.load_playlist(args.playlist)
|
||||||
player.register_key_binding('r', restart)
|
player.register_key_binding('r', restart)
|
||||||
|
|
||||||
update_playlist(args.playlist, args.prefix, shift=shift)
|
update_playlist(args.playlist, args.prefix, shift=shift)
|
||||||
sub = SubtitleServer(player, args.playlist)
|
|
||||||
player.loadlist(args.playlist)
|
player.loadlist(args.playlist)
|
||||||
|
sub = SubtitleServer(player, args.playlist)
|
||||||
if not shift:
|
if not shift:
|
||||||
player.pause = True
|
player.pause = True
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,24 @@ class Subtitles():
|
||||||
|
|
||||||
def __init__(self, player, playlist):
|
def __init__(self, player, playlist):
|
||||||
self.player = player
|
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:
|
with open(playlist, 'r') as fd:
|
||||||
self.playlist = fd.read().strip().split('\n')
|
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):
|
def update(self, pos):
|
||||||
if pos is None:
|
if pos is None:
|
||||||
|
@ -70,8 +85,14 @@ class Subtitles():
|
||||||
self.next_path = self.playlist[index]
|
self.next_path = self.playlist[index]
|
||||||
|
|
||||||
def load_subtitles(self):
|
def load_subtitles(self):
|
||||||
|
if 'png' in self.path:
|
||||||
|
self.current = []
|
||||||
|
else:
|
||||||
srt = self.path.replace('.mp4', '.srt')
|
srt = self.path.replace('.mp4', '.srt')
|
||||||
self.current = ox.srt.load(srt)
|
self.current = ox.srt.load(srt)
|
||||||
|
if 'png' in self.next_path:
|
||||||
|
self.next = []
|
||||||
|
else:
|
||||||
srt = self.next_path.replace('.mp4', '.srt')
|
srt = self.next_path.replace('.mp4', '.srt')
|
||||||
self.next = ox.srt.load(srt)
|
self.next = ox.srt.load(srt)
|
||||||
|
|
||||||
|
@ -188,6 +209,7 @@ class NotFoundHandler(RequestHandler):
|
||||||
|
|
||||||
|
|
||||||
class SubtitleServer(Thread):
|
class SubtitleServer(Thread):
|
||||||
|
sub = None
|
||||||
|
|
||||||
def __init__(self, player, playlist):
|
def __init__(self, player, playlist):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
|
@ -197,15 +219,21 @@ class SubtitleServer(Thread):
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
main(self.player, self.playlist)
|
main(self.player, self.playlist, self)
|
||||||
|
|
||||||
def join(self):
|
def join(self):
|
||||||
IOLoop.instance().stop()
|
IOLoop.instance().stop()
|
||||||
return Thread.join(self)
|
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)
|
sub = Subtitles(player, playlist)
|
||||||
|
if parent:
|
||||||
|
parent.sub = sub
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
'debug': DEBUG,
|
'debug': DEBUG,
|
||||||
|
@ -221,6 +249,8 @@ def main(player, playlist):
|
||||||
log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
|
log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
|
||||||
logging.basicConfig(level=logging.DEBUG, format=log_format)
|
logging.basicConfig(level=logging.DEBUG, format=log_format)
|
||||||
http_server = HTTPServer(Application(handlers, **options))
|
http_server = HTTPServer(Application(handlers, **options))
|
||||||
|
if parent:
|
||||||
|
parent.server = http_server
|
||||||
main = IOLoop.instance()
|
main = IOLoop.instance()
|
||||||
|
|
||||||
def shutdown():
|
def shutdown():
|
||||||
|
|
Loading…
Reference in a new issue