예제 #1
0
        /// <summary>
        /// ビデオをプレイリストに追加する
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns></returns>
        public async Task AddVideoToPlaylist(string id)
        {
            // 入力の検証
            var playlistVm = this;
            var videoId    = id;

            if (playlistVm == null || string.IsNullOrEmpty(videoId))
            {
                return;
            }

            // 以下を参考にプレイリストに指定の動画を追加
            // https://github.com/youtube/api-samples/blob/master/dotnet/Google.Apis.YouTube.Samples.Playlists/PlaylistUpdates.cs#L94
            var factory = new YoutubeServiceFactory();
            var service = await factory.Create();

            var playlistItem = new PlaylistItem();

            playlistItem.Snippet                    = new PlaylistItemSnippet();
            playlistItem.Snippet.PlaylistId         = playlistVm.Id;
            playlistItem.Snippet.ResourceId         = new ResourceId();
            playlistItem.Snippet.ResourceId.Kind    = "youtube#video";
            playlistItem.Snippet.ResourceId.VideoId = videoId;
            playlistItem = await service.PlaylistItems.Insert(playlistItem, "snippet").ExecuteAsync();

            PlaylistItemViewModels.Add(new PlaylistItemViewModel(playlistItem, this));
        }
예제 #2
0
        /// <summary>
        /// プレイリストのアイテムを削除します
        /// </summary>
        /// <param name="id">ID</param>
        internal async void RemovePlaylistItem(string id)
        {
            var factory = new YoutubeServiceFactory();
            var service = await factory.Create();

            await service.PlaylistItems.Delete(id).ExecuteAsync();

            // VMからも一致するアイテムを削除する
            PlaylistItemViewModels.Remove(PlaylistItemViewModels.First(item => item.Id == id));
        }
예제 #3
0
        /// <summary>
        /// プレイリストのアイテムを追加します
        /// </summary>
        /// <param name="vm">ViewModel</param>
        /// <returns></returns>
        internal async void AddPlaylistItem(PlaylistItemViewModel vm)
        {
            // 以下を参考にプレイリストに指定の動画を追加
            // https://github.com/youtube/api-samples/blob/master/dotnet/Google.Apis.YouTube.Samples.Playlists/PlaylistUpdates.cs#L94
            var factory = new YoutubeServiceFactory();
            var service = await factory.Create();

            var playlistItem = new PlaylistItem();

            playlistItem.Snippet            = new PlaylistItemSnippet();
            playlistItem.Snippet.PlaylistId = Playlist.Id;
            playlistItem.Snippet.ResourceId = vm.PlaylistItem.Snippet.ResourceId;
            playlistItem = await service.PlaylistItems.Insert(playlistItem, "snippet").ExecuteAsync();

            PlaylistItemViewModels.Add(new PlaylistItemViewModel(playlistItem, this));
        }