public bool UpdateSongPositionInPlaylist( string userEmail, string playlistId, YouTubeSong song, int position) { var isSuccessfullyUpdated = false; try { var service = new YouTubeServiceClient(); service.UpdatePlaylistItemAsync(userEmail, song.SongId, playlistId, song.PlayListItemId, position).Wait(); isSuccessfullyUpdated = true; } catch (AggregateException ex) { foreach (var e in ex.InnerExceptions) { //TODO: Add Logging isSuccessfullyUpdated = false; } } return(isSuccessfullyUpdated); }
private async Task GetPlayListSongsInternalAsync(string userEmail, string playListId, List <IYouTubeSong> playListSongs) { var youtubeService = await GetYouTubeService(userEmail); var channelsListRequest = youtubeService.Channels.List("contentDetails"); channelsListRequest.Mine = true; var nextPageToken = ""; while (nextPageToken != null) { var listRequest = youtubeService.PlaylistItems.List("contentDetails"); listRequest.MaxResults = 50; listRequest.PlaylistId = playListId; listRequest.PageToken = nextPageToken; var response = await listRequest.ExecuteAsync(); if (playListSongs == null) { playListSongs = new List <IYouTubeSong>(); } foreach (var playlistItem in response.Items) { var videoR = youtubeService.Videos.List("snippet,contentDetails,status"); videoR.Id = playlistItem.ContentDetails.VideoId; var responseV = await videoR.ExecuteAsync(); if (responseV.Items.Count > 0) { var parsedSong = SongTitleParser.ParseTitle(responseV.Items[0].Snippet.Title); var duration = new DurationParser().GetDuration(responseV.Items[0].ContentDetails.Duration); IYouTubeSong currentSong = new YouTubeSong(parsedSong.Key, parsedSong.Value, responseV.Items[0].Snippet.Title, responseV.Items[0].Id, playlistItem.Id, duration); playListSongs.Add(currentSong); Debug.WriteLine(currentSong.Title); } } nextPageToken = response.NextPageToken; } }