From e3e8b67fe36f329da19a648fd4b80aba722a79a1 Mon Sep 17 00:00:00 2001 From: Alex Ballas Date: Thu, 22 Aug 2024 12:34:37 +0300 Subject: [PATCH] More changes to support internal subs --- internal/gui/actions.go | 16 +++++++++++++++- internal/gui/gui.go | 11 +++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/internal/gui/actions.go b/internal/gui/actions.go index 6325dfb..ee37b94 100644 --- a/internal/gui/actions.go +++ b/internal/gui/actions.go @@ -338,6 +338,20 @@ func playAction(screen *NewScreen) { } } + if screen.SelectInternalSubs.Selected != "" { + for n, opt := range screen.SelectInternalSubs.Options { + if opt == screen.SelectInternalSubs.Selected { + tempSubsPath, err := utils.ExtractSub(n, screen.mediafile) + if err != nil { + break + } + + screen.tempFiles = append(screen.tempFiles, tempSubsPath) + screen.subsfile = tempSubsPath + } + } + } + screen.tvdata = &soapcalls.TVPayload{ ControlURL: screen.controlURL, EventURL: screen.eventlURL, @@ -479,10 +493,10 @@ func clearmediaAction(screen *NewScreen) { } func clearsubsAction(screen *NewScreen) { + screen.SelectInternalSubs.ClearSelected() screen.SubsText.Text = "" screen.subsfile = "" screen.SubsText.Refresh() - screen.SelectInternalSubs.ClearSelected() } func skipNextAction(screen *NewScreen) { diff --git a/internal/gui/gui.go b/internal/gui/gui.go index 1c311e4..0258b73 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -25,6 +25,7 @@ import ( // NewScreen . type NewScreen struct { + tempFiles []string SelectInternalSubs *widget.Select CurrentPos binding.String EndPos binding.String @@ -91,6 +92,16 @@ func (f *debugWriter) Write(b []byte) (int, error) { // Start . func Start(ctx context.Context, s *NewScreen) { + if s.tempFiles == nil { + s.tempFiles = make([]string, 0) + } + + defer func() { + for _, file := range s.tempFiles { + os.Remove(file) + } + }() + w := s.Current w.SetOnDropped(onDropFiles(s))