コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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));
        }
コード例 #3
0
        ///// <summary>
        ///// Urlエンコード文字列から文字列に変換します。
        ///// </summary>
        ///// <param name="txt"></param>
        ///// <returns></returns>
        //private string FromUrlEncode(string txt)
        //{
        //    txt = HttpUtility.UrlDecode(txt);
        //    txt = txt.Replace("&lt;", "<");
        //    txt = txt.Replace("&gt;", ">");
        //    txt = txt.Replace("&quot;", "\"");
        //    txt = txt.Replace("&apos;", "'");
        //    txt = txt.Replace("&amp;", "&");
        //    txt = txt.Replace("&nbsp;", "\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("&nbsp;", "&#x20;");
                //descriptionString = HttpUtility.HtmlDecode(descriptionString);
                //descriptionString = descriptionString.Replace("&", "&amp;");
                //descriptionString = descriptionString.Replace("'", "&apos;");

                // 明細部読み込み
                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;
            }
        }
コード例 #4
0
ファイル: VideoModel.cs プロジェクト: twinbird827/NicoV3
        /// <summary>
        /// ビデオ情報を読み取ります。
        /// </summary>
        public void Reload()
        {
            // ビデオ詳細情報取得
            var url = string.Format(Constants.VideoDetailUrl, this.VideoId);
            var txt = GetSmileVideoHtmlText(url);
            var xml = XDocument.Load(new StringReader(txt)).Root.Element("thumb");

            Title          = xml.Element("title").Value;
            ViewCounter    = long.Parse(xml.Element("view_counter").Value);
            MylistCounter  = long.Parse(xml.Element("mylist_counter").Value);
            CommentCounter = long.Parse(xml.Element("comment_num").Value);
            StartTime      = DateTime.Parse(xml.Element("first_retrieve").Value);
            ThumbnailUrl   = xml.Element("thumbnail_url").Value;
            LengthSeconds  = NicoDataConverter.ToLengthSeconds(xml.Element("length").Value);
            LastResBody    = xml.Element("last_res_body").Value;
            Tags           = string.Join(" ", xml
                                         .Elements("tags")
                                         .First(x => (string)x.Attribute("domain") == "jp")
                                         .Elements("tag")
                                         .Select(x => (string)x)
                                         );
        }