Skip to content

Commit

Permalink
fix: Fix YouTube API being queried multiple times if video is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Sep 3, 2023
1 parent d5123c7 commit bc46719
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/device/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ func (d *Device) queryVideoId(castMedia *cast.Media) error {
if currArtist == d.prevArtist && currTitle == d.prevTitle {
castMedia.Media.ContentId = d.prevVideoId
} else {
defer func() {
d.prevArtist = currArtist
d.prevTitle = currTitle
}()
if config.Default.YouTubeAPIKey == "" {
d.logger.Warn("Video ID not found. Please set a YouTube API key.")
} else {
Expand All @@ -304,8 +308,6 @@ func (d *Device) queryVideoId(castMedia *cast.Media) error {
return err
}
}
d.prevArtist = currArtist
d.prevTitle = currTitle
}
return nil
}
Expand Down

0 comments on commit bc46719

Please sign in to comment.