public void YouTubeSubscriptionsTest() { Tracing.TraceMsg("Entering YouTubeSubscriptionsTest"); string playlistID = "4A3A73D5172EB90A"; YouTubeRequestSettings settings = new YouTubeRequestSettings(this.ApplicationName, this.ytDevKey, this.ytUser, this.ytPwd); // settings.PageSize = 15; YouTubeRequest f = new YouTubeRequest(settings); // this returns the server default answer Feed <Subscription> feed = f.GetSubscriptionsFeed(null); foreach (Subscription s in feed.Entries) { Assert.IsTrue(s.PlaylistId != null, "There should be a PlaylistId"); Assert.IsTrue(s.PlaylistTitle != null, "There should be a PlaylistTitle"); if (s.PlaylistId == playlistID) { f.Delete(s); } } Subscription sub = new Subscription(); sub.Type = SubscriptionEntry.SubscriptionType.playlist; sub.PlaylistId = playlistID; f.Insert(feed, sub); // this returns the server default answer feed = f.GetSubscriptionsFeed(null); List <Subscription> list = new List <Subscription>(); foreach (Subscription s in feed.Entries) { Assert.IsTrue(s.PlaylistId != null, "There should be a PlaylistId"); Assert.IsTrue(s.PlaylistTitle != null, "There should be a PlaylistTitle"); if (s.PlaylistId == playlistID) { list.Add(s); } } Assert.IsTrue(list.Count > 0, "There should be one subscription matching"); foreach (Subscription s in list) { f.Delete(s); } foreach (Subscription s in feed.Entries) { Assert.IsTrue(s.PlaylistId != null, "There should be a PlaylistId"); Assert.IsTrue(s.PlaylistTitle != null, "There should be a PlaylistTitle"); Assert.IsFalse(s.PlaylistId == playlistID, "They should be gone"); } }
public void YouTubeSubscriptionsTest() { Tracing.TraceMsg("Entering YouTubeSubscriptionsTest"); string channelUsername = "******"; YouTubeRequestSettings settings = new YouTubeRequestSettings(this.ApplicationName, this.ytDevKey, this.ytUser, this.ytPwd); YouTubeRequest f = new YouTubeRequest(settings); // this returns the server default answer Feed <Subscription> feed = f.GetSubscriptionsFeed(null); foreach (Subscription s in feed.Entries) { if (!string.IsNullOrEmpty(s.UserName) && s.UserName == channelUsername) { f.Delete(s); } } Subscription sub = new Subscription(); sub.Type = SubscriptionEntry.SubscriptionType.channel; sub.UserName = "******"; f.Insert(feed, sub); // this returns the server default answer feed = f.GetSubscriptionsFeed(null); List <Subscription> list = new List <Subscription>(); foreach (Subscription s in feed.Entries) { if (!string.IsNullOrEmpty(s.UserName) && s.UserName == channelUsername) { list.Add(s); } } Assert.IsTrue(list.Count > 0, "There should be one subscription matching"); foreach (Subscription s in list) { f.Delete(s); } feed = f.GetSubscriptionsFeed(null); int iCount = 0; foreach (Subscription s in feed.Entries) { iCount++; } Assert.IsTrue(iCount == 0, "There should be no subscriptions in the feed"); }
public void CreatePlaylist() { Playlist playlistBlueprint = new Playlist(); playlistBlueprint.Title = _playlistName; playlistBlueprint.Summary = _playlistSummary; Playlist playlist; try { playlist = _request.Insert(new Uri("http://gdata.youtube.com/feeds/api/users/default/playlists"), playlistBlueprint); } catch (InvalidCredentialsException) { throw new InvalidLoginInfoException(); } foreach (var query in _queryList) { YouTubeQuery ytQuery = new YouTubeQuery(YouTubeQuery.DefaultVideoUri); //ytQuery.OrderBy = "viewCount"; ytQuery.Query = query; ytQuery.SafeSearch = YouTubeQuery.SafeSearchValues.None; Feed <Video> results = _request.Get <Video>(ytQuery); Video firstVideo = results.Entries.ToList()[0]; PlayListMember playlistMember = new PlayListMember(); playlistMember.VideoId = firstVideo.VideoId; _request.AddToPlaylist(playlist, playlistMember); } int idIndex = playlist.Id.IndexOf("playlist:"); string id = playlist.Id.Substring(idIndex + "playlist:".Length); PlaylistUrl = "https://www.youtube.com/playlist?list=" + id; }
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); }
public void YouTubeSubscriptionsTest() { Tracing.TraceMsg("Entering YouTubeSubscriptionsTest"); string playlistID = "4A3A73D5172EB90A"; YouTubeRequestSettings settings = new YouTubeRequestSettings(this.ApplicationName, this.ytClient, this.ytDevKey, this.ytUser, this.ytPwd); // settings.PageSize = 15; YouTubeRequest f = new YouTubeRequest(settings); // this returns the server default answer Feed<Subscription> feed = f.GetSubscriptionsFeed(null); foreach (Subscription s in feed.Entries) { Assert.IsTrue(s.PlaylistId != null, "There should be a PlaylistId"); Assert.IsTrue(s.PlaylistTitle != null, "There should be a PlaylistTitle"); if (s.PlaylistId == playlistID) { f.Delete(s); } } Subscription sub = new Subscription(); sub.Type = SubscriptionEntry.SubscriptionType.playlist; sub.PlaylistId = playlistID; f.Insert(feed, sub); // this returns the server default answer feed = f.GetSubscriptionsFeed(null); List<Subscription> list = new List<Subscription>(); foreach (Subscription s in feed.Entries) { Assert.IsTrue(s.PlaylistId != null, "There should be a PlaylistId"); Assert.IsTrue(s.PlaylistTitle != null, "There should be a PlaylistTitle"); if (s.PlaylistId == playlistID) { list.Add(s); } } Assert.IsTrue(list.Count > 0, "There should be one subscription matching"); foreach (Subscription s in list) { f.Delete(s); } foreach (Subscription s in feed.Entries) { Assert.IsTrue(s.PlaylistId != null, "There should be a PlaylistId"); Assert.IsTrue(s.PlaylistTitle != null, "There should be a PlaylistTitle"); Assert.IsFalse(s.PlaylistId == playlistID, "They should be gone"); } }
public void YouTubeSubscriptionsTest() { Tracing.TraceMsg("Entering YouTubeSubscriptionsTest"); string channelUsername = "******"; YouTubeRequestSettings settings = new YouTubeRequestSettings(this.ApplicationName, this.ytDevKey, this.ytUser, this.ytPwd); YouTubeRequest f = new YouTubeRequest(settings); // this returns the server default answer Feed<Subscription> feed = f.GetSubscriptionsFeed(null); foreach (Subscription s in feed.Entries) { if (!string.IsNullOrEmpty(s.UserName) && s.UserName == channelUsername) { f.Delete(s); } } Subscription sub = new Subscription(); sub.Type = SubscriptionEntry.SubscriptionType.channel; sub.UserName = "******"; f.Insert(feed, sub); // this returns the server default answer feed = f.GetSubscriptionsFeed(null); List<Subscription> list = new List<Subscription>(); foreach (Subscription s in feed.Entries) { if (!string.IsNullOrEmpty(s.UserName) && s.UserName == channelUsername) { list.Add(s); } } Assert.IsTrue(list.Count > 0, "There should be one subscription matching"); foreach (Subscription s in list) { f.Delete(s); } feed = f.GetSubscriptionsFeed(null); int iCount = 0; foreach (Subscription s in feed.Entries) { iCount++; } Assert.IsTrue(iCount == 0, "There should be no subscriptions in the feed"); }