Skip to content

Commit ee25f00

Browse files
committed
if track exists, don't search for it again
1 parent 5b68267 commit ee25f00

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

src/jellyfin.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,16 @@ func createJfPlaylist(cfg Config, tracks []Track) error {
159159
var songIDs []string
160160

161161
for _, track := range tracks {
162-
songID, err := getJfSong(cfg, track)
163-
if songID == "" || err != nil {
164-
debug.Debug(fmt.Sprintf("could not get %s", track.File))
165-
continue
162+
if track.ID == "" {
163+
songID, err := getJfSong(cfg, track)
164+
if songID == "" || err != nil {
165+
debug.Debug(fmt.Sprintf("could not get %s", track.File))
166+
continue
167+
}
168+
track.ID = songID
169+
}
170+
songIDs = append(songIDs, track.ID)
166171
}
167-
songIDs = append(songIDs, songID)
168-
}
169172

170173
params := "/Playlists"
171174

src/listenbrainz.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type Exploration struct {
9999

100100
type Track struct {
101101
Album string
102+
ID string
102103
Artist string
103104
Title string
104105
File string

src/playlist.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (cfg *Config) getPlaylistName() {
3434
cfg.PlaylistName = playlistName
3535
}
3636

37-
func checkTracks(cfg Config, tracks []Track) []Track { // Returns updated slice with Present status
37+
func checkTracks(cfg Config, tracks []Track) []Track { // Returns updated slice with Present status and song ID (if available)
3838
for i, track := range tracks {
3939
var ID string
4040
switch cfg.System {
@@ -45,6 +45,7 @@ func checkTracks(cfg Config, tracks []Track) []Track { // Returns updated slice
4545
}
4646
if ID != "" {
4747
tracks[i].Present = true
48+
tracks[i].ID = ID
4849
}
4950
}
5051
return tracks

src/subsonic.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,17 @@ func subsonicPlaylist(cfg Config, tracks []Track) error {
115115
var reqParam string
116116

117117
for _, track := range tracks { // Get track IDs from app and format them
118-
ID, err := searchTrack(cfg, track)
119-
if ID == "" || err != nil { // if ID is empty, skip song
120-
debug.Debug(err.Error())
121-
continue
118+
if track.ID == "" {
119+
songID, err := searchTrack(cfg, track)
120+
if songID == "" || err != nil { // if ID is empty, skip song
121+
debug.Debug(fmt.Sprintf("could not get %s", track.File))
122+
continue
123+
}
124+
track.ID = songID
122125
}
123-
trackIDs += "&songId="+ID
126+
trackIDs += "&songId="+track.ID
124127
}
128+
125129
reqParam = fmt.Sprintf("createPlaylist?name=%s%s&f=json", cfg.PlaylistName, trackIDs)
126130

127131
_, err := subsonicRequest(reqParam, cfg)

0 commit comments

Comments
 (0)