protected void deletePlaylist(string playlistUrl) { if (CheckUsernameAndPassword()) { Login(); YouTubeQuery query = new YouTubeQuery() { Uri = new Uri(YouTubeQuery.CreatePlaylistsUri(accountname)), StartIndex = 1, NumberToRetrieve = 50 }; // max. 50 per query YouTubeFeed feed = service.Query(query); foreach (PlaylistsEntry e in feed.Entries) { if (e.Content.Src.Content.Substring(e.Content.Src.Content.IndexOf("://")) == playlistUrl.Substring(playlistUrl.IndexOf("://"))) { e.Delete(); break; } } } }
public GenericListItemCollections GetList(SiteItemEntry entry) { GenericListItemCollections res = new GenericListItemCollections(); res.Title = entry.Title; YouTubeQuery query = new YouTubeQuery(YouTubeQuery.CreatePlaylistsUri(entry.GetValue("id"))); PlaylistsFeed userPlaylists = Youtube2MP.service.GetPlaylists(query); res.Title = userPlaylists.Title.Text; foreach (PlaylistsEntry playlistsEntry in userPlaylists.Entries) { Google.GData.Extensions.XmlExtension e = playlistsEntry.FindExtension("group", "http://search.yahoo.com/mrss/") as Google.GData.Extensions.XmlExtension; string img = "http://i2.ytimg.com/vi/hqdefault.jpg"; try { img = e.Node.FirstChild.Attributes["url"].Value; } catch { } PlayList playList = new PlayList(); SiteItemEntry itemEntry = new SiteItemEntry(); itemEntry.Provider = playList.Name; itemEntry.SetValue("url", playlistsEntry.Content.AbsoluteUri); string title = playlistsEntry.Title.Text; GenericListItem listItem = new GenericListItem() { Title = title, IsFolder = false, LogoUrl = img.Replace("default", "hqdefault"), //DefaultImage = "defaultArtistBig.png", Tag = itemEntry }; res.Add(listItem); } res.ItemType = ItemType.Item; return(res); }
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 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 playlists for a given username /// </summary> /// <param name="user">the username</param> /// <returns>a feed of Videos</returns> public Feed <Playlist> GetPlaylistsFeed(string user) { YouTubeQuery q = PrepareQuery <YouTubeQuery>(YouTubeQuery.CreatePlaylistsUri(user)); return(PrepareFeed <Playlist>(q)); }