Skip to content

Commit

Permalink
fix(device): Fix ad skip being blocked by API lookups
Browse files Browse the repository at this point in the history
Ref #27
  • Loading branch information
gabe565 committed Oct 3, 2023
1 parent 6418104 commit a0de9b7
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions internal/device/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}()
}
}
}
Expand Down

0 comments on commit a0de9b7

Please sign in to comment.