From e4362468f7607e982f3459af56a0bac5c49b51e6 Mon Sep 17 00:00:00 2001 From: marcobaobao Date: Sat, 15 Mar 2025 11:08:08 +0100 Subject: [PATCH] fixed livestreams not being monitored --- server/internal/livestream/livestream.go | 21 ++++--------------- server/internal/livestream/livestream_test.go | 6 ++++-- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/server/internal/livestream/livestream.go b/server/internal/livestream/livestream.go index c2abba6..1867436 100644 --- a/server/internal/livestream/livestream.go +++ b/server/internal/livestream/livestream.go @@ -141,26 +141,13 @@ func (l *LiveStream) monitorStartTime(r io.Reader) { } } - const TRIES = 5 - /* - if it's waiting a livestream the 5th line will indicate the time to live - its a dumb and not robust method. + scanner.Scan() - example: - [youtube] Extracting URL: https://www.youtube.com/watch?v=IQVbGfVVjgY - [youtube] IQVbGfVVjgY: Downloading webpage - [youtube] IQVbGfVVjgY: Downloading ios player API JSON - [youtube] IQVbGfVVjgY: Downloading web creator player API JSON - WARNING: [youtube] This live event will begin in 27 minutes. <- STDERR, ignore - [wait] Waiting for 00:27:15 - Press Ctrl+C to try now <- 5th line - */ - for range TRIES { + for !strings.Contains(scanner.Text(), "Waiting for") { scanner.Scan() - - if strings.Contains(scanner.Text(), "Waiting for") { - waitTimeScanner() - } } + + waitTimeScanner() } func (l *LiveStream) WaitTime() <-chan time.Duration { diff --git a/server/internal/livestream/livestream_test.go b/server/internal/livestream/livestream_test.go index acc15b6..50fa141 100644 --- a/server/internal/livestream/livestream_test.go +++ b/server/internal/livestream/livestream_test.go @@ -9,15 +9,17 @@ import ( ) func setupTest() { - config.Instance().DownloaderPath = "yt-dlp" + config.Instance().DownloaderPath = "build/yt-dlp" } +const URL = "https://www.youtube.com/watch?v=pwoAyLGOysU" + func TestLivestream(t *testing.T) { setupTest() done := make(chan *LiveStream) - ls := New("https://www.youtube.com/watch?v=LSm1daKezcE", done, &internal.MessageQueue{}, &internal.MemoryDB{}) + ls := New(URL, done, &internal.MessageQueue{}, &internal.MemoryDB{}) go ls.Start() time.AfterFunc(time.Second*20, func() {