Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 4
0
        /// <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);
        }