diff --git a/src/jellyfin.go b/src/jellyfin.go index 9345dbd..8f940af 100644 --- a/src/jellyfin.go +++ b/src/jellyfin.go @@ -159,13 +159,16 @@ func createJfPlaylist(cfg Config, tracks []Track) error { var songIDs []string for _, track := range tracks { - songID, err := getJfSong(cfg, track) - if songID == "" || err != nil { - debug.Debug(fmt.Sprintf("could not get %s", track.File)) - continue + if track.ID == "" { + songID, err := getJfSong(cfg, track) + if songID == "" || err != nil { + debug.Debug(fmt.Sprintf("could not get %s", track.File)) + continue + } + track.ID = songID + } + songIDs = append(songIDs, track.ID) } - songIDs = append(songIDs, songID) -} params := "/Playlists" diff --git a/src/listenbrainz.go b/src/listenbrainz.go index 189e44d..a40d77a 100644 --- a/src/listenbrainz.go +++ b/src/listenbrainz.go @@ -99,6 +99,7 @@ type Exploration struct { type Track struct { Album string + ID string Artist string Title string File string diff --git a/src/playlist.go b/src/playlist.go index 882ddf2..c3e99b5 100644 --- a/src/playlist.go +++ b/src/playlist.go @@ -34,7 +34,7 @@ func (cfg *Config) getPlaylistName() { cfg.PlaylistName = playlistName } -func checkTracks(cfg Config, tracks []Track) []Track { // Returns updated slice with Present status +func checkTracks(cfg Config, tracks []Track) []Track { // Returns updated slice with Present status and song ID (if available) for i, track := range tracks { var ID string switch cfg.System { @@ -45,6 +45,7 @@ func checkTracks(cfg Config, tracks []Track) []Track { // Returns updated slice } if ID != "" { tracks[i].Present = true + tracks[i].ID = ID } } return tracks diff --git a/src/subsonic.go b/src/subsonic.go index 7aed19f..c536655 100644 --- a/src/subsonic.go +++ b/src/subsonic.go @@ -115,13 +115,17 @@ func subsonicPlaylist(cfg Config, tracks []Track) error { var reqParam string for _, track := range tracks { // Get track IDs from app and format them - ID, err := searchTrack(cfg, track) - if ID == "" || err != nil { // if ID is empty, skip song - debug.Debug(err.Error()) - continue + if track.ID == "" { + songID, err := searchTrack(cfg, track) + if songID == "" || err != nil { // if ID is empty, skip song + debug.Debug(fmt.Sprintf("could not get %s", track.File)) + continue + } + track.ID = songID } - trackIDs += "&songId="+ID + trackIDs += "&songId="+track.ID } + reqParam = fmt.Sprintf("createPlaylist?name=%s%s&f=json", cfg.PlaylistName, trackIDs) _, err := subsonicRequest(reqParam, cfg)