Skip to content

Commit

Permalink
feat(subsonic): gracefully handle missing podcast episode paths when …
Browse files Browse the repository at this point in the history
…returning playlists

fixes #345

* fix return playlist if file not found and do not add to playlist not downloaded podcast

---------

Co-authored-by: sentriz <[email protected]>
  • Loading branch information
archekb and sentriz authored Aug 15, 2023
1 parent 7d2c4fb commit d5f8e23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion server/ctrlsubsonic/handlers_playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"log"
"net/http"
"sort"
"time"
Expand Down Expand Up @@ -208,8 +209,10 @@ func playlistRender(c *Controller, params params.Params, playlistID string, play
for _, path := range playlist.Items {
file, err := specidpaths.Lookup(c.DB, PathsOf(c.MusicPaths), c.PodcastsPath, path)
if err != nil {
return nil, fmt.Errorf("lookup path %q: %w", path, err)
log.Printf("error looking up path %q: %s", path, err)
continue
}

var trch *spec.TrackChild
switch id := file.SID(); id.Type {
case specid.Track:
Expand Down Expand Up @@ -237,5 +240,8 @@ func playlistRender(c *Controller, params params.Params, playlistID string, play
trch.TranscodedSuffix = transcodeSuffix
resp.List = append(resp.List, trch)
}

resp.SongCount = len(resp.List)

return resp, nil
}
2 changes: 1 addition & 1 deletion server/ctrlsubsonic/specidpaths/specidpaths.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Locate(dbc *db.DB, podcastsPath string, id specid.ID) (Result, error) {
}
case specid.PodcastEpisode:
var pe db.PodcastEpisode
if err := dbc.Where("id=?", id.Value).Find(&pe).Error; err == nil {
if err := dbc.Where("id=? AND status=?", id.Value, db.PodcastEpisodeStatusCompleted).Find(&pe).Error; err == nil {
pe.AbsP = filepath.Join(podcastsPath, pe.Path)
return &pe, err
}
Expand Down

0 comments on commit d5f8e23

Please sign in to comment.