Exemple #1
0
        public void Reload()
        {
            if (string.IsNullOrWhiteSpace(Word))
            {
                ServiceFactory.MessageService.Error("検索ワードが入力されていません。");
                return;
            }

            Videos.Clear();

            string targets = IsTag ? Constants.TargetTag : Constants.TargetKeyword;
            string q       = HttpUtil.ToUrlEncode(Word);
            string fields  = Constants.Fields;
            string offset  = Offset.ToString();
            string limit   = Limit.ToString();
            string context = Constants.Context;
            string sort    = OrderBy;
            string url     = String.Format(Constants.SearchByWordUrl, q, targets, fields, sort, offset, limit, context);
            string txt     = GetSmileVideoHtmlText(url);

            // TODO 入力チェック

            var json = DynamicJson.Parse(txt);

            foreach (dynamic data in json["data"])
            {
                var video = new VideoModel()
                {
                    VideoUrl        = data["contentId"],
                    Title           = data["title"],
                    Description     = data["description"],
                    Tags            = data["tags"],
                    CategoryTag     = data["categoryTags"],
                    ViewCounter     = data["viewCounter"],
                    MylistCounter   = data["mylistCounter"],
                    CommentCounter  = data["commentCounter"],
                    StartTime       = NicoDataConverter.ToDatetime(data["startTime"]),
                    LastCommentTime = NicoDataConverter.ToDatetime(data["lastCommentTime"]),
                    LengthSeconds   = data["lengthSeconds"],
                    ThumbnailUrl    = data["thumbnailUrl"] + ThumbSize,
                    //CommunityIcon = data["communityIcon"]
                };

                // 状態に追加
                VideoStatusModel.Instance.VideoMerge(video);

                // 自身に追加
                Videos.Add(video.VideoId);
            }

            DataLength = json["meta"]["totalCount"];

            ServiceFactory.MessageService.Debug(url);
        }
        public VideoDetailModel(VideoModel source)
        {
            this.Method      = "GET";
            this.ContentType = "application/x-www-form-urlencoded";
            Source           = source;

            if (string.IsNullOrWhiteSpace(Source.Tags))
            {
                // タグ情報がない場合はリロードして取得する。
                Source.Reload();
            }

            ReadFlvUrl().ConfigureAwait(false);
            Tags = Source.Tags;
        }
        /// <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);
        }
Exemple #4
0
        public void Reload()
        {
            // ログインする。
            LoginModel.Instance.Login();

            // ログインできなかった場合
            if (!LoginModel.Instance.IsLogin)
            {
                ServiceFactory.MessageService.Error("Login error");
                return;
            }

            Videos.Clear();

            string txt = GetSmileVideoHtmlText(Constants.DeflistList);

            // TODO 入力チェック

            var json = DynamicJson.Parse(txt);

            foreach (dynamic data in json["mylistitem"])
            {
                var video = new VideoModel()
                {
                    VideoUrl    = data["item_id"],
                    Title       = data["item_data"]["title"],
                    Description = data["description"],
                    //Tags = data["tags"],
                    //CategoryTag = data["categoryTags"],
                    ViewCounter    = long.Parse(data["item_data"]["view_counter"]),
                    MylistCounter  = long.Parse(data["item_data"]["mylist_counter"]),
                    CommentCounter = long.Parse(data["item_data"]["num_res"]),
                    StartTime      = NicoDataConverter.FromUnixTime((long)data["create_time"]),
                    //LastCommentTime = Converter.ToDatetime(data["lastCommentTime"]),
                    LengthSeconds = long.Parse(data["item_data"]["length_seconds"]),
                    ThumbnailUrl  = data["item_data"]["thumbnail_url"],
                    LastResBody   = data["item_data"]["last_res_body"],
                    //CommunityIcon = data["communityIcon"]
                };

                // 状態に追加
                VideoStatusModel.Instance.VideoMerge(video);

                // 自身に追加
                Videos.Add(video.VideoId);
            }
        }
Exemple #5
0
        /// <summary>
        /// ビデオ情報をマージします。
        /// </summary>
        /// <param name="video">マージするビデオ情報</param>
        public void VideoMerge(VideoModel video)
        {
            if (Videos.Any(v => v.VideoId == video.VideoId))
            {
                var v = Videos.First(temp => temp.VideoId == video.VideoId);

                // 更新要素を再設定
                v.ViewCounter    = video.ViewCounter;
                v.MylistCounter  = video.MylistCounter;
                v.CommentCounter = video.CommentCounter;
                v.LastResBody    = video.LastResBody;
            }
            else
            {
                // 追加
                Videos.Add(video);
            }
        }
Exemple #6
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));
        }
Exemple #7
0
        /// <summary>
        /// ビデオ情報を取得します。
        /// </summary>
        /// <param name="id">取得したいビデオID</param>
        /// <param name="reload">既存情報をリロードするか</param>
        /// <returns>ビデオ情報</returns>
        public VideoModel GetVideo(string id, bool reload = false)
        {
            var video = Videos.FirstOrDefault(v => v.VideoId == id);

            if (video != null)
            {
                if (reload)
                {
                    video.Reload();
                }
                return(video);
            }
            else
            {
                var tmp = new VideoModel(id);

                Videos.Add(tmp);

                return(tmp);
            }
        }