From a0de9b7ef20c43ded2eb494dfc0eb27c1cc29e1b Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Tue, 3 Oct 2023 02:54:33 -0500 Subject: [PATCH] fix(device): Fix ad skip being blocked by API lookups Ref #27 --- internal/device/watch.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/internal/device/watch.go b/internal/device/watch.go index f6f588e..8070033 100644 --- a/internal/device/watch.go +++ b/internal/device/watch.go @@ -186,7 +186,9 @@ func (d *Device) tick() error { } d.prevVideoId = castMedia.Media.ContentId d.unmuteSegment() - d.querySegments(castMedia) + d.segments = nil + go d.querySegments(castMedia) + break } for i, segment := range d.segments { @@ -305,17 +307,19 @@ func (d *Device) queryVideoId(castMedia *cast.Media) { d.logger.Info("Video ID not found. Searching for video on YouTube...") d.prevArtist = currArtist d.prevTitle = currTitle - if err := util.Retry(d.ctx, 10, 500*time.Millisecond, func(try uint) (err error) { - castMedia.Media.ContentId, err = youtube.QueryVideoId(d.ctx, currArtist, currTitle) - if err != nil { - d.logger.Error("YouTube search failed.", "error", err.Error()) + go func() { + if err := util.Retry(d.ctx, 10, 500*time.Millisecond, func(try uint) (err error) { + castMedia.Media.ContentId, err = youtube.QueryVideoId(d.ctx, currArtist, currTitle) + if err != nil { + d.logger.Error("YouTube search failed.", "error", err.Error()) + } + return err + }); err != nil { + d.logger.Debug("Halting YouTube search retries.") + return } - return err - }); err != nil { - d.logger.Debug("Halting YouTube search retries.") - return - } - d.logger.Debug("YouTube search found video ID", "video_id", castMedia.Media.ContentId) + d.logger.Debug("YouTube search found video ID", "video_id", castMedia.Media.ContentId) + }() } } }