Example #1
0
        private async void StartListening(string url)
        {
            // Establish the local endpoint for the socket.
            // The DNS name of the computer
            // running the listener is "host.contoso.com".
            IPAddress  ipAddress     = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];
            IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 81);

            // Create a TCP/IP socket.
            Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            listener.Bind(localEndPoint);
            listener.Listen(100);

            StateObject state = new StateObject();

            state.WorkSocket = listener;
            state.ConnectUri = await VideoStatusModel.Instance
                               .GetVideo(NicoDataConverter.ToId(url))
                               .GetMovieUriAsync();

            allDone.Reset();

            // Start an asynchronous socket to listen for connections.
            Console.WriteLine("Waiting for a connection...");
            listener.BeginAccept(new AsyncCallback(AcceptCallback), state);

            FlvFile = new Uri("127.0.0.1:81", UriKind.Relative);

            // Wait until a connection is made before continuing.
            allDone.WaitOne();
        }
        public override async Task Reload()
        {
            const string url = "http://www.nicovideo.jp/api/deflist/list";

            var json = await GetJsonAsync(url);

            Videos.Clear();

            foreach (dynamic item in json["mylistitem"])
            {
                var video = VideoStatusModel.Instance.GetVideo((string)item["item_id"]);

                video.VideoUrl    = item["item_id"];
                video.Title       = item["item_data"]["title"];
                video.Description = item["description"];
                //video.Tags = data["tags"];
                //video.CategoryTag = data["categoryTags"];
                video.ViewCounter    = long.Parse(item["item_data"]["view_counter"]);
                video.MylistCounter  = long.Parse(item["item_data"]["mylist_counter"]);
                video.CommentCounter = long.Parse(item["item_data"]["num_res"]);
                video.StartTime      = NicoDataConverter.FromUnixTime((long)item["item_data"]["first_retrieve"]);
                //video.LastCommentTime = Converter.item(data["lastCommentTime"]);
                video.LengthSeconds = long.Parse(item["item_data"]["length_seconds"]);
                video.ThumbnailUrl  = item["item_data"]["thumbnail_url"];
                video.LastResBody   = item["item_data"]["last_res_body"];
                //video.CommunityIcon = data["communityIcon"];

                Videos.Add(video.VideoId);
            }
        }
Example #3
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 override async Task Reload()
        {
            if (string.IsNullOrWhiteSpace(Word))
            {
                ServiceFactory.MessageService.Error("検索ワードが入力されていません。");
                return;
            }

            Videos.Clear();

            string targets = IsTag ? "tagsExact" : "title,description,tags";
            string q       = NicoDataConverter.ToUrlEncode(Word);
            string fields  = "contentId,title,description,tags,categoryTags,viewCounter,mylistCounter,commentCounter,startTime,lastCommentTime,lengthSeconds,thumbnailUrl";
            string offset  = Offset.ToString();
            string limit   = Limit.ToString();
            string context = "kaz.server-on.net/NicoV4";
            string sort    = OrderBy;
            string url     = String.Format("http://api.search.nicovideo.jp/api/v2/video/contents/search?q={0}&targets={1}&fields={2}&_sort={3}&_offset={4}&_limit={5}&_context={6}",
                                           q, targets, fields, sort, offset, limit, context
                                           );

            // TODO 入力チェック

            var json = await GetJsonAsync(url);

            Videos.Clear();

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

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

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

            ServiceFactory.MessageService.Debug(url);
        }
        /// <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);
        }
Example #6
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);
            }
        }
Example #7
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));
        }
Example #8
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;
            }
        }
        /// <summary>
        /// 共通の追加処理
        /// </summary>
        /// <param name="url">追加するURL</param>
        private async Task AddMylist(string url)
        {
            SearchVideoByMylistModel mylist;

            try
            {
                mylist = await MylistStatusModel.Instance.GetMylist(NicoDataConverter.ToId(url));

                if (!mylist.Videos.Any())
                {
                    throw new ArgumentException("データ件数が0件");
                }
            }
            catch
            {
                ServiceFactory.MessageService.Error("有効なUrlを指定してください。");
                return;
            }

            MylistStatusModel.Instance.AddFavorites(mylist.MylistId);
        }
Example #10
0
        /// <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)
                                         );
        }