From ee25f00ec0f0ed2a843c18f6c93121176034ea79 Mon Sep 17 00:00:00 2001 From: Markus Kuuse Date: Wed, 6 Nov 2024 19:12:05 +0200 Subject: [PATCH] if track exists, don't search for it again --- src/jellyfin.go | 15 +++++++++------ src/listenbrainz.go | 1 + src/playlist.go | 3 ++- src/subsonic.go | 14 +++++++++----- 4 files changed, 21 insertions(+), 12 deletions(-) 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)