Example #1
0
        public async Task RefreshPlaylist(IList <ChainLink> lastMonthsChainLinks, SpotifyPlaylist playlist)
        {
            var accessToken = await GetAccessToken();

            var trackIds = GetTrackIds(lastMonthsChainLinks, accessToken);

            var updatePlayListDescriptionTask = UpdatePlaylistDescription(playlist, accessToken);

            var updatePlaylistTask = UpdatePlaylist(playlist, accessToken, await trackIds);

            await Task.WhenAll(new List <Task> {
                updatePlayListDescriptionTask, updatePlaylistTask
            });
        }
Example #2
0
        private async Task UpdatePlaylist(SpotifyPlaylist playlist, string accessToken, List <string> trackIds)
        {
            _log.LogInformation($"Updating Spotify playlist {playlist.PlaylistUri}...");
            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            var payload  = new { uris = trackIds };
            var response = await client.PutAsync($"{playlist.PlaylistUri}/tracks",
                                                 new StringContent(JsonConvert.SerializeObject(payload)));

            if (response.IsSuccessStatusCode)
            {
                _log.LogInformation("Updated Spotify playlist");
            }
            else
            {
                var errorMessage = await response.Content.ReadAsStringAsync();

                _log.LogError($"Error updating playlist: {response.StatusCode} {errorMessage}", response);
            }
        }