Skip to content

Commit

Permalink
if track exists, don't search for it again
Browse files Browse the repository at this point in the history
  • Loading branch information
LumePart committed Nov 6, 2024
1 parent 5b68267 commit ee25f00
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
15 changes: 9 additions & 6 deletions src/jellyfin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions src/listenbrainz.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type Exploration struct {

type Track struct {
Album string
ID string
Artist string
Title string
File string
Expand Down
3 changes: 2 additions & 1 deletion src/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
14 changes: 9 additions & 5 deletions src/subsonic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ee25f00

Please sign in to comment.