@@ -4,12 +4,11 @@ import (
44 "bytes"
55 "encoding/json"
66 "fmt"
7- "log"
7+ "log/slog "
88 "net/url"
99 "strings"
1010
1111 "explo/src/config"
12- "explo/src/debug"
1312 "explo/src/models"
1413 "explo/src/util"
1514)
@@ -193,8 +192,8 @@ func (c *Plex) GetLibrary() error {
193192 }
194193 }
195194 if err = c .AddLibrary (); err != nil {
196- debug .Debug (err .Error ())
197- log . Fatalf ("library named %s not found and cannot be added, please create it manually and ensure 'Prefer local metadata' is checked" , c .Cfg .LibraryName )
195+ slog .Debug (err .Error ())
196+ return fmt . Errorf ("library named %s not found and cannot be added, please create it manually and ensure 'Prefer local metadata' is checked" , c .Cfg .LibraryName )
198197 }
199198 return fmt .Errorf ("library '%s' not found" , c .Cfg .LibraryName )
200199}
@@ -230,18 +229,18 @@ func (c *Plex) SearchSongs(tracks []*models.Track) error {
230229
231230 body , err := c .HttpClient .MakeRequest ("GET" , c .Cfg .URL + params , nil , c .Cfg .Creds .Headers )
232231 if err != nil {
233- log . Printf ("search request failed for '%s': %s" , track .Title , err .Error ())
232+ slog . Warn ("search request failed for '%s': %s" , track .Title , err .Error ())
234233 continue
235234 }
236235
237236 var searchResults PlexSearch
238237 if err = util .ParseResp (body , & searchResults ); err != nil {
239- log . Printf ("failed to parse response for '%s': %s" , track .Title , err .Error ())
238+ slog . Warn ("failed to parse response for '%s': %s" , track .Title , err .Error ())
240239 continue
241240 }
242241 key , err := getPlexSong (track , searchResults )
243242 if err != nil {
244- debug .Debug (err .Error ())
243+ slog .Debug (err .Error ())
245244 continue
246245 }
247246 if key != "" {
@@ -345,7 +344,7 @@ func getPlexSong(track *models.Track, searchResults PlexSearch) (string, error)
345344 artistMatch := strings .Contains (strings .ToLower (md .OriginalTitle ), loweredArtist ) || strings .Contains (strings .ToLower (md .GrandparentTitle ), loweredArtist )
346345
347346 if titleMatch && (albumMatch || artistMatch ) {
348- debug .Debug (fmt .Sprintf ("matched track via metadata: %s by %s Plex Key: %s " , track .Title , track .Artist , md . Key ))
347+ slog .Debug (fmt .Sprintf ("matched track via metadata: %s by %s" , track .Title , track .Artist ))
349348 return md .Key , nil
350349 }
351350
@@ -358,12 +357,12 @@ func getPlexSong(track *models.Track, searchResults PlexSearch) (string, error)
358357 durationMatch := util .Abs (media .Duration - track .Duration ) < 10000 // duration within 10s
359358
360359 if durationMatch && pathMatch {
361- debug .Debug (fmt .Sprintf ("matched track via path: %s by %s Plex Key: %s " , track .Title , track .Artist , md . Key ))
360+ slog .Debug (fmt .Sprintf ("matched track via path: %s by %s" , track .Title , track .Artist ))
362361 return md .Key , nil
363362 }
364363 }
365364
366- debug .Debug (fmt .Sprintf ("full search result: %v" , searchResults .MediaContainer .SearchResult ))
365+ slog .Debug (fmt .Sprintf ("full search result: %v" , searchResults .MediaContainer .SearchResult ))
367366 return "" , fmt .Errorf ("failed to find '%s' by '%s' in '%s'" , track .Title , track .Artist , track .Album )
368367}
369368
@@ -373,7 +372,7 @@ func (c *Plex) addtoPlaylist(tracks []*models.Track) {
373372 params := fmt .Sprintf ("/playlists/%s/items?uri=server://%s/com.plexapp.plugins.library%s" , c .Cfg .PlaylistID , c .machineID , track .ID )
374373
375374 if _ , err := c .HttpClient .MakeRequest ("PUT" , c .Cfg .URL + params , nil , c .Cfg .Creds .Headers ); err != nil {
376- log . Printf ("failed to add %s to playlist: %s" , track .Title , err .Error ())
375+ slog . Warn ("failed to add %s to playlist: %s" , track .Title , err .Error ())
377376 }
378377 }
379378 }
0 commit comments