Skip to content

Commit

Permalink
feat: support internet radio stations for jukebox
Browse files Browse the repository at this point in the history
fixes #481
  • Loading branch information
sentriz committed Mar 11, 2024
1 parent 6ce1fe5 commit 62d49a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion jukebox/jukebox.go
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"regexp"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -133,7 +134,9 @@ func (j *Jukebox) SetPlaylist(items []string) error {

var newPlayingIndex = -1
for i, item := range items {
item, _ = filepath.Abs(item)
if !strings.HasPrefix(item, "http") {
item, _ = filepath.Abs(item)
}
if currentPlayingIndex >= 0 && playlist[currentPlayingIndex].Filename == item {
newPlayingIndex = i
continue // don't add current track to loadlist
Expand Down
2 changes: 1 addition & 1 deletion server/ctrlsubsonic/handlers_common.go
Expand Up @@ -437,7 +437,7 @@ func (c *Controller) ServeJukebox(r *http.Request) *spec.Response { // nolint:go
case "get":
specPlaylist, err := getSpecPlaylist()
if err != nil {
return spec.NewError(10, "error getting status tracks: %v", err)
return spec.NewError(10, "error getting spec playlist: %v", err)
}
status, err := getSpecStatus()
if err != nil {
Expand Down
11 changes: 10 additions & 1 deletion server/ctrlsubsonic/specidpaths/specidpaths.go
Expand Up @@ -39,7 +39,7 @@ func Locate(dbc *db.DB, id specid.ID) (Result, error) {

// Locate maps a location on the filesystem to a specid
func Lookup(dbc *db.DB, musicPaths []string, podcastsPath string, path string) (Result, error) {
if !filepath.IsAbs(path) {
if !strings.HasPrefix(path, "http") && !filepath.IsAbs(path) {
return nil, ErrNotAbs
}

Expand All @@ -56,6 +56,15 @@ func Lookup(dbc *db.DB, musicPaths []string, podcastsPath string, path string) (
return nil, ErrNotFound
}

// probably internet radio
if strings.HasPrefix(path, "http") {
var irs db.InternetRadioStation
if err := dbc.First(&irs, "stream_url=?", path).Error; err == nil {
return &irs, nil
}
return nil, ErrNotFound
}

var musicPath string
for _, mp := range musicPaths {
if fileutil.HasPrefix(path, mp) {
Expand Down

0 comments on commit 62d49a3

Please sign in to comment.