Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (c *Client) CheckTracks(tracks []*models.Track) error {
return nil
}

func (c *Client) CreatePlaylist(tracks []*models.Track) error {
func (c *Client) RefreshLibrary() error {
if c.System == "" {
return fmt.Errorf("could not get music system")
}
Expand All @@ -204,6 +204,13 @@ func (c *Client) CreatePlaylist(tracks []*models.Track) error {
slog.Debug("falling back on SLEEP env variable")
time.Sleep(time.Duration(c.Cfg.Sleep) * time.Minute)
}
return nil
}

func (c *Client) CreatePlaylist(tracks []*models.Track) error {
if c.System == "" {
return fmt.Errorf("could not get music system")
}

if err := c.API.SearchSongs(tracks); err != nil { // search newly added songs
slog.Warn("SearchSongs failed", "context", err)
Expand Down
13 changes: 10 additions & 3 deletions src/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ func NewDownloader(cfg *cfg.DownloadConfig, httpClient *util.HttpClient, filterL
Downloaders: downloader}, nil
}

func (c *DownloadClient) StartDownload(tracks *[]*models.Track) {
func (c *DownloadClient) StartDownload(tracks *[]*models.Track) int {
if c.Cfg.ExcludeLocal { // remove locally found tracks, so they can't be added to playlist
filterLocalTracks(tracks, true)
}

var newDownloads atomic.Int32

if c.needsDownloadDir() {
if err := os.MkdirAll(c.Cfg.DownloadDir, 0755); err != nil {
slog.Error(err.Error())
return
return 0
}
}

Expand Down Expand Up @@ -100,13 +102,17 @@ func (c *DownloadClient) StartDownload(tracks *[]*models.Track) {
return nil
}

if track.Present {
newDownloads.Add(1)
}

return nil
})
}

if err := g.Wait(); err != nil {
slog.Warn(err.Error())
return
return int(newDownloads.Load())
}

if m, ok := d.(Monitor); ok {
Expand All @@ -117,6 +123,7 @@ func (c *DownloadClient) StartDownload(tracks *[]*models.Track) {
}

filterLocalTracks(tracks, false)
return int(newDownloads.Load())
}
func (c *DownloadClient) needsDownloadDir() bool {
for _, svc := range c.Cfg.Services {
Expand Down
9 changes: 8 additions & 1 deletion src/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,14 @@ func main() {
}

if cfg.Flags.DownloadMode != "skip" {
downloader.StartDownload(&tracks)
newDownloads := downloader.StartDownload(&tracks)
if newDownloads > 0 {
if err := client.RefreshLibrary(); err != nil {
slog.Warn(err.Error())
}
} else {
slog.Info("no new tracks downloaded, skipping library refresh", "system", cfg.System)
}
if len(tracks) == 0 {
slog.Error("couldn't download any tracks", "notify", true)
os.Exit(1)
Expand Down