Skip to content

Commit ca8c394

Browse files
author
Datanoise
committed
fix: resolve duplicate JS declaration and restore admin dashboard functionality
1 parent 65205f4 commit ca8c394

5 files changed

Lines changed: 24 additions & 2 deletions

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010

1111
require (
1212
github.com/braheezy/shine-mp3 v0.1.0 // indirect
13+
github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8 // indirect
1314
github.com/dustin/go-humanize v1.0.1 // indirect
1415
github.com/go-audio/audio v1.0.0 // indirect
1516
github.com/go-audio/riff v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ github.com/braheezy/shine-mp3 v0.1.0 h1:N2wZhv6ipCFduTSftaPNdDgZ5xFmQAPvB7JcqA4s
22
github.com/braheezy/shine-mp3 v0.1.0/go.mod h1:0H/pmcpFAd+Fnrj6Pc7du7wL36U/HqtfcgPJuCgc1L4=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8 h1:OtSeLS5y0Uy01jaKK4mA/WVIYtpzVm63vLVAPzJXigg=
6+
github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8/go.mod h1:apkPC/CR3s48O2D7Y++n1XWEpgPNNCjXYga3PPbJe2E=
57
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
68
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
79
github.com/glebarez/go-sqlite v1.22.0 h1:uAcMJhaA6r3LHMTFgP0SifzgXg46yJkgxqyuyec+ruQ=

relay/relay.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ func (r *Relay) GetStream(mount string) (*Stream, bool) {
247247
return s, ok
248248
}
249249

250+
func (r *Relay) UpdateMetadata(mount, song string) {
251+
if st, ok := r.GetStream(mount); ok {
252+
st.SetCurrentSong(song, r)
253+
}
254+
}
255+
250256
// IsOgg returns true if the stream is Ogg-based (Ogg/Vorbis, Ogg/Opus, etc)
251257
func (s *Stream) IsOgg() bool {
252258
ct := strings.ToLower(s.ContentType)

relay/streamer.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/DatanoiseTV/tinyice/config"
14+
"github.com/dhowden/tag"
1415
"github.com/hajimehoshi/go-mp3"
1516
"github.com/sirupsen/logrus"
1617
)
@@ -352,13 +353,25 @@ func (sm *StreamerManager) streamFile(ctx context.Context, s *Streamer, path str
352353
}
353354
defer f.Close()
354355

356+
// Extract metadata
357+
songTitle := filepath.Base(path)
358+
if m, err := tag.ReadFrom(f); err == nil {
359+
if m.Artist() != "" && m.Title() != "" {
360+
songTitle = fmt.Sprintf("%s - %s", m.Artist(), m.Title())
361+
} else if m.Title() != "" {
362+
songTitle = m.Title()
363+
}
364+
}
365+
// Seek back to start after reading tags
366+
f.Seek(0, 0)
367+
355368
decoder, err := mp3.NewDecoder(f)
356369
if err != nil {
357370
return err
358371
}
359372

360373
s.mu.Lock()
361-
s.CurrentFile = filepath.Base(path)
374+
s.CurrentFile = songTitle
362375
s.CurrentFileTime = time.Now()
363376
s.CurrentFileDuration = time.Duration(decoder.Length()) * time.Second / (44100 * 2 * 2) // Rough estimate for 44.1kHz 16bit stereo
364377
s.mu.Unlock()
@@ -368,6 +381,7 @@ func (sm *StreamerManager) streamFile(ctx context.Context, s *Streamer, path str
368381
if s.InjectMetadata {
369382
output.CurrentSong = s.CurrentFile
370383
output.Name = s.Name
384+
sm.relay.UpdateMetadata(s.OutputMount, s.CurrentFile)
371385
}
372386
output.Bitrate = fmt.Sprintf("%d", s.Bitrate)
373387

server/templates/admin.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,6 @@ <h2>Edit AutoDJ</h2>
805805
});
806806
}
807807

808-
const csrfToken = "{{.CSRFToken}}";
809808
function showTab(id, updateHash) {
810809
document.querySelectorAll('.tab-content').forEach(function(t) { t.classList.remove('active'); });
811810
document.querySelectorAll('.nav-link').forEach(function(t) { t.classList.remove('active'); });

0 commit comments

Comments
 (0)