private async Task AddSongToPlaylist(Playlist playlist, string song, bool checkExistence = true) { if (playlist == null || string.IsNullOrWhiteSpace(song) || song == "+") { return; } if (checkExistence && _trackRepository.Exists(playlist, song)) { return; } var track = await _spotify.SearchForATrackAsync(song); if (track == null) { _logger.LogWarning("{SearchedSong} : SpotifyFileNotFound!", song); track = new Track { Song = song, Playlist = playlist }; _trackRepository.Register(track); // To avoid searching for the track again and again return; } if (await _spotify.AddTrackToPlaylistAsync(playlist, track)) { _logger.LogInformation("Spotify track is added. Playlist:{PlaylistName} Artist:{ArtistName} Track:{TrackName}", playlist.Name, track.Artists.FirstOrDefault()?.Name, track.Name); track.Song = song; track.Playlist = playlist; _trackRepository.Register(track); } }