Exemple #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));
        }
Exemple #2
0
        /// <summary>
        /// プレイリストを取得する
        /// </summary>
        /// <returns></returns>
        public async Task GetPlaylist()
        {
            // Playlistをクリアする
            PlaylistViewModels.Clear();

            var factory = new YoutubeServiceFactory();
            var service = await factory.Create();

            var newPlaylist     = service.Playlists.List("snippet");
            var newPlaylistItem = service.PlaylistItems.List("snippet");

            // 100件まで編集可能とする
            newPlaylistItem.MaxResults = 100;
            // チャンネルIDを指定することでも取得可能
            // newPlaylist.ChannelId = "UCpkkP5J-16g3zgfuIihCTrA";
            newPlaylist.Mine = true;
            var list = await newPlaylist.ExecuteAsync();

            foreach (var playlist in list.Items)
            {
                var playlistVm = new PlaylistViewModel(playlist, this);
                PlaylistViewModels.Add(playlistVm);

                newPlaylistItem.PlaylistId = playlist.Id;
                var item = await newPlaylistItem.ExecuteAsync();

                foreach (var playlistItem in item.Items)
                {
                    playlistVm.PlaylistItemViewModels.Add(new PlaylistItemViewModel(playlistItem, playlistVm));
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// プレイリストを追加する
        /// </summary>
        /// <returns></returns>
        public async Task AddPlaylist()
        {
            // 入力の検証
            if (string.IsNullOrEmpty(AddPlaylistTitle.Value))
            {
                return;
            }

            // 入力結果からプレイリストを追加する
            var factory = new YoutubeServiceFactory();
            var service = await factory.Create();

            var newPlaylist = new Playlist();

            newPlaylist.Snippet             = new PlaylistSnippet();
            newPlaylist.Snippet.Title       = AddPlaylistTitle.Value;
            newPlaylist.Snippet.Description = AddPlaylistDescription.Value;
            newPlaylist.Status = new PlaylistStatus();
            newPlaylist.Status.PrivacyStatus = "private";
            newPlaylist = await service.Playlists.Insert(newPlaylist, "snippet,status").ExecuteAsync();

            // 追加後にフォームの値をクリアする
            AddPlaylistTitle.Value       = string.Empty;
            AddPlaylistDescription.Value = string.Empty;

            // プレイリスト一覧を更新
            await GetPlaylist();
        }
Exemple #4
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));
        }
Exemple #5
0
        /// <summary>
        /// プレイリストを削除する
        /// </summary>
        /// <param name="id">プレイリストのID</param>
        /// <returns></returns>
        public async Task DeletePlaylist(string id)
        {
            // 指定のIDと一致するプレイリストを削除する
            var factory = new YoutubeServiceFactory();
            var service = await factory.Create();

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

            // プレイリスト一覧を更新
            await GetPlaylist();
        }
Exemple #6
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));
        }
        /// <summary>
        /// 動画を検索する
        /// </summary>
        /// <returns></returns>
        public async Task Search(string param)
        {
            // 事前にクリアする
            MainWindowViewModel.SearchResultViewModel.SearchResultList.Clear();

            var factory = new YoutubeServiceFactory();
            var service = await factory.Create();

            var searchListRequest = service.Search.List("snippet");

            searchListRequest.Q          = param;
            searchListRequest.MaxResults = 50;
            var searchListResponse = await searchListRequest.ExecuteAsync();

            foreach (var searchResult in searchListResponse.Items)
            {
                switch (searchResult.Id.Kind)
                {
                case "youtube#video":
                    MainWindowViewModel.SearchResultViewModel.SearchResultList.Add(new SearchResultItemViewModel(searchResult.Id.VideoId, searchResult.Snippet.Title, searchResult.Snippet.Description, searchResult.Snippet.Thumbnails.Default__.Url));
                    break;
                }
            }
        }