Ejemplo n.º 1
0
        private void addChannel(YoutubeChannelItem channelItem)
        {
            YoutubeChannelNodeState state = new YoutubeChannelNodeState(channelItem);
            YoutubeChannelNode node = new YoutubeChannelNode(state);

            lock (channelLock)
            {
                Children.Add(node);                
                Properties.Settings.Default.YoutubeChannels.Add(state);
            }  
           
        }
        public YoutubeChannelNodeState(YoutubeChannelItem item)
        {
            Info = item.Info as SearchResult;
      
            if (item.Metadata != null)
            {
                ThumbString = System.Convert.ToBase64String(item.Metadata.Thumbnail.ImageData);
            }
            else
            {
                ThumbString = null;
            }

            ChannelsResource.ListRequest listRequest = new ChannelsResource.ListRequest(YoutubeViewModel.Youtube, "statistics");

            listRequest.Id = item.ChannelId;

            ChannelListResponse response = listRequest.Execute();

            if (response.Items.Count > 0)
            {
                Statistics = response.Items[0].Statistics;
            }
        }
Ejemplo n.º 3
0
        private async Task search(IClientServiceRequest request, String searchInfo, bool isNextPage, CancellationToken token)
        {
            SearchListResponse searchResponse = null;
            PlaylistItemListResponse playlistItemResponse = null;
            PlaylistListResponse playlistResponse = null;

            SearchResource.ListRequest searchRequest = request as SearchResource.ListRequest;
            PlaylistItemsResource.ListRequest playlistItemsRequest = request as PlaylistItemsResource.ListRequest;
            PlaylistsResource.ListRequest playlistRequest = request as PlaylistsResource.ListRequest;

            List<YoutubeItem> items = new List<YoutubeItem>();  
            int relevance;

            if (isNextPage)
            {
                if (NextPageToken == null)
                {
                    // Final page
                    return;
                }

                if (searchRequest != null)
                {
                    searchRequest.PageToken = NextPageToken;
                }
                else if (playlistItemsRequest != null) 
                {
                    playlistItemsRequest.PageToken = NextPageToken;
                }
                else if (playlistRequest != null)
                {
                    playlistRequest.PageToken = NextPageToken;
                }

                relevance = MediaState.UIMediaCollection.Count;
            }
            else
            {
                MediaState.clearUIState(searchInfo, DateTime.Now, MediaStateType.SearchResult);

                CurrentQuery = request;
                relevance = 0;
            }                       
          
            // Call the search.list method to retrieve results matching the specified query term.
            if (searchRequest != null)
            {
                searchResponse = await searchRequest.ExecuteAsync(token);

                NextPageToken = searchResponse.NextPageToken;
                
                foreach (SearchResult searchResult in searchResponse.Items)
                {
                    YoutubeItem newItem = null;

                    switch (searchResult.Id.Kind)
                    {
                        case "youtube#video":
                            newItem = new YoutubeVideoItem(searchResult, relevance);
                            break;

                        case "youtube#channel":
                            newItem = new YoutubeChannelItem(searchResult, relevance);
                            break;

                        case "youtube#playlist":
                            newItem = new YoutubePlaylistItem(searchResult, relevance);
                            break;
                        default:
                            break;
                    }

                    if (newItem == null || MediaState.UIMediaCollection.Contains(newItem)) continue;

                    items.Add(newItem);

                    relevance++;
                }
               
            }

            if (playlistItemsRequest != null)
            {
                playlistItemResponse = await playlistItemsRequest.ExecuteAsync(token);
                NextPageToken = playlistItemResponse.NextPageToken;

                foreach (PlaylistItem playlistItem in playlistItemResponse.Items)
                {
                    YoutubeVideoItem newItem = new YoutubeVideoItem(playlistItem, relevance);

                    items.Add(newItem);

                    relevance++;
                }
            }

            if (playlistRequest != null)
            {
                playlistResponse = await playlistRequest.ExecuteAsync(token);
                NextPageToken = playlistResponse.NextPageToken;

                foreach (Playlist playlist in playlistResponse.Items)
                {
                    YoutubePlaylistItem newItem = new YoutubePlaylistItem(playlist, relevance);

                    if (!items.Contains(newItem))
                    {
                        items.Add(newItem);
                    }

                    relevance++;
                }

            }
                                              
            // Add each result to the appropriate list, and then display the lists of
            // matching videos, channels, and playlists.                        
            MediaState.addUIState(items);
        }