public async Task<List<AnimeVideoData>> GetVideos(bool force) { var output = force ? new List<AnimeVideoData>() : await DataCache.RetrieveData<List<AnimeVideoData>>($"videos_{_id}", "AnimeDetails", 7) ?? new List<AnimeVideoData>(); if (output.Any()) return output; var raw = await GetRequestResponse(false); if (string.IsNullOrEmpty(raw)) return output; var doc = new HtmlDocument(); doc.LoadHtml(raw); try { foreach ( var video in doc.FirstOfDescendantsWithClass("div", "video-block promotional-video mt16") .WhereOfDescendantsWithClass("div", "video-list-outer po-r pv")) { try { var current = new AnimeVideoData(); var img = video.Descendants("img").First(); current.Thumb = img.Attributes["data-src"].Value; if (current.Thumb.Contains("banned")) continue; var href = video.Descendants("a").First().Attributes["href"].Value; var pos = href.IndexOf('?'); href = href.Substring(0, pos); current.YtLink = $"https://www.youtube.com/watch?v={href.Split('/').Last()}"; current.Name = WebUtility.HtmlDecode(img.Attributes["data-title"].Value); output.Add(current); } catch (Exception) { //html } } } catch (Exception) { //no videos } DataCache.SaveData(output, $"videos_{_id}", "AnimeDetails"); return output; }
public async Task<List<AnimeVideoData>> GetVideos() { var output = new List<AnimeVideoData>(); var raw = await GetRequestResponse(false); if (string.IsNullOrEmpty(raw)) return output; var doc = new HtmlDocument(); doc.LoadHtml(raw); try { foreach (var videoNode in doc.WhereOfDescendantsWithClass("div", "video-list-outer-vertical")) { var current = new AnimeVideoData(); var link = videoNode.ChildNodes.First(node => node.Name == "a"); current.Thumb = link.Attributes["data-bg"].Value; if(current.Thumb.Contains("banned")) continue; current.AnimeId = int.Parse(link.Attributes["data-anime-id"].Value); var href = link.Attributes["href"].Value; var pos = href.IndexOf('?'); href = href.Substring(0, pos); current.YtLink = $"https://www.youtube.com/watch?v={href.Split('/').Last()}"; current.Name = WebUtility.HtmlDecode( videoNode.FirstOfDescendantsWithClass("div", "info-container").InnerText.Trim()); current.AnimeTitle = WebUtility.HtmlDecode(videoNode.Descendants("a").Last().InnerText.Trim()); output.Add(current); } } catch (Exception) { // } return output; }
public static async Task OpenVideo(AnimeVideoData data) { try { var youTube = YouTube.Default; var video = youTube.GetVideo(data.YtLink); var uri = await video.GetUriAsync(); ViewModelLocator.GeneralMain.MediaElementSource = uri; ViewModelLocator.GeneralMain.MediaElementVisibility = true; ViewModelLocator.GeneralMain.MediaElementIndirectSource = data.YtLink; } catch (Exception) { ResourceLocator.MessageDialogProvider.ShowMessageDialog("Something went wrong with loading this video, probably google has messed again with their api again... yay!","Unable to load youtube video!"); } }