Beispiel #1
0
        public override int DiscoverNextPageCategories(NextPageCategory category)
        {
            // remove the NextPageCategory from the list as we are resolving it now
            category.ParentCategory.SubCategories.Remove(category);
            // query Youtube to get the feed results
            var feed = service.Query(new YouTubeQuery(category.Url));

            foreach (var entry in feed.Entries)
            {
                category.ParentCategory.SubCategories.Add(new RssLink()
                {
                    Name                = entry is SubscriptionEntry ? ((SubscriptionEntry)entry).UserName : entry.Title.Text,
                    Url                 = entry is SubscriptionEntry ? YouTubeQuery.CreateUserUri(((SubscriptionEntry)entry).UserName) : entry.Content.Src.Content,
                    ParentCategory      = category.ParentCategory,
                    EstimatedVideoCount = (entry is PlaylistsEntry) ? (uint?)(entry as PlaylistsEntry).CountHint : null
                });
            }
            // if there are more results add a new NextPageCategory
            if (feed.NextChunk != null)
            {
                category.ParentCategory.SubCategories.Add(new NextPageCategory()
                {
                    ParentCategory = category.ParentCategory, Url = feed.NextChunk
                });
            }
            // return the number of categories we discovered
            return(feed.Entries.Count);
        }
        public Video GetVideo(string videoID)
        {
            var query = new YouTubeQuery(YouTubeQuery.CreateUserUri(YouTubeConfiguration.Settings.Gallery.User))
            {
                Query = videoID
            };

            var feed = GetYouTubeFeed(query);

            return(YouTubeDataMapper.MapYouTubeVideo((YouTubeEntry)feed.Entries.First()));
        }
        public PagedList <Video> ListVideos(int page, int pageSize)
        {
            var query = new YouTubeQuery(YouTubeQuery.CreateUserUri(YouTubeConfiguration.Settings.Gallery.User))
            {
                StartIndex       = (page - 1) * pageSize + 1,
                NumberToRetrieve = pageSize
            };

            var feed  = GetYouTubeFeed(query);
            var items = from YouTubeEntry videoEntry in feed.Entries select YouTubeDataMapper.MapYouTubeVideo(videoEntry);

            return(new PagedList <Video>(items, Utils.CalculatePageNumber(feed.StartIndex, feed.ItemsPerPage), feed.ItemsPerPage, Utils.CalculatePageNumber(feed.TotalResults, feed.ItemsPerPage)));
        }
Beispiel #4
0
        public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice)
        {
            ContextMenuExecutionResult result = new ContextMenuExecutionResult();

            try
            {
                if (choice.DisplayText == Translation.Instance.AddToFavourites + " (" + Settings.Name + ")")
                {
                    addFavorite(selectedItem);
                }
                else if (choice.DisplayText == Translation.Instance.RemoveFromFavorites + " (" + Settings.Name + ")")
                {
                    removeFavorite(selectedItem);
                    result.RefreshCurrentItems = true;
                }
                else if (choice.DisplayText == Translation.Instance.RelatedVideos)
                {
                    YouTubeQuery query = new YouTubeQuery()
                    {
                        Uri = new Uri((selectedItem.Other as MyYouTubeEntry).YouTubeEntry.RelatedVideosUri.Content), NumberToRetrieve = pageSize
                    };
                    result.ResultItems = parseGData(query).ConvertAll <SearchResultItem>(v => v as SearchResultItem);
                    currentVideosTitle = Translation.Instance.RelatedVideos + " [" + selectedItem.Title + "]";
                }
                else if (choice.DisplayText.StartsWith(Translation.Instance.UploadsBy))
                {
                    string       username = selectedItem == null ? selectedCategory.Name : (selectedItem.Other as MyYouTubeEntry).YouTubeEntry.Uploader.Value;
                    YouTubeQuery query    = new YouTubeQuery(YouTubeQuery.CreateUserUri(username))
                    {
                        NumberToRetrieve = pageSize
                    };
                    result.ResultItems = parseGData(query).ConvertAll <SearchResultItem>(v => v as SearchResultItem);
                    currentVideosTitle = Translation.Instance.UploadsBy + " [" + username + "]";
                }
                else if (choice.DisplayText.StartsWith(Translation.Instance.Playlists))
                {
                    string       username = selectedItem == null ? selectedCategory.Name : (selectedItem.Other as MyYouTubeEntry).YouTubeEntry.Uploader.Value;
                    YouTubeQuery query    = new YouTubeQuery(YouTubeQuery.CreatePlaylistsUri(username))
                    {
                        NumberToRetrieve = pageSize
                    };
                    YouTubeFeed feed           = service.Query(query);
                    Category    parentCategory = new Category()
                    {
                        SubCategories = new List <Category>()
                    };
                    GetPlaylistEntriesAsCategories(parentCategory, feed);
                    result.ResultItems = parentCategory.SubCategories.ConvertAll <SearchResultItem>(v => v as SearchResultItem);
                }
                else if (choice.DisplayText == Translation.Instance.AddComment)
                {
                    addComment(selectedItem, choice.UserInputText);
                }
                else if (choice.ParentEntry != null && choice.ParentEntry.DisplayText == Translation.Instance.RateVideo)
                {
                    rateVideo(selectedItem, byte.Parse(choice.DisplayText));
                }
                else if (choice.ParentEntry != null && choice.ParentEntry.DisplayText == Translation.Instance.AddToPlaylist)
                {
                    if (choice.Other == null)
                    {
                        choice.Other = request.Insert <Playlist>(new Uri(YouTubeQuery.CreatePlaylistsUri(accountname)), new Playlist()
                        {
                            Title = choice.UserInputText
                        }).PlaylistsEntry.Content.Src.Content;
                    }
                    addToPlaylist(selectedItem, choice.Other as string);
                    // force re-discovery of dynamic subcategories for my playlists category (as either a new catgeory was added or the count changed)
                    var playlistsCategory = Settings.Categories.FirstOrDefault(c => !(c is RssLink) && c.Name == string.Format("{0}'s {1}", accountname, Translation.Instance.Playlists));
                    if (playlistsCategory != null)
                    {
                        playlistsCategory.SubCategoriesDiscovered = false;
                    }
                }
                else if (choice.DisplayText == Translation.Instance.RemoveFromPlaylist)
                {
                    removeFromPlaylist(selectedItem, choice.Other as string);
                    result.RefreshCurrentItems = true;
                    if ((selectedCategory as RssLink).EstimatedVideoCount != null)
                    {
                        (selectedCategory as RssLink).EstimatedVideoCount--;
                    }
                }
                else if (choice.DisplayText == Translation.Instance.DeletePlaylist)
                {
                    deletePlaylist((selectedCategory as RssLink).Url);
                    selectedCategory.ParentCategory.SubCategoriesDiscovered = false;
                    result.RefreshCurrentItems = true;
                }
            }
            catch (Exception ex)
            {
                throw new OnlineVideosException(ex.Message);
            }
            return(result);
        }
Beispiel #5
0
        public override int DiscoverSubCategories(Category parentCategory)
        {
            parentCategory.SubCategories = new List <Category>();
            if (parentCategory is RssLink)
            {
                YouTubeQuery ytq = new YouTubeQuery((parentCategory as RssLink).Url)
                {
                    NumberToRetrieve = pageSize
                };
                YouTubeFeed feed = service.Query(ytq);
                GetPlaylistEntriesAsCategories(parentCategory, feed);
            }
            else
            {
                Login();

                if (parentCategory.Name.EndsWith(Translation.Instance.Playlists))
                {
                    // authenticated user's playlists
                    YouTubeQuery query = new YouTubeQuery()
                    {
                        Uri = new Uri(YouTubeQuery.CreatePlaylistsUri(accountname)), StartIndex = 1, NumberToRetrieve = pageSize
                    };
                    YouTubeFeed feed = null;
                    try
                    {
                        feed = service.Query(query);
                    }
                    catch (Google.GData.Client.GDataRequestException queryEx)
                    {
                        HandleGDataErrorMessage(queryEx);
                    }
                    GetPlaylistEntriesAsCategories(parentCategory, feed);
                }
                else
                {
                    // authenticated user's subscriptions
                    RssLink newVidsLink = new RssLink();
                    newVidsLink.Name = Translation.Instance.NewVideos;
                    newVidsLink.Url  = USER_NEWSUBSCRIPTIONS_FEED;
                    parentCategory.SubCategories.Add(newVidsLink);
                    newVidsLink.ParentCategory = parentCategory;

                    YouTubeQuery query = new YouTubeQuery()
                    {
                        Uri = new Uri(YouTubeQuery.CreateSubscriptionUri(accountname)), StartIndex = 1, NumberToRetrieve = pageSize
                    };
                    YouTubeFeed feed = null;
                    try
                    {
                        feed = service.Query(query);
                    }
                    catch (Google.GData.Client.GDataRequestException queryEx)
                    {
                        HandleGDataErrorMessage(queryEx);
                    }
                    foreach (SubscriptionEntry subScr in feed.Entries)
                    {
                        RssLink subScrLink = new RssLink();
                        subScrLink.Name = subScr.UserName;
                        subScrLink.Url  = YouTubeQuery.CreateUserUri(subScr.UserName);
                        parentCategory.SubCategories.Add(subScrLink);
                        subScrLink.ParentCategory = parentCategory;
                    }
                    // if there are more results add a new NextPageCategory
                    if (feed.NextChunk != null)
                    {
                        parentCategory.SubCategories.Add(new NextPageCategory()
                        {
                            ParentCategory = parentCategory, Url = feed.NextChunk
                        });
                    }
                }
            }
            parentCategory.SubCategoriesDiscovered = true;
            return(parentCategory.SubCategories.Count);
        }
        /// <summary>
        /// returns a Feed of vidoes for a given username
        /// </summary>
        /// <param name="user">the username</param>
        /// <returns>a feed of Videos</returns>
        public Feed <Video> GetVideoFeed(string user)
        {
            YouTubeQuery q = PrepareQuery <YouTubeQuery>(YouTubeQuery.CreateUserUri(user));

            return(PrepareFeed <Video>(q));
        }