Esempio n. 1
0
 public void loadList(Boolean showDialog)
 {
     list.Clear();
     //追加
     if (Properties.Settings.Default.auto_admission_list != "")
     {
         //追加
         var account_list   = Properties.Settings.Default.auto_admission_list;
         var admissionArray = JsonConvert.DeserializeObject <List <AutoAdmissionJSON> >(account_list);
         //ListView
         foreach (var autoAdmission in admissionArray)
         {
             //UnixTime→DateTime
             var dateTime = FromUnixTime(autoAdmission.UnixTime);
             var pos      = admissionArray.IndexOf(autoAdmission);
             var item     = new ProgramListViewData {
                 Name = autoAdmission.Name, Pos = pos, dateTime = "開場時間 : " + dateTime.ToString()
             };
             list.Add(item);
         }
     }
     else
     {
         if (showDialog)
         {
             //登録されてないよ!
             showEmptyMessage();
         }
     }
 }
        public async void loadNicoFavList(Boolean dialogShow)
        {
            //ニコ生フォロー中表示。引数はログイン無い時にダイアログだすかどうか
            list.Clear();
            if (setting.Values["user_session"] != null)
            {
                // タイトルを取得したいサイトのURL
                var urlstring = "https://sp.live.nicovideo.jp/favorites";
                // 指定したサイトのHTMLをストリームで取得する
                var client = new HttpClient();
                client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "NicoLiveAlert_Twitter;@takusan_23");
                client.DefaultRequestHeaders.TryAddWithoutValidation("Cookie", "user_session=" + setting.Values["user_session"]);
                using (var stream = await client.GetAsync(new Uri(urlstring)))
                {
                    //var html = await client.GetStringAsync(urlstring);

                    if (stream.StatusCode == HttpStatusCode.OK)
                    {
                        var parser     = new HtmlParser();
                        var jsonString = await stream.Content.ReadAsStringAsync();

                        var doc = await parser.ParseDocumentAsync(jsonString);


                        //フォロー中の番組のJSON
                        var json = doc.Head.GetElementsByTagName("script")[3].TextContent;
                        json = HttpUtility.UrlDecode(json);

                        json = json.Replace("window.__initial_state__ = \"", "");
                        json = json.Replace("locationBeforeTransitions\":null}}\";", "locationBeforeTransitions\":null}}");
                        json = json.Replace("window.__public_path__ = \"https://nicolive.cdn.nimg.jp/relive/sp/\";", "");


                        var nicoJSON = JsonConvert.DeserializeObject <RootObject>(json);

                        //forEachで取り出す
                        if (nicoJSON != null)
                        {
                            var pos = 0;
                            foreach (var program in nicoJSON.pageContents.favorites.favoritePrograms.programs)
                            {
                                //予約枠だけ取得
                                if (program.liveCycle == "BeforeOpen")
                                {
                                    //なんかしらんけどbeginAtがフォロー中番組だけ値が大きすぎるのでUnixTimeにする割り算
                                    var beginTime = program.beginAt / 1000L;
                                    var dateTime  = "開場時間 : " + DateTimeOffset.FromUnixTimeSeconds(beginTime).LocalDateTime.ToString();
                                    var item      = new ProgramListViewData {
                                        Name = program.title + " | " + program.socialGroupName + " | " + program.id, Pos = pos, beginAt = beginTime, ID = program.id, dateTime = dateTime
                                    };
                                    pos += 1;
                                    list.Add(item);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (dialogShow)
                {
                    showLoginMessage();
                }
            }
        }
Esempio n. 3
0
        public async void loadNicoRepo(Boolean dialogShow)
        {
            list.Clear();
            //今のUnixTime
            long nowUnixTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            if (Properties.Settings.Default.user_session != "")
            {
                //ニコレポAPI?
                var urlString = "https://www.nicovideo.jp/api/nicorepo/timeline/my/all?client_app=pc_myrepo";
                //user_session
                var user_session = Properties.Settings.Default.user_session;
                //Cookieをせっと(user_session)
                var cookieContainer = new CookieContainer();
                var cookie          = new Cookie();
                cookie.Name   = "user_session";
                cookie.Value  = user_session;
                cookie.Domain = ".nicovideo.jp";
                cookieContainer.Add(cookie);
                var header = new HttpClientHandler();
                header.CookieContainer = cookieContainer;

                var client = new HttpClient(header);
                client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "NicoLiveAlert_Twitter;@takusan_23");
                client.DefaultRequestHeaders.TryAddWithoutValidation("Cookie", "user_session=" + Properties.Settings.Default.user_session);
                using (var stream = await client.GetAsync(new Uri(urlString)))
                {
                    if (stream.StatusCode == HttpStatusCode.OK)
                    {
                        var jsonString = await stream.Content.ReadAsStringAsync();

                        var jsonObject = JsonConvert.DeserializeObject <NicoRepoRootObject>(jsonString);

                        //forEach
                        var pos = 0;
                        foreach (var json in jsonObject.data)
                        {
                            //ニコレポには生放送以外の内容も流れてくるので生放送だけふるう
                            if (json.program != null)
                            {
                                //予約枠の投稿だけひろう
                                if (json.topic == "live.user.program.reserve")
                                {
                                    //番組開始時刻
                                    var date = DateTime.Parse(json.program.beginAt);
                                    //DateTime→UnixTime
                                    var unix = new DateTimeOffset(date.Ticks, new TimeSpan(+09, 00, 00));
                                    //開場時間
                                    var dateTime = "開場時間 : " + date.ToString();
                                    //すでに終わってる予約枠は拾わない
                                    if (nowUnixTime <= unix.ToUnixTimeSeconds())
                                    {
                                        var name = $"{json.program.title} | {json.community.name} | {json.program.id}";
                                        var item = new ProgramListViewData {
                                            Name = name, beginAt = unix.ToUnixTimeSeconds(), ID = json.program.id, Pos = pos, dateTime = dateTime
                                        };
                                        list.Add(item);
                                        pos += 1;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        //user_session再取得
                        var nicologin = new NicoLogin();
                        nicologin.ReNiconicoLogin();
                    }
                }
            }
            else
            {
                if (dialogShow)
                {
                    showLoginMessage();
                }
            }
        }