Skip to content

Commit

Permalink
lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
jmillerv committed Dec 10, 2023
1 parent e56412a commit 3ba2ecf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 25 deletions.
7 changes: 3 additions & 4 deletions content/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"strings"
"time"

"github.com/pkg/errors"

"github.com/faiface/beep"
"github.com/faiface/beep/flac"
"github.com/faiface/beep/mp3"
Expand All @@ -19,6 +17,7 @@ import (
"github.com/faiface/beep/wav"
"github.com/h2non/filetype"
"github.com/hcl/audioduration"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -59,7 +58,7 @@ func (l *LocalFile) Play() error {

err := l.setDecoder()
if err != nil {
return errors.New(fmt.Sprintf("error setting decoder: %v", err)) //nolint:revive,gosimple // error pref
return errors.New(fmt.Sprintf("error setting decoder: %v", err)) //nolint:revive
}

_, err = l.Content.Seek(0, 0)
Expand All @@ -70,7 +69,7 @@ func (l *LocalFile) Play() error {
if l.fileType == wavFile || l.fileType == flacFile {
streamer, format, err = l.decodeReader(l.Content)
if err != nil {
return errors.New(fmt.Sprintf("unable to decode file: %v", err)) //nolint:revive,gosimple // error pref
return errors.New(fmt.Sprintf("unable to decode file: %v", err)) //nolint:revive
}
}

Expand Down
8 changes: 5 additions & 3 deletions content/podcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ func (p *Podcast) Play() error {
log.Infof("time remaining: %v", p.Duration)
time.Sleep(p.Duration)
log.Info("stopping web radio")
err := p.Stop()
if err != nil {
log.WithError(err).Error("error stopping web radio")

podcastStopErr := p.Stop()
if podcastStopErr != nil {
log.WithError(podcastStopErr).Error("error stopping web radio")
}

close(done)
}()

Expand Down
2 changes: 1 addition & 1 deletion content/podcast_episodes_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (p *podcasts) getOldestEpisode() episode {
func (p *podcasts) getRandomEpisode() episode {
var randomEpisode episode

rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec // weak generator fine fo this purpose

item := p.Episodes[rand.Intn(len(p.Episodes))] //nolint:gosec // weak generator fine fo this purpose
_, cacheHit := cache.PodcastPlayedCache.Get(item.GUID)
Expand Down
24 changes: 13 additions & 11 deletions content/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *Scheduler) Run() error { //nolint:godox,funlen,gocognit,cyclop,nolintli

// if content is scheduled, retrieve and play
scheduled := p.Timeslot.IsScheduledNow(now)
if scheduled {
if scheduled { //nolint:nestif
log.Infof("scheduler.Run::getting media type: %v", p.Type)

content := p.GetMedia()
Expand All @@ -78,7 +78,7 @@ func (s *Scheduler) Run() error { //nolint:godox,funlen,gocognit,cyclop,nolintli

// if p.getMediaType is webRadioContent or podcastContent start a timer and stop content from inside a go routine
// because these are streams rather than files they behave differently from local content.
switch p.getMediaType() { //nolint:exhaustive // TODO consider refactoring into function
switch p.getMediaType() { //nolint:exhaustive,dupl // TODO consider refactoring into function
case webRadioContent:
log.Info("web radio content detected")

Expand All @@ -91,9 +91,10 @@ func (s *Scheduler) Run() error { //nolint:godox,funlen,gocognit,cyclop,nolintli
go func() {
defer wg.Done()
log.Info("Run::playing web radio inside of a go routine")
err := content.Play()
if err != nil {
log.WithError(err).Error("Run::content.Play")

contentPlayErr := content.Play()
if contentPlayErr != nil {
log.WithError(contentPlayErr).Error("Run::content.Play")
} // play will block until done
}()

Expand All @@ -105,19 +106,19 @@ func (s *Scheduler) Run() error { //nolint:godox,funlen,gocognit,cyclop,nolintli
// If the StrictPodcastSchedule is set to false, use the duration of the podcast to set the countdown.
if !s.Content.StrictPodcastSchedule {
podcast.Duration = podcast.Player.duration

} else {
podcast.Duration = getDurationToEndTime(p.Timeslot.End)
}

wg.Add(1)

go func() {
defer wg.Done()
log.Info("playing podcast inside of a go routine")

err = content.Play()
contentPlayErr := content.Play()
if err != nil {
log.WithError(err).Error("Run::content.Play")
log.WithError(contentPlayErr).Error("Run::content.Play")
} // play will block until done
}()
default:
Expand Down Expand Up @@ -175,7 +176,7 @@ func (s *Scheduler) Shuffle() error { //nolint:godox,funlen,gocognit,cyclop,noli

log.Info("Starting Daemon")

rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec // weak generator fine fo this purpose
rand.Shuffle(len(s.Content.Programs),
func(i, j int) {
s.Content.Programs[i], s.Content.Programs[j] = s.Content.Programs[j], s.Content.Programs[i]
Expand Down Expand Up @@ -228,7 +229,8 @@ func (s *Scheduler) Shuffle() error { //nolint:godox,funlen,gocognit,cyclop,noli
go func() {
defer wg.Done()
log.Info("Run::playing web radio inside of a go routine")
err := content.Play()

err = content.Play()
if err != nil {
log.WithError(err).Error("Run::content.Play")
} // play will block until done
Expand All @@ -241,12 +243,12 @@ func (s *Scheduler) Shuffle() error { //nolint:godox,funlen,gocognit,cyclop,noli
// If the StrictPodcastSchedule is set to false, use the duration of the podcast to set the countdown.
if !s.Content.StrictPodcastSchedule {
podcast.Duration = podcast.Player.duration

} else {
podcast.Duration = getDurationToEndTime(p.Timeslot.End)
}

wg.Add(1)

go func() {
defer wg.Done()
log.Info("playing podcast inside of a go routine")
Expand Down
15 changes: 11 additions & 4 deletions content/web_radio.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,23 @@ func (w *WebRadio) Play() error {
log.Infof("time remaining: %v", w.Duration)
time.Sleep(w.Duration)
log.Info("stopping web radio")
err := w.Stop()
if err != nil {
log.WithError(err).Error("error stopping web radio")

webRadioStopErr := w.Stop()
if webRadioStopErr != nil {
log.WithError(webRadioStopErr).Error("error stopping web radio")
}

close(done)
}()

go func() {
w.Player.pipeChan <- w.Player.out
}()
<-done // wait for done signal from the duration routine

}

log.Info("WebRadio.Play::returning nil")

return nil
}

Expand All @@ -87,7 +90,9 @@ func (w *WebRadio) Stop() error {

if w.Player.isPlaying {
log.Debug("WebRadio.Stop::setting isPlaying to false")

w.Player.isPlaying = false

_, err := w.Player.in.Write([]byte("q"))
if err != nil {
log.WithError(err).Error("error stopping web radio streamPlayerName: w.Player.in.Write()")
Expand All @@ -106,6 +111,8 @@ func (w *WebRadio) Stop() error {
w.Player.command = nil
w.Player.url = ""
}

log.Debug("WebRadio.Stop::returning nil")

return nil
}
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() { //nolint:funlen,cyclop // main function can be longer & more compl
Usage: "Daemon that schedules audio programming content",
Version: "0.0.1",
Commands: cli.Commands{
{
{ //nolint:exhaustruct
Name: "start",
Aliases: []string{"s"},
Usage: "start",
Expand Down Expand Up @@ -93,7 +93,7 @@ func main() { //nolint:funlen,cyclop // main function can be longer & more compl
},
},
},
{
{ //nolint:exhaustruct
Name: "clear-cache",
Aliases: []string{"clear"},
Usage: "./go-dj clear-cache",
Expand Down

0 comments on commit 3ba2ecf

Please sign in to comment.