/// <summary> /// ランキング情報を再取得します。 /// </summary> public void Reload() { if (string.IsNullOrWhiteSpace(Target) || string.IsNullOrWhiteSpace(Period) || string.IsNullOrWhiteSpace(Category)) { ServiceFactory.MessageService.Error("検索ワードが入力されていません。"); return; } Videos.Clear(); var url = string.Format(Constants.RankingUrl, Target, Period, Category); var txt = GetSmileVideoHtmlText(url); // TODO 入力チェック // ランキングを検索した。 var result = XDocument.Load(new StringReader(txt)).Root; var channel = result.Descendants("channel").First(); foreach (var item in channel.Descendants("item")) { var desc = XDocument.Load(new StringReader("<root>" + item.Element("description").Value + "</root>")).Root; var lengthSecondsStr = (string)desc .Descendants("strong") .Where(x => (string)x.Attribute("class") == "nico-info-length") .First(); var video = new VideoModel() { VideoUrl = item.Element("link").Value, Title = item.Element("title").Value, ViewCounter = NicoDataConverter.ToCounter(desc, "nico-info-total-view"), MylistCounter = NicoDataConverter.ToCounter(desc, "nico-info-total-res"), CommentCounter = NicoDataConverter.ToCounter(desc, "nico-info-total-mylist"), StartTime = DateTime.Parse(channel.Element("pubDate").Value), ThumbnailUrl = (string)desc.Descendants("img").First().Attribute("src"), LengthSeconds = NicoDataConverter.ToLengthSeconds(lengthSecondsStr), }; // 状態に追加 VideoStatusModel.Instance.VideoMerge(video); // 自身に追加 Videos.Add(video.VideoId); } ServiceFactory.MessageService.Debug(url); }
/// <summary> /// マイリスト情報を再取得します。 /// </summary> public void Reload() { var result = XDocument.Load(new StringReader(GetSmileVideoHtmlText(MylistUrl))).Root; var channel = result.Descendants("channel").First(); // マイリスト情報を本インスタンスのプロパティに転記 MylistTitle = channel.Element("title").Value; MylistCreator = channel.Element(XName.Get("creator", "http://purl.org/dc/elements/1.1/")).Value; MylistDate = DateTime.Parse(channel.Element("lastBuildDate").Value); MylistDescription = channel.Element("description").Value; UserId = GetUserId(); UserThumbnailUrl = GetThumbnailUrl(); Videos.Clear(); foreach (var item in channel.Descendants("item")) { var desc = XDocument.Load(new StringReader("<root>" + item.Element("description").Value + "</root>")).Root; var lengthSecondsStr = (string)desc .Descendants("strong") .Where(x => (string)x.Attribute("class") == "nico-info-length") .First(); var video = new VideoModel() { VideoUrl = item.Element("link").Value, Title = item.Element("title").Value, ViewCounter = NicoDataConverter.ToCounter(desc, "nico-numbers-view"), MylistCounter = NicoDataConverter.ToCounter(desc, "nico-numbers-mylist"), CommentCounter = NicoDataConverter.ToCounter(desc, "nico-numbers-res"), StartTime = DateTime.Parse(channel.Element("pubDate").Value), ThumbnailUrl = (string)desc.Descendants("img").First().Attribute("src"), LengthSeconds = NicoDataConverter.ToLengthSeconds(lengthSecondsStr), }; // ビデオ情報をステータスモデルに追加 VideoStatusModel.Instance.VideoMerge(video); // idを追加 Videos.Add(video.VideoId); } OnPropertyChanged(nameof(Videos)); }
///// <summary> ///// Urlエンコード文字列から文字列に変換します。 ///// </summary> ///// <param name="txt"></param> ///// <returns></returns> //private string FromUrlEncode(string txt) //{ // txt = HttpUtility.UrlDecode(txt); // txt = txt.Replace("<", "<"); // txt = txt.Replace(">", ">"); // txt = txt.Replace(""", "\""); // txt = txt.Replace("'", "'"); // txt = txt.Replace("&", "&"); // txt = txt.Replace(" ", "\n"); // return txt; //} protected string UpdateVideoFromXml(XElement item, string view, string mylist, string comment) { string descriptionString; XElement desc; try { // 明細部をXDocumentで読み込むために整形 descriptionString = item.Element("description").Value; descriptionString = descriptionString.Replace(" ", " "); //descriptionString = HttpUtility.HtmlDecode(descriptionString); //descriptionString = descriptionString.Replace("&", "&"); //descriptionString = descriptionString.Replace("'", "'"); // 明細部読み込み desc = XDocument.Load(new StringReader($"<root>{descriptionString}</root>")).Root; // 動画時間 var lengthSecondsStr = (string)desc .Descendants("strong") .Where(x => (string)x.Attribute("class") == "nico-info-length") .First(); var video = VideoStatusModel.Instance.GetVideo(NicoDataConverter.ToId(item.Element("link").Value)); video.Title = item.Element("title").Value; video.ViewCounter = NicoDataConverter.ToCounter(desc, view); video.MylistCounter = NicoDataConverter.ToCounter(desc, mylist); video.CommentCounter = NicoDataConverter.ToCounter(desc, comment); video.StartTime = NicoDataConverter.ToRankingDatetime(desc, "nico-info-date"); video.ThumbnailUrl = (string)desc.Descendants("img").First().Attribute("src"); video.LengthSeconds = NicoDataConverter.ToLengthSeconds(lengthSecondsStr); video.Description = (string)desc.Descendants("p").FirstOrDefault(x => (string)x.Attribute("class") == "nico-description"); return(video.VideoId); } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw; } }