public override List <ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem) { List <ContextMenuEntry> entries = new List <ContextMenuEntry>(); if (selectedItem != null && ManuallyRetrieveSubtitles) { string data = GetWebData(selectedItem.VideoUrl); Regex rgx = new Regex(@"urPlayer.init\((.*)\);", RegexOptions.Multiline); Match m = rgx.Match(data); if (m != null) { var json = JObject.Parse(m.Groups[1].Value); JArray subtitles = (JArray)json["subtitles"]; if (subtitles != null && subtitles.Count() > 0) { ContextMenuEntry textningssprak = new ContextMenuEntry(); textningssprak.Action = ContextMenuEntry.UIAction.ShowList; textningssprak.DisplayText = _textningssprak; textningssprak.Other = json.ToString(); ContextMenuEntry entry = new ContextMenuEntry(); entry.DisplayText = string.Format(_ingenTextning); textningssprak.SubEntries.Add(entry); foreach (JToken subtitle in subtitles.Where(s => s["label"] != null)) { entry = new ContextMenuEntry(); entry.DisplayText = subtitle["label"].Value <string>(); textningssprak.SubEntries.Add(entry); } entries.Add(textningssprak); } } } return(entries); }
public override List <ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem) { List <ContextMenuEntry> entries = new List <ContextMenuEntry>(); if (selectedItem != null && EnableAOSearch && selectedItem.Other is SerializableDictionary <string, string> ) { var other = selectedItem.Other as SerializableDictionary <string, string>; ContextMenuEntry amnesord = new ContextMenuEntry(); amnesord.Action = ContextMenuEntry.UIAction.ShowList; amnesord.DisplayText = _amnesord; foreach (var ao in other) { ContextMenuEntry entry = new ContextMenuEntry(); entry.DisplayText = ao.Key; entry.Other = ao.Value; amnesord.SubEntries.Add(entry); } if (amnesord.SubEntries.Count > 0) { entries.Add(amnesord); } } if (selectedItem != null && ManuallyRetrieveSubtitles) { string data = GetWebData(selectedItem.VideoUrl); Regex rgx = new Regex(@"^urPlayer.init\((.*)\);", RegexOptions.Multiline); Match m = rgx.Match(data); if (m != null) { var json = JObject.Parse(m.Groups[1].Value); JArray subtitles = (JArray)json["subtitles"]; if (subtitles != null && subtitles.Count() > 0) { ContextMenuEntry textningssprak = new ContextMenuEntry(); textningssprak.Action = ContextMenuEntry.UIAction.ShowList; textningssprak.DisplayText = _textningssprak; textningssprak.Other = json.ToString(); ContextMenuEntry entry = new ContextMenuEntry(); entry.DisplayText = string.Format(_ingenTextning); textningssprak.SubEntries.Add(entry); foreach (JToken subtitle in subtitles) { entry = new ContextMenuEntry(); entry.DisplayText = string.Format(subtitle["label"].Value <string>()); textningssprak.SubEntries.Add(entry); } entries.Add(textningssprak); } } } return(entries); }
public override List <ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem) { List <ContextMenuEntry> entries = new List <ContextMenuEntry>(); if (selectedItem != null) { ContextMenuEntry entry = new ContextMenuEntry(); string other = selectedItem.GetOtherAsString(); JObject json = (JObject)JsonConvert.DeserializeObject(other); bool isSaved = json["saved"].Value <bool>(); entry.DisplayText = isSaved ? "Remove from watchlist" : "Add to watchlist"; entries.Add(entry); } return(entries); }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { HasNextPage = false; currentVideosTitle = "Mehr zum Thema [" + choice.DisplayText + "]"; var result = new List<VideoInfo>(); string data = GetWebData(choice.Other as string); var html = new HtmlDocument(); html.LoadHtml(data); var section = html.DocumentNode.Descendants("section").FirstOrDefault(s => s.GetAttributeValue("id", "") == "content"); GetLatestVideos(ref result, section.Descendants("ul").First()); var nextPageA = html.DocumentNode.Descendants("a").FirstOrDefault(a => a.InnerText == "nächste"); if (nextPageA != null) { HasNextPage = true; nextPageUrl = "http://www.heise.de" + nextPageA.GetAttributeValue("href", ""); } return new ContextMenuExecutionResult() { ResultItems = result.ConvertAll<SearchResultItem>(v => (SearchResultItem)v) }; }
public override List <ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem) { var result = new List <ContextMenuEntry>(); if (selectedItem != null && selectedItem.Other is SerializableDictionary <string, string> ) { ContextMenuEntry mehrZumThema = new ContextMenuEntry() { DisplayText = "Mehr zum Thema ...", Action = ContextMenuEntry.UIAction.ShowList }; foreach (var item in (selectedItem.Other as SerializableDictionary <string, string>)) { mehrZumThema.SubEntries.Add(new ContextMenuEntry() { DisplayText = item.Key, Action = ContextMenuEntry.UIAction.Execute, Other = item.Value }); } result.Add(mehrZumThema); } return(result); }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); if (choice.DisplayText == GetTranslation("Unstar", "Unstar")) { JToken data = MyGetWebData((selectedItem.Other as SerializableDictionary<string, string>)["starUrl"] + "false"); result.RefreshCurrentItems = true; if (data["success"] != null && (bool)data["success"]) result.ExecutionResultMessage = GetTranslation("Unstar", "Unstar") + ": OK"; else result.ExecutionResultMessage = GetTranslation("Unstar", "Unstar") + ": Error"; return result; } if (choice.DisplayText == GetTranslation("Star", "Star")) { JToken data = MyGetWebData((selectedItem.Other as SerializableDictionary<string, string>)["starUrl"] + "true"); result.ExecutionResultMessage = GetTranslation("Star", "Star"); if (data["success"] != null && (bool)data["success"]) { result.RefreshCurrentItems = true; result.ExecutionResultMessage += ": OK"; } else result.ExecutionResultMessage += ": Error"; return result; } if (choice.DisplayText == selectedCategory.Name + ": " + GetTranslation("Remove from History", "Remove from History")) { JObject json = MyGetWebData(ApiUrl); string userId = json["user"]["userId"].Value<string>(); json = MyGetWebData((selectedItem.Other as SerializableDictionary<string, string>)["watchedUrl"].Replace("{userId}",userId), string.Empty); result.ExecutionResultMessage = GetTranslation("Remove from History", "Remove from History"); if (json["status"] != null && json["status"].Value<string>() == "ok") { result.RefreshCurrentItems = true; result.ExecutionResultMessage += ": OK"; } else result.ExecutionResultMessage += ": Error"; return result; } //People search if (choice.DisplayText != null && choice.DisplayText is string && (string)choice.DisplayText == GetTranslation("Cast", "Cast")) { List<SearchResultItem> results = new List<SearchResultItem>(); foreach (string actor in (selectedItem.Other as SerializableDictionary<string, string>)["actors"].Split(';')) { results.Add(new RssLink() { Name = actor, Url = ApiUrl + "/search?query=" + HttpUtility.UrlEncode("\"" + actor + "\"") + "&block=1&partial=1&pageNumber=1", Other = _search, ParentCategory = selectedCategory, HasSubCategories = true, SubCategories = new List<Category>() }); } result.ResultItems = results; return result; } if (choice.DisplayText != null && choice.DisplayText is string && (string)choice.DisplayText == GetTranslation("Director", "Director")) { List<SearchResultItem> results = new List<SearchResultItem>(); foreach (string director in (selectedItem.Other as SerializableDictionary<string, string>)["directors"].Split(';')) { results.Add(new RssLink() { Name = director, Url = ApiUrl + "/search?query=" + HttpUtility.UrlEncode("\"" + director + "\"") + "&block=1&partial=1&pageNumber=1", Other = _search, ParentCategory = selectedCategory, HasSubCategories = true, SubCategories = new List<Category>() }); } result.ResultItems = results; return result; } return base.ExecuteContextMenuEntry(selectedCategory, selectedItem, choice); }
public override List <ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem) { List <ContextMenuEntry> result = new List <ContextMenuEntry>(); if (selectedItem != null) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.RelatedVideos, Action = ContextMenuEntry.UIAction.Execute }); MyYouTubeEntry ytEntry = selectedItem.Other as MyYouTubeEntry; if (ytEntry != null && ytEntry.YouTubeEntry != null) { if (ytEntry.YouTubeEntry.Uploader != null && !string.IsNullOrEmpty(ytEntry.YouTubeEntry.Uploader.Value)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.UploadsBy + " [" + ytEntry.YouTubeEntry.Uploader.Value + "]", Action = ContextMenuEntry.UIAction.Execute }); result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.Playlists + " [" + ytEntry.YouTubeEntry.Uploader.Value + "]", Action = ContextMenuEntry.UIAction.Execute }); } if (selectedCategory != null && selectedCategory.Other as string == "Login" && selectedCategory.Name == string.Format("{0}'s {1}", accountname, Translation.Instance.Favourites)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.RemoveFromFavorites + " (" + Settings.Name + ")", Action = ContextMenuEntry.UIAction.Execute }); } else if (!string.IsNullOrEmpty(accountname) && !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(accountname)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.AddToFavourites + " (" + Settings.Name + ")", Action = ContextMenuEntry.UIAction.Execute }); } if (!string.IsNullOrEmpty(accountname) && !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(accountname)) { // comment result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.AddComment, Action = ContextMenuEntry.UIAction.GetText }); // rate (YouTube uses a 1-5 rating system in which 1 is the lowest rating that can be given) var rCtx = new ContextMenuEntry() { DisplayText = Translation.Instance.RateVideo, Action = ContextMenuEntry.UIAction.ShowList }; for (int i = 1; i <= 5; i++) { rCtx.SubEntries.Add(new ContextMenuEntry() { DisplayText = i.ToString() }); } result.Add(rCtx); // add to playlist var plCtx = new ContextMenuEntry() { DisplayText = Translation.Instance.AddToPlaylist, Action = ContextMenuEntry.UIAction.ShowList }; plCtx.SubEntries.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.CreateNewPlaylist, Action = ContextMenuEntry.UIAction.GetText }); foreach (var pl in request.GetPlaylistsFeed(accountname).Entries) { plCtx.SubEntries.Add(new ContextMenuEntry() { DisplayText = pl.Title, Other = pl.PlaylistsEntry.Content.Src.Content }); } result.Add(plCtx); if (selectedCategory != null && selectedCategory.ParentCategory != null && !(selectedCategory.ParentCategory is RssLink) && selectedCategory.ParentCategory.Name == string.Format("{0}'s {1}", accountname, Translation.Instance.Playlists)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.RemoveFromPlaylist, Other = (selectedCategory as RssLink).Url }); } } } } else { if (selectedCategory != null && selectedCategory.ParentCategory != null && !(selectedCategory.ParentCategory is RssLink) && selectedCategory.ParentCategory.Name == string.Format("{0}'s {1}", accountname, Translation.Instance.Playlists)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.DeletePlaylist, Other = (selectedCategory as RssLink).Url }); } else if (selectedCategory != null && selectedCategory.ParentCategory != null && !(selectedCategory.ParentCategory is RssLink) && selectedCategory.ParentCategory.Name == string.Format("{0}'s {1}", accountname, Translation.Instance.Subscriptions)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.UploadsBy + " [" + selectedCategory.Name + "]", Action = ContextMenuEntry.UIAction.Execute }); result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.Playlists + " [" + selectedCategory.Name + "]", Action = ContextMenuEntry.UIAction.Execute }); } } return(result); }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); try { if (choice.DisplayText == Translation.Instance.AddToFavourites + " (" + Settings.Name + ")") { var query = Service.PlaylistItems.Insert( new Google.Apis.YouTube.v3.Data.PlaylistItem() { Snippet = new Google.Apis.YouTube.v3.Data.PlaylistItemSnippet() { Title = selectedItem.Title, PlaylistId = userFavoritesPlaylistId, ResourceId = new Google.Apis.YouTube.v3.Data.ResourceId() { VideoId = selectedItem.VideoUrl, Kind = "youtube#video" } } }, "snippet"); var response = query.Execute(); result.ExecutionResultMessage = string.Format("{0} {1}", Translation.Instance.Success, Translation.Instance.AddingToFavorites); } else if (choice.DisplayText == Translation.Instance.RemoveFromFavorites + " (" + Settings.Name + ")") { var query = Service.PlaylistItems.Delete((selectedItem as YouTubeVideo).PlaylistItemId); var response = query.Execute(); result.RefreshCurrentItems = true; } else if (choice.DisplayText == Translation.Instance.RelatedVideos) { base.HasNextPage = false; nextPageVideosQuery = null; currentVideosTitle = Translation.Instance.RelatedVideos + " [" + selectedItem.Title + "]"; result.ResultItems = QuerySearchVideos(null, "videos", null, null, (selectedItem as YouTubeVideo).VideoUrl).ConvertAll <SearchResultItem>(v => v as SearchResultItem); } else if (choice.DisplayText.StartsWith(Translation.Instance.UploadsBy)) { base.HasNextPage = false; nextPageVideosQuery = null; currentVideosTitle = Translation.Instance.UploadsBy + " [" + (selectedItem as YouTubeVideo).ChannelTitle + "]"; result.ResultItems = QuerySearchVideos(null, "videos", (selectedItem as YouTubeVideo).ChannelId, null, null).ConvertAll <SearchResultItem>(v => v as SearchResultItem); } else if (choice.DisplayText.StartsWith(Translation.Instance.Playlists)) { var parentCategory = new YouTubeCategory() { Name = Translation.Instance.Playlists + " [" + (selectedItem as YouTubeVideo).ChannelTitle + "]" }; parentCategory.SubCategories = QueryChannelPlaylists(parentCategory, (selectedItem as YouTubeVideo).ChannelId); result.ResultItems = parentCategory.SubCategories.ConvertAll <SearchResultItem>(v => v as SearchResultItem); } else if (choice.DisplayText == Translation.Instance.RemoveFromPlaylist) { var query = Service.PlaylistItems.Delete((selectedItem as YouTubeVideo).PlaylistItemId); var response = query.Execute(); result.RefreshCurrentItems = true; if ((selectedCategory as YouTubeCategory).EstimatedVideoCount != null) { (selectedCategory as YouTubeCategory).EstimatedVideoCount--; } } else if (choice.DisplayText == Translation.Instance.DeletePlaylist) { var query = Service.Playlists.Delete((selectedCategory as YouTubeCategory).Id); var response = query.Execute(); selectedCategory.ParentCategory.SubCategoriesDiscovered = false; result.RefreshCurrentItems = true; } else if (choice.ParentEntry != null && choice.ParentEntry.DisplayText == Translation.Instance.AddToPlaylist) { if (choice.Other == null) { // create new playlist first var query = Service.Playlists.Insert( new Google.Apis.YouTube.v3.Data.Playlist() { Snippet = new Google.Apis.YouTube.v3.Data.PlaylistSnippet() { Title = choice.UserInputText } }, "snippet"); var response = query.Execute(); choice.Other = response.Id; } var queryItem = Service.PlaylistItems.Insert( new Google.Apis.YouTube.v3.Data.PlaylistItem() { Snippet = new Google.Apis.YouTube.v3.Data.PlaylistItemSnippet() { Title = selectedItem.Title, PlaylistId = choice.Other as string, ResourceId = new Google.Apis.YouTube.v3.Data.ResourceId() { VideoId = selectedItem.VideoUrl, Kind = "youtube#video" } } }, "snippet"); var responseItem = queryItem.Execute(); // 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 YouTubeCategory) && (c as YouTubeCategory).IsMine && c.Name.EndsWith(Translation.Instance.Playlists)); if (playlistsCategory != null) { playlistsCategory.SubCategoriesDiscovered = false; } } } catch (Google.GoogleApiException apiEx) { throw new OnlineVideosException(string.Format("{0} {1}", apiEx.HttpStatusCode, apiEx.Message)); } catch (Exception ex) { throw new OnlineVideosException(ex.Message); } return(result); }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, OnlineVideos.VideoInfo selectedItem, ContextMenuEntry choice) { if (choice != null && choice.DisplayText.StartsWith("Mehr ")) { currentVideoTitle = choice.DisplayText; return new ContextMenuExecutionResult() { ResultItems = GetVideosFromApiUrl(GetApiUrl("myvideo.videos.list_by_user", new NameValueCollection() { { "user", choice.Other as string } })) .ConvertAll<SearchResultItem>(v => v as SearchResultItem) }; } return null; }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { if (selectedItem != null && ManuallyRetrieveSubtitles && choice.ParentEntry != null && choice.ParentEntry.DisplayText == _textningssprak && choice.ParentEntry.Other is string) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); if (choice.DisplayText == _ingenTextning) selectedItem.SubtitleText = ""; else selectedItem.SubtitleText = GetSubtitle(JObject.Parse(choice.ParentEntry.Other as string), choice.DisplayText); result.ExecutionResultMessage = selectedItem.Title + " - " + (string.IsNullOrEmpty(selectedItem.SubtitleText) && choice.DisplayText != _ingenTextning ? "Fel vid hämtning av textning!" : _textningssprak + ": " + choice.DisplayText); result.RefreshCurrentItems = false; return result; } else return base.ExecuteContextMenuEntry(selectedCategory, selectedItem, choice); }
public override List<ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem) { List<ContextMenuEntry> entries = new List<ContextMenuEntry>(); if (selectedItem != null) { ContextMenuEntry entry = new ContextMenuEntry(); string other = selectedItem.GetOtherAsString(); JObject json = (JObject)JsonConvert.DeserializeObject(other); bool isSaved = json["saved"].Value<bool>(); entry.DisplayText = isSaved ? "Remove from watchlist" : "Add to watchlist"; entries.Add(entry); } return entries; }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); if (choice.DisplayText == Translation.Instance.DeleteAll) { result.RefreshCurrentItems = OnlineVideoSettings.Instance.FavDB.RemoveAllFavoriteVideos(((RssLink)selectedCategory).Url); // we have to manually refresh the categories if (result.RefreshCurrentItems && selectedCategory.ParentCategory != null) { DiscoverDynamicCategories(); } } else if (choice.DisplayText == Translation.Instance.RemoveFromFavorites) { if (selectedCategory is FavoriteCategory) { result.RefreshCurrentItems = OnlineVideoSettings.Instance.FavDB.RemoveFavoriteCategory(((FavoriteCategory)selectedCategory).FavoriteDbCategory); if (result.RefreshCurrentItems) { selectedCategory.ParentCategory.SubCategories.Remove(selectedCategory); } return(result); } else { result.RefreshCurrentItems = OnlineVideoSettings.Instance.FavDB.RemoveFavoriteVideo(selectedItem as FavoriteDbVideoInfo); } // we have to manually refresh the categories if (result.RefreshCurrentItems && selectedCategory.ParentCategory != null) { DiscoverDynamicCategories(); } } return(result); }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { if (selectedItem != null && ManuallyRetrieveSubtitles && choice.ParentEntry != null && choice.ParentEntry.DisplayText == _textningssprak && choice.ParentEntry.Other is string) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); if (choice.DisplayText == _ingenTextning) { selectedItem.SubtitleText = ""; } else { selectedItem.SubtitleText = GetSubtitle(JObject.Parse(choice.ParentEntry.Other as string), choice.DisplayText); } result.ExecutionResultMessage = selectedItem.Title + " - " + (string.IsNullOrEmpty(selectedItem.SubtitleText) && choice.DisplayText != _ingenTextning ? "Fel vid hämtning av textning!" : _textningssprak + ": " + choice.DisplayText); result.RefreshCurrentItems = false; return(result); } else if (selectedItem != null && EnableAOSearch && choice.ParentEntry != null && choice.ParentEntry.DisplayText == _amnesord && choice.Other is string) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); RssLink cat = new RssLink() { Name = choice.DisplayText, Url = choice.Other as string }; List <SearchResultItem> results = new List <SearchResultItem>(); foreach (VideoInfo vi in GetVideos(cat)) { results.Add(vi); } result.ResultItems = results; return(result); } else { return(base.ExecuteContextMenuEntry(selectedCategory, selectedItem, choice)); } }
/// <summary> /// This function is called when one of the custom contextmenu entries was selected by the user. /// Override it to handle the entries you added with <see cref="GetContextMenuEntries"/>. /// </summary> /// <param name="selectedCategory">either the <see cref="Category"/> the context menu was shown for, or the <see cref="Category"/> of the video the context menu was shown for</param> /// <param name="selectedItem">when this is null the context menu was called on the <see cref="Category"/> otherwise on the <see cref="VideoInfo"/></param> /// <param name="choice">the <see cref="ContextMenuEntry"/> that was chosen by the user</param> /// <returns>a <see cref="ContextMenuExecutionResult"/> telling the GUI how to react to the execution of the choice</returns> public virtual ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { return(null); }
/// <summary> /// This function is called when one of the custom contextmenu entries was selected by the user. /// Override it to handle the entries you added with <see cref="GetContextMenuEntries"/>. /// </summary> /// <param name="selectedCategory">either the <see cref="Category"/> the context menu was shown for, or the <see cref="Category"/> of the video the context menu was shown for</param> /// <param name="selectedItem">when this is null the context menu was called on the <see cref="Category"/> otherwise on the <see cref="VideoInfo"/></param> /// <param name="choice">the <see cref="ContextMenuEntry"/> that was chosen by the user</param> /// <returns>a <see cref="ContextMenuExecutionResult"/> telling the GUI how to react to the execution of the choice</returns> public virtual ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { return null; }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { if (selectedItem != null && choice.DisplayText.Contains("watchlist")) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); string other = selectedItem.GetOtherAsString(); JObject json = (JObject)JsonConvert.DeserializeObject(other); bool isSaved = json["saved"].Value<bool>(); string guid = json["guid"].Value<string>(); bool success; if (isSaved) { success = UnsaveVideo(guid); } else { success = SaveVideo(guid); } result.RefreshCurrentItems = success; result.ExecutionResultMessage = (success ? "OK: " : "ERROR: ") + choice.DisplayText + " (" + selectedItem.Title + ")"; return result; } return base.ExecuteContextMenuEntry(selectedCategory, selectedItem, choice); }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); if (choice.DisplayText == Translation.Instance.DeleteAll) { result.RefreshCurrentItems = OnlineVideoSettings.Instance.FavDB.RemoveAllFavoriteVideos(((RssLink)selectedCategory).Url); // we have to manually refresh the categories if (result.RefreshCurrentItems && selectedCategory.ParentCategory != null) DiscoverDynamicCategories(); } else if (choice.DisplayText == Translation.Instance.RemoveFromFavorites) { if (selectedCategory is FavoriteCategory) { result.RefreshCurrentItems = OnlineVideoSettings.Instance.FavDB.RemoveFavoriteCategory(((FavoriteCategory)selectedCategory).FavoriteDbCategory); if (result.RefreshCurrentItems) selectedCategory.ParentCategory.SubCategories.Remove(selectedCategory); return result; } else { result.RefreshCurrentItems = OnlineVideoSettings.Instance.FavDB.RemoveFavoriteVideo(selectedItem as FavoriteDbVideoInfo); } // we have to manually refresh the categories if (result.RefreshCurrentItems && selectedCategory.ParentCategory != null) DiscoverDynamicCategories(); } return result; }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { if (selectedItem != null && ManuallyRetrieveSubtitles && choice.ParentEntry != null && choice.ParentEntry.DisplayText == _textningssprak && choice.ParentEntry.Other is string) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); if (choice.DisplayText == _ingenTextning) { selectedItem.SubtitleText = ""; } else { selectedItem.SubtitleText = GetSubtitle(JObject.Parse(choice.ParentEntry.Other as string), choice.DisplayText); } result.ExecutionResultMessage = selectedItem.Title + " - " + (string.IsNullOrEmpty(selectedItem.SubtitleText) && choice.DisplayText != _ingenTextning ? "Fel vid hämtning av textning!" : _textningssprak + ": " + choice.DisplayText); result.RefreshCurrentItems = false; return(result); } else { return(base.ExecuteContextMenuEntry(selectedCategory, selectedItem, choice)); } }
public override List<ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem) { List<ContextMenuEntry> entries = new List<ContextMenuEntry>(); if (selectedItem != null && ManuallyRetrieveSubtitles) { string data = GetWebData(selectedItem.VideoUrl); Regex rgx = new Regex(@"urPlayer.init\((.*)\);", RegexOptions.Multiline); Match m = rgx.Match(data); if (m != null) { var json = JObject.Parse(m.Groups[1].Value); JArray subtitles = (JArray)json["subtitles"]; if (subtitles != null && subtitles.Count() > 0) { ContextMenuEntry textningssprak = new ContextMenuEntry(); textningssprak.Action = ContextMenuEntry.UIAction.ShowList; textningssprak.DisplayText = _textningssprak; textningssprak.Other = json.ToString(); ContextMenuEntry entry = new ContextMenuEntry(); entry.DisplayText = string.Format(_ingenTextning); textningssprak.SubEntries.Add(entry); foreach (JToken subtitle in subtitles.Where(s => s["label"] != null)) { entry = new ContextMenuEntry(); entry.DisplayText = subtitle["label"].Value<string>(); textningssprak.SubEntries.Add(entry); } entries.Add(textningssprak); } } } return entries; }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); try { if (choice.DisplayText == Translation.Instance.RelatedVideos) { result.ResultItems = GetRelatedVideos(selectedItem, "Episode").ConvertAll <SearchResultItem>(v => v as SearchResultItem); } else if (choice.DisplayText == Translation.Instance.Recommendations) { result.ResultItems = GetRelatedVideos(selectedItem, "More Like This").ConvertAll <SearchResultItem>(v => v as SearchResultItem); } } catch (Exception ex) { throw new OnlineVideosException(ex.Message); } return(result); }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { if (selectedItem != null && choice.DisplayText.Contains("watchlist")) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); string other = selectedItem.GetOtherAsString(); JObject json = (JObject)JsonConvert.DeserializeObject(other); bool isSaved = json["saved"].Value <bool>(); string guid = json["guid"].Value <string>(); bool success; if (isSaved) { success = UnsaveVideo(guid); } else { success = SaveVideo(guid); } result.RefreshCurrentItems = success; result.ExecutionResultMessage = (success ? "OK: " : "ERROR: ") + choice.DisplayText + " (" + selectedItem.Title + ")"; return(result); } return(base.ExecuteContextMenuEntry(selectedCategory, selectedItem, choice)); }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, OnlineVideos.VideoInfo selectedItem, ContextMenuEntry choice) { if (choice != null && choice.DisplayText.StartsWith("Mehr ")) { currentVideoTitle = choice.DisplayText; return(new ContextMenuExecutionResult() { ResultItems = GetVideosFromApiUrl(GetApiUrl("myvideo.videos.list_by_user", new NameValueCollection() { { "user", choice.Other as string } })) .ConvertAll <SearchResultItem>(v => v as SearchResultItem) }); } return(null); }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { if (choice.DisplayText == Translation.Instance.Delete) { try { DeleteVideo(selectedItem.VideoUrl); } catch { } // file might be locked (e.g. still downloading) } else if (choice.DisplayText == Translation.Instance.DeleteAll) { FileInfo[] files = new DirectoryInfo((selectedCategory as RssLink).Url).GetFiles("*", selectedCategory.Name == Translation.Instance.All ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); foreach (FileInfo file in files) { if (IsPossibleVideo(file.Name)) { try { DeleteVideo(selectedItem.VideoUrl); } catch { } // file might be locked (e.g. still downloading) } } } else if (choice.DisplayText == Translation.Instance.Cancel) { ((IDownloader)(selectedItem.Other as DownloadInfo).Downloader).CancelAsync(); } return new ContextMenuExecutionResult() { RefreshCurrentItems = true }; }
public override List<ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem) { List<ContextMenuEntry> entries = new List<ContextMenuEntry>(); if (selectedItem != null && EnableAOSearch && selectedItem.Other is SerializableDictionary<string, string>) { var other = selectedItem.Other as SerializableDictionary<string, string>; ContextMenuEntry amnesord = new ContextMenuEntry(); amnesord.Action = ContextMenuEntry.UIAction.ShowList; amnesord.DisplayText = _amnesord; foreach (var ao in other) { ContextMenuEntry entry = new ContextMenuEntry(); entry.DisplayText = ao.Key; entry.Other = ao.Value; amnesord.SubEntries.Add(entry); } if (amnesord.SubEntries.Count > 0) entries.Add(amnesord); } if (selectedItem != null && ManuallyRetrieveSubtitles) { string data = GetWebData(selectedItem.VideoUrl); Regex rgx = new Regex(@"^urPlayer.init\((.*)\);", RegexOptions.Multiline); Match m = rgx.Match(data); if (m != null) { var json = JObject.Parse(m.Groups[1].Value); JArray subtitles = (JArray)json["subtitles"]; if (subtitles != null && subtitles.Count() > 0) { ContextMenuEntry textningssprak = new ContextMenuEntry(); textningssprak.Action = ContextMenuEntry.UIAction.ShowList; textningssprak.DisplayText = _textningssprak; textningssprak.Other = json.ToString(); ContextMenuEntry entry = new ContextMenuEntry(); entry.DisplayText = string.Format(_ingenTextning); textningssprak.SubEntries.Add(entry); foreach (JToken subtitle in subtitles) { entry = new ContextMenuEntry(); entry.DisplayText = string.Format(subtitle["label"].Value<string>()); textningssprak.SubEntries.Add(entry); } entries.Add(textningssprak); } } } return entries; }
public override List<ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem) { var result = new List<ContextMenuEntry>(); if (selectedItem != null && selectedItem.Other is SerializableDictionary<string, string>) { ContextMenuEntry mehrZumThema = new ContextMenuEntry() { DisplayText = "Mehr zum Thema ...", Action = ContextMenuEntry.UIAction.ShowList }; foreach (var item in (selectedItem.Other as SerializableDictionary<string, string>)) { mehrZumThema.SubEntries.Add(new ContextMenuEntry() { DisplayText = item.Key, Action = ContextMenuEntry.UIAction.Execute, Other = item.Value }); } result.Add(mehrZumThema); } return result; }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { if (selectedItem != null && ManuallyRetrieveSubtitles && choice.ParentEntry != null && choice.ParentEntry.DisplayText == _textningssprak && choice.ParentEntry.Other is string) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); if (choice.DisplayText == _ingenTextning) selectedItem.SubtitleText = ""; else selectedItem.SubtitleText = GetSubtitle(JObject.Parse(choice.ParentEntry.Other as string), choice.DisplayText); result.ExecutionResultMessage = selectedItem.Title + " - " + (string.IsNullOrEmpty(selectedItem.SubtitleText) && choice.DisplayText != _ingenTextning ? "Fel vid hämtning av textning!" : _textningssprak + ": " + choice.DisplayText); result.RefreshCurrentItems = false; return result; } else if (selectedItem != null && EnableAOSearch && choice.ParentEntry != null && choice.ParentEntry.DisplayText == _amnesord && choice.Other is string) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); RssLink cat = new RssLink() { Name = choice.DisplayText, Url = choice.Other as string }; List<SearchResultItem> results = new List<SearchResultItem>(); foreach (VideoInfo vi in GetVideos(cat)) results.Add(vi); result.ResultItems = results; return result; } else return base.ExecuteContextMenuEntry(selectedCategory, selectedItem, choice); }
public override List <ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem) { List <ContextMenuEntry> result = new List <ContextMenuEntry>(); var ytVideo = selectedItem as YouTubeVideo; var ytCategory = selectedCategory as YouTubeCategory; if (selectedItem == null && ytCategory != null) { if (ytCategory.Kind == YouTubeCategory.CategoryKind.Playlist && ytCategory.IsMine && !string.IsNullOrEmpty(ytCategory.Id)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.DeletePlaylist, Action = ContextMenuEntry.UIAction.Execute }); } } if (ytVideo != null) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.RelatedVideos, Action = ContextMenuEntry.UIAction.Execute }); if (!string.IsNullOrEmpty(ytVideo.ChannelTitle) && !string.IsNullOrEmpty(ytVideo.ChannelId)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.UploadsBy + " [" + ytVideo.ChannelTitle + "]", Action = ContextMenuEntry.UIAction.Execute }); result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.Playlists + " [" + ytVideo.ChannelTitle + "]", Action = ContextMenuEntry.UIAction.Execute }); } if (!string.IsNullOrEmpty(userFavoritesPlaylistId)) { if (ytCategory != null && ytCategory.Kind == YouTubeCategory.CategoryKind.Playlist && ytCategory.Id == userFavoritesPlaylistId && !string.IsNullOrEmpty(ytVideo.PlaylistItemId)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.RemoveFromFavorites + " (" + Settings.Name + ")", Action = ContextMenuEntry.UIAction.Execute }); } else { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.AddToFavourites + " (" + Settings.Name + ")", Action = ContextMenuEntry.UIAction.Execute }); } } if (ytCategory != null && ytCategory.Kind == YouTubeCategory.CategoryKind.Playlist && ytCategory.IsMine && !string.IsNullOrEmpty(ytCategory.Id) && !string.IsNullOrEmpty(ytVideo.PlaylistItemId)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.RemoveFromPlaylist, Action = ContextMenuEntry.UIAction.Execute }); } if (enableLogin) { var plCtx = new ContextMenuEntry() { DisplayText = Translation.Instance.AddToPlaylist, Action = ContextMenuEntry.UIAction.ShowList }; plCtx.SubEntries.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.CreateNewPlaylist, Action = ContextMenuEntry.UIAction.GetText }); foreach (var pl in QueryChannelPlaylists(new YouTubeCategory() { IsMine = true }, null)) { if (pl is YouTubeCategory) { plCtx.SubEntries.Add(new ContextMenuEntry() { DisplayText = pl.Name, Other = (pl as YouTubeCategory).Id }); } } result.Add(plCtx); } } return(result); }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { if (choice != null && choice.DisplayText.StartsWith("Get Description")) { string resultUrl = GetFormattedVideoUrl(selectedItem); string data = GetWebData(resultUrl); if (!String.IsNullOrEmpty(data)) { Match m = Regex.Match(data, @"<div\sclass=""imdbdatos"">\s*<i><a\shref=""(?<url>[^""]*)"">IMDb</a>\s<span\sclass=""icon-chevron-right2""></span></i>\s*<i>(?<stars>[^<]*)</i>\s*<i>(?<votes>[^<]*)</i>", defaultRegexOptions); if (m.Success) { selectedItem.Description = m.Groups["stars"].Value + ' ' + m.Groups["votes"].Value + ' '; } m = Regex.Match(data, @"<h2>Synopsis</h2>\s*<p>(?<description>[^<]*)</p>", defaultRegexOptions); if (m.Success) { selectedItem.Description = selectedItem.Description + m.Groups["description"].Value; } } } return(null); }
void HandleCustomContextMenuEntry(ContextMenuEntry currentEntry, Category aCategory, VideoInfo aVideo) { List<KeyValuePair<string, ContextMenuEntry>> dialogOptions = new List<KeyValuePair<string, ContextMenuEntry>>(); while (true) { bool execute = currentEntry.Action == ContextMenuEntry.UIAction.Execute; if (currentEntry.Action == ContextMenuEntry.UIAction.GetText) { SearchDialog dlg = new SearchDialog() { Owner = this }; dlg.tbxSearch.Text = currentEntry.UserInputText ?? ""; dlg.lblHeading.Text = currentEntry.DisplayText; if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.tbxSearch.Text)) { currentEntry.UserInputText = dlg.tbxSearch.Text; execute = true; } else break; } if (currentEntry.Action == ContextMenuEntry.UIAction.ShowList) { PlaybackChoices dlg = new PlaybackChoices() { Owner = this }; dlg.lblHeading.Content = currentEntry.DisplayText; dialogOptions.Clear(); foreach (var subEntry in currentEntry.SubEntries) { dialogOptions.Add(new KeyValuePair<string, ContextMenuEntry>(subEntry.DisplayText, subEntry)); } dlg.lvChoices.ItemsSource = dialogOptions.Select(dO => dO.Key).ToList(); dlg.lvChoices.SelectedIndex = 0; if (dlg.ShowDialog() != true) break; else currentEntry = dialogOptions[dlg.lvChoices.SelectedIndex].Value; } if (execute) { waitCursor.Visibility = System.Windows.Visibility.Visible; Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback( delegate() { return SelectedSite.ExecuteContextMenuEntry(aCategory, aVideo, currentEntry); }, delegate(Gui2UtilConnector.ResultInfo resultInfo) { waitCursor.Visibility = System.Windows.Visibility.Hidden; if (ReactToResult(resultInfo, currentEntry.DisplayText)) { if (resultInfo.ResultObject is ContextMenuExecutionResult) { var cmer = resultInfo.ResultObject as ContextMenuExecutionResult; if (!string.IsNullOrEmpty(cmer.ExecutionResultMessage)) { notification.Show(currentEntry.DisplayText, cmer.ExecutionResultMessage); } if (cmer.RefreshCurrentItems) { CategorySelected(SelectedCategory); } if (cmer.ResultItems != null && cmer.ResultItems.Count > 0) { DisplaySearchResultItems(currentEntry.DisplayText, cmer.ResultItems); } } } }); break; } } }
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 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 List<ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem) { List<ContextMenuEntry> result = new List<ContextMenuEntry>(); if (selectedItem != null) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.RelatedVideos, Action = ContextMenuEntry.UIAction.Execute }); MyYouTubeEntry ytEntry = selectedItem.Other as MyYouTubeEntry; if (ytEntry != null && ytEntry.YouTubeEntry != null) { if (ytEntry.YouTubeEntry.Uploader != null && !string.IsNullOrEmpty(ytEntry.YouTubeEntry.Uploader.Value)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.UploadsBy + " [" + ytEntry.YouTubeEntry.Uploader.Value + "]", Action = ContextMenuEntry.UIAction.Execute }); result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.Playlists + " [" + ytEntry.YouTubeEntry.Uploader.Value + "]", Action = ContextMenuEntry.UIAction.Execute }); } if (selectedCategory != null && selectedCategory.Other as string == "Login" && selectedCategory.Name == string.Format("{0}'s {1}", accountname, Translation.Instance.Favourites)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.RemoveFromFavorites + " (" + Settings.Name + ")", Action = ContextMenuEntry.UIAction.Execute }); } else if (!string.IsNullOrEmpty(accountname) && !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(accountname)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.AddToFavourites + " (" + Settings.Name + ")", Action = ContextMenuEntry.UIAction.Execute }); } if (!string.IsNullOrEmpty(accountname) && !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(accountname)) { // comment result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.AddComment, Action = ContextMenuEntry.UIAction.GetText }); // rate (YouTube uses a 1-5 rating system in which 1 is the lowest rating that can be given) var rCtx = new ContextMenuEntry() { DisplayText = Translation.Instance.RateVideo, Action = ContextMenuEntry.UIAction.ShowList }; for (int i = 1; i <= 5; i++) rCtx.SubEntries.Add(new ContextMenuEntry() { DisplayText = i.ToString() }); result.Add(rCtx); // add to playlist var plCtx = new ContextMenuEntry() { DisplayText = Translation.Instance.AddToPlaylist, Action = ContextMenuEntry.UIAction.ShowList }; plCtx.SubEntries.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.CreateNewPlaylist, Action = ContextMenuEntry.UIAction.GetText }); foreach (var pl in request.GetPlaylistsFeed(accountname).Entries) { plCtx.SubEntries.Add(new ContextMenuEntry() { DisplayText = pl.Title, Other = pl.PlaylistsEntry.Content.Src.Content }); } result.Add(plCtx); if (selectedCategory != null && selectedCategory.ParentCategory != null && !(selectedCategory.ParentCategory is RssLink) && selectedCategory.ParentCategory.Name == string.Format("{0}'s {1}", accountname, Translation.Instance.Playlists)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.RemoveFromPlaylist, Other = (selectedCategory as RssLink).Url }); } } } } else { if (selectedCategory != null && selectedCategory.ParentCategory != null && !(selectedCategory.ParentCategory is RssLink) && selectedCategory.ParentCategory.Name == string.Format("{0}'s {1}", accountname, Translation.Instance.Playlists)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.DeletePlaylist, Other = (selectedCategory as RssLink).Url }); } else if (selectedCategory != null && selectedCategory.ParentCategory != null && !(selectedCategory.ParentCategory is RssLink) && selectedCategory.ParentCategory.Name == string.Format("{0}'s {1}", accountname, Translation.Instance.Subscriptions)) { result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.UploadsBy + " [" + selectedCategory.Name + "]", Action = ContextMenuEntry.UIAction.Execute }); result.Add(new ContextMenuEntry() { DisplayText = Translation.Instance.Playlists + " [" + selectedCategory.Name + "]", Action = ContextMenuEntry.UIAction.Execute }); } } return result; }
public override List<ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem) { List<ContextMenuEntry> menuItems = new List<ContextMenuEntry>(); if (HaveCredentials() && selectedItem != null && selectedItem.Other != null && selectedItem.Other is SerializableDictionary<string, string>) { var other = selectedItem.Other as SerializableDictionary<string, string>; if (other.ContainsKey("starred") && other.ContainsKey("starUrl")) { ContextMenuEntry starMenuEntry = new ContextMenuEntry(); bool starred = false; bool.TryParse((string)other["starred"], out starred); if (starred) starMenuEntry.DisplayText = GetTranslation("Unstar", "Unstar"); else starMenuEntry.DisplayText = GetTranslation("Star", "Star"); menuItems.Add(starMenuEntry); } } if (HaveCredentials() && selectedCategory.Other != null && selectedCategory.Other is string && (selectedCategory.Other as string) == _watched && selectedItem != null && selectedItem.Other != null && selectedItem.Other is SerializableDictionary<string, string>) { var other = selectedItem.Other as SerializableDictionary<string, string>; if (other.ContainsKey("watchedUrl")) { ContextMenuEntry watchedMenuEntry = new ContextMenuEntry(); watchedMenuEntry.DisplayText = selectedCategory.Name + ": " + GetTranslation("Remove from History", "Remove from History"); menuItems.Add(watchedMenuEntry); } } if (selectedItem != null && selectedItem.Other != null && selectedItem.Other is SerializableDictionary<string, string>) { var other = selectedItem.Other as SerializableDictionary<string, string>; if (other.ContainsKey("peopleSearchUrl")) { if (other.ContainsKey("actors")) { ContextMenuEntry actorsMenuEntry = new ContextMenuEntry(); actorsMenuEntry.DisplayText = GetTranslation("Cast", "Cast"); menuItems.Add(actorsMenuEntry); } if (other.ContainsKey("directors")) { ContextMenuEntry directorsMenuEntry = new ContextMenuEntry(); directorsMenuEntry.DisplayText = GetTranslation("Director", "Director"); menuItems.Add(directorsMenuEntry); } } } return menuItems; }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { if (choice.DisplayText == Translation.Instance.Delete) { try { DeleteVideo(selectedItem.VideoUrl); } catch { } // file might be locked (e.g. still downloading) } else if (choice.DisplayText == Translation.Instance.DeleteAll) { FileInfo[] files = new DirectoryInfo((selectedCategory as RssLink).Url).GetFiles("*", selectedCategory.Name == Translation.Instance.All ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); foreach (FileInfo file in files) { if (IsPossibleVideo(file.Name)) { try { DeleteVideo(selectedItem.VideoUrl); } catch { } // file might be locked (e.g. still downloading) } } } else if (choice.DisplayText == Translation.Instance.Cancel) { ((IDownloader)(selectedItem.Other as DownloadInfo).Downloader).CancelAsync(); } return(new ContextMenuExecutionResult() { RefreshCurrentItems = true }); }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { HasNextPage = false; currentVideosTitle = "Mehr zum Thema [" + choice.DisplayText + "]"; var result = new List <VideoInfo>(); string data = GetWebData(choice.Other as string); var html = new HtmlDocument(); html.LoadHtml(data); var section = html.DocumentNode.Descendants("section").FirstOrDefault(s => s.GetAttributeValue("id", "") == "content"); GetLatestVideos(ref result, section.Descendants("ul").First()); var nextPageA = html.DocumentNode.Descendants("a").FirstOrDefault(a => a.InnerText == "nächste"); if (nextPageA != null) { HasNextPage = true; nextPageUrl = "http://www.heise.de" + nextPageA.GetAttributeValue("href", ""); } return(new ContextMenuExecutionResult() { ResultItems = result.ConvertAll <SearchResultItem>(v => (SearchResultItem)v) }); }
public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice) { ContextMenuExecutionResult result = new ContextMenuExecutionResult(); try { if (choice.DisplayText == Translation.Instance.RelatedVideos) { result.ResultItems = GetRelatedVideos(selectedItem, "Episode").ConvertAll<SearchResultItem>(v => v as SearchResultItem); } else if (choice.DisplayText == Translation.Instance.Recommendations) { result.ResultItems = GetRelatedVideos(selectedItem, "More Like This").ConvertAll<SearchResultItem>(v => v as SearchResultItem); } } catch (Exception ex) { throw new OnlineVideosException(ex.Message); } return result; }