Skip to content

Commit e7ed284

Browse files
committed
check library scan state for supported clients
1 parent 646cbb2 commit e7ed284

6 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/client/client.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type APIClient interface {
2424
AddLibrary() error
2525
SearchSongs([]*models.Track) error
2626
RefreshLibrary() error
27+
CheckRefreshState() bool
2728
CreatePlaylist([]*models.Track) error
2829
SearchPlaylist() error
2930
UpdatePlaylist() error
@@ -142,9 +143,11 @@ func (c *Client) CreatePlaylist(tracks []*models.Track) error {
142143
if err := c.API.RefreshLibrary(); err != nil {
143144
return fmt.Errorf("[%s] failed to schedule a library scan: %s", c.System, err.Error())
144145
}
145-
146146
slog.Info("Refreshing library...", "system", c.System)
147-
time.Sleep(time.Duration(c.Cfg.Sleep) * time.Minute)
147+
if !c.API.CheckRefreshState() {
148+
time.Sleep(time.Duration(c.Cfg.Sleep) * time.Minute)
149+
}
150+
148151
if err := c.API.SearchSongs(tracks); err != nil { // search newly added songs
149152
slog.Warn("SearchSongs failed", "context", err)
150153
}

src/client/emby.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ func (c *Emby) RefreshLibrary() error {
120120
return nil
121121
}
122122

123+
func (c *Emby) CheckRefreshState() bool {
124+
return false
125+
}
126+
123127
func (c *Emby) SearchSongs(tracks []*models.Track) error {
124128
for _, track := range tracks {
125129
reqParam := fmt.Sprintf("/emby/Items?IncludeMediaTypes=Audio&SearchTerm=%s&Recursive=true&Fields=Path", url.QueryEscape(track.CleanTitle))

src/client/jellyfin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ func (c *Jellyfin) RefreshLibrary() error {
130130
return nil
131131
}
132132

133+
func (c *Jellyfin) CheckRefreshState() bool {
134+
return false
135+
}
136+
133137
func (c *Jellyfin) SearchSongs(tracks []*models.Track) error {
134138
for _, track := range tracks {
135139
reqParam := fmt.Sprintf("/Items?IncludeMediaTypes=Audio&SearchTerm=%s&Recursive=true&Fields=Path", url.QueryEscape(track.CleanTitle))

src/client/mpd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func (c *MPD) RefreshLibrary() error {
5959
return nil
6060
}
6161

62+
func (c *MPD) CheckRefreshState() bool {
63+
return true
64+
}
65+
6266
func (c *MPD) CreatePlaylist(tracks []*models.Track) error {
6367
f, err := os.OpenFile(c.Cfg.PlaylistDir+c.Cfg.PlaylistName+".m3u", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
6468
if err != nil {

src/client/plex.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ func (c *Plex) RefreshLibrary() error {
223223
return nil
224224
}
225225

226+
func (c *Plex) CheckRefreshState() bool {
227+
return false
228+
}
229+
226230
func (c *Plex) SearchSongs(tracks []*models.Track) error {
227231
for _, track := range tracks {
228232
params := fmt.Sprintf("/library/search?query=%s", url.QueryEscape(track.CleanTitle))

src/client/subsonic.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ func (c *Subsonic) startScan() error {
180180
return nil
181181
}
182182

183+
func (c *Subsonic) CheckRefreshState() bool {
184+
return false
185+
}
186+
183187
func (c *Subsonic) CreatePlaylist(tracks []*models.Track) error {
184188
var trackIDs strings.Builder
185189
for _, track := range tracks { // build songID parameters

0 commit comments

Comments
 (0)