Skip to content

Commit 459b5af

Browse files
author
Datanoise
committed
fix: resolve AutoDJ start/stop issues, unpopulated playlist and forbidden errors
1 parent 9a65963 commit 459b5af

3 files changed

Lines changed: 146 additions & 123 deletions

File tree

relay/streamer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"math/rand"
77
"os"
88
"path/filepath"
9+
"strings"
910
"sync"
1011
"time"
1112

@@ -142,7 +143,8 @@ func (s *Streamer) ScanMusicDir() error {
142143

143144
s.Playlist = []string{}
144145
for _, f := range files {
145-
if !f.IsDir() && filepath.Ext(f.Name()) == ".mp3" {
146+
ext := strings.ToLower(filepath.Ext(f.Name()))
147+
if !f.IsDir() && ext == ".mp3" {
146148
s.Playlist = append(s.Playlist, filepath.Join(s.MusicDir, f.Name()))
147149
}
148150
}

server/server.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,7 @@ func (s *Server) handleToggleAutoDJ(w http.ResponseWriter, r *http.Request) {
22412241
}
22422242

22432243
mount := r.FormValue("mount")
2244+
found := false
22442245
for _, adj := range s.Config.AutoDJs {
22452246
if adj.Mount == mount {
22462247
adj.Enabled = !adj.Enabled
@@ -2253,11 +2254,29 @@ func (s *Server) handleToggleAutoDJ(w http.ResponseWriter, r *http.Request) {
22532254
} else {
22542255
s.StreamerM.StopStreamer(mount)
22552256
}
2257+
found = true
22562258
break
22572259
}
22582260
}
2259-
s.Config.SaveConfig()
22602261

2262+
if !found {
2263+
// Might be a legacy or manual streamer
2264+
streamer := s.StreamerM.GetStreamer(mount)
2265+
if streamer != nil {
2266+
s.StreamerM.StopStreamer(mount)
2267+
} else {
2268+
// If it was the legacy one, we can try to restart it
2269+
if mount == "/autodj" && s.Config.MusicDir != "" {
2270+
streamer, err := s.StreamerM.StartStreamer("AutoDJ", "/autodj", s.Config.MusicDir, true, "mp3", 128, true)
2271+
if err == nil {
2272+
streamer.ScanMusicDir()
2273+
streamer.Play()
2274+
}
2275+
}
2276+
}
2277+
}
2278+
2279+
s.Config.SaveConfig()
22612280
http.Redirect(w, r, "/admin#tab-streamer", http.StatusSeeOther)
22622281
}
22632282

0 commit comments

Comments
 (0)