Exemplo n.º 1
0
        private GetStreamInfo GetStreamData(string data)
        {
            var gsi = new GetStreamInfo();

            gsi.LiveId       = string.Empty;
            gsi.Community_Id = string.Empty;
            gsi.Provider_Id  = string.Empty;

            if (!string.IsNullOrEmpty(data))
            {
                if (data.IndexOf(',') > 0)
                {
                    var ttt = data.Split(',');
                    gsi.LiveId       = "lv" + ttt[0];
                    gsi.Community_Id = ttt[1];
                    gsi.Provider_Id  = ttt[2];
                }
                else
                {
                    gsi.LiveId = data;
                }
            }

            return(gsi);
        }
Exemplo n.º 2
0
    private GetStreamInfo GetStreamData(string gameID)
    {
        // create web request form
        var request = WebRequest.Create(string.Format("{0}?game_id={1}", url, gameID));

        request.Method  = "Get";
        request.Timeout = 12000;
        request.Headers.Add("Client-ID", clientID);

        // get response from API
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        // get data stream from API
        Stream dataStream = response.GetResponseStream();

        // open data stream
        StreamReader dataReader = new StreamReader(dataStream);

        // read data stream
        string data = dataReader.ReadToEnd();
        //Debug.Log(data);

        // transform JSON into a serialized object
        GetStreamInfo jsonData = JsonUtility.FromJson <GetStreamInfo>(data);

        // close streams
        dataReader.Close();
        dataStream.Close();
        response.Close();

        return(jsonData);
    }
Exemplo n.º 3
0
        private Form1 _form;  //親フォーム

        public Popup(Form1 fo, GetStreamInfo gsi)
        {
            InitializeComponent();

            _form = fo;
            _gsi  = gsi;
        }
Exemplo n.º 4
0
        private void DispStreamInfo(GetStreamInfo gsi)
        {
            var ttt = string.Format(DateTime.Now.ToString("[yyyy/MM/dd HH:mm:ss]") + "  放送ID:{0}  コミュニティID:{1}  ユーザーID:{2}",
                                    gsi.LiveId, gsi.Community_Id, gsi.Provider_Id);

            AddLog(ttt, 1);
        }
Exemplo n.º 5
0
    private List <int> GetViewerCounts(GetStreamInfo jsonData)
    {
        // make sure previous list is cleared to prevent duplicates in when refreshing
        viewerCounts.Clear();

        // loop through serialized JSON data for viewer counts and add to list
        for (int i = 0; i < jsonData.data.Count; i++)
        {
            viewerCounts.Add(jsonData.data[i].viewer_count);
        }

        Debug.Log("Update viewer counts");
        return(viewerCounts);
    }
Exemplo n.º 6
0
        private void PopupProc(GetStreamInfo gsi)
        {
            var fpop = new Popup(this, gsi);

            try
            {
                int i = fpop.GetPopiNum();
                fpop.SetPosition("RD");     //表示する座標を決定
                fpop.Show();
            }
            catch (Exception Ex)
            {
                DebugWrite.Writeln(nameof(GetStreamInfo), Ex);
            }
        }
Exemplo n.º 7
0
        private async Task work2(GetStreamInfo gsi, int f_idx)
        {
            try
            {
                //var gsi2 = await _nLiveNet.GetStreamInfo2Async(gsi.LiveId, gsi.Provider_Id);
                lists_c[f_idx].Last_Date = gsi.Col12.ToString("yyyy/MM/dd HH:mm:ss");
                lists_c[f_idx].Col14     = Comm.GetLiveNumber(gsi.LiveId);
                gsi.Col02 = await _nLiveNet.CreateImageAsync(gsi.Community_Thumbnail);

                lists_si.Add(gsi);
                var liveid = Props.GetLiveUrl(gsi.LiveId);
                if (lists_c[f_idx].Pop)
                {
                    PopupProc(gsi);
                }
                if (lists_c[f_idx].Web)
                {
                    OpenProcess.OpenWeb(liveid, props.BrowserPath, props.IsDefaultBrowser);
                }
                if (lists_c[f_idx].Sound)
                {
                    SoundProc();
                }
                if (lists_c[f_idx].App_a)
                {
                    OpenProcess.OpenProgram(liveid, props.AppA_Path);
                }
                if (lists_c[f_idx].App_b)
                {
                    OpenProcess.OpenProgram(liveid, props.AppB_Path);
                }
                if (lists_c[f_idx].App_c)
                {
                    OpenProcess.OpenProgram(liveid, props.AppC_Path);
                }
                if (lists_c[f_idx].App_d)
                {
                    OpenProcess.OpenProgram(liveid, props.AppD_Path);
                }
            }
            catch (Exception Ex)
            {
                AddLog("work2: " + Ex.Message, 2);
            }
        }
Exemplo n.º 8
0
    private void Update()
    {
        timer += Time.deltaTime;

        // get the target game
        gameID = this.GetComponent <AssignGameName>().myGameId;

        // refresh viewer counts list for target game by the number of seconds specified
        // in 'refreshRate' variable
        if (gameID != "" && timer > refreshRate)
        {
            // load JSON data containing top streams for target game
            GetStreamInfo jsonStreamInfo = GetStreamData(gameID);

            // parse JSON data
            GetViewerCounts(jsonStreamInfo);

            // reset timer for next request
            timer = 0;
        }
    }
Exemplo n.º 9
0
        public async Task <GetStreamInfo> GetStreamInfo2Async(string liveid, string userid)
        {
            var gsi = new GetStreamInfo();

            gsi.Status = "fail";
            gsi.Error  = "not_permitted";

            try
            {
                //データー取得
                gsi.LiveId      = liveid;
                gsi.Provider_Id = userid;
                //ニコキャスかどうかの判定
                var providertype = "unama";
                gsi.Provider_Type = providertype;

                var html = await _wc.DownloadStringTaskAsync(Props.NicoLiveUrl + liveid).Timeout(_wc.timeout);

                providertype      = Regex.Match(html, "\"content_type\":\"([^\"]*)\"", RegexOptions.Compiled).Groups[1].Value;
                gsi.Provider_Type = providertype;
                if (html.IndexOf("window.NicoGoogleTagManagerDataLayer = [];") > 0)
                {
                    //コミュ限定・有料放送
                    var ttt = Regex.Match(html, "<title>([^<]*)</title>", RegexOptions.Compiled).Groups[1].Value;
                    ttt                     = Regex.Replace(ttt, "(.*) - (ニコニコ生放送|実験放送)$", "$1");
                    gsi.Title               = WebUtility.HtmlDecode(ttt);
                    ttt                     = Regex.Match(html, "<meta +name=\"description\" +content=\"([^\"]*)\"/>", RegexOptions.Compiled).Groups[1].Value;
                    gsi.Description         = WebUtility.HtmlDecode(ttt);
                    ttt                     = Regex.Match(html, "<meta +itemprop=\"thumbnail\" +content=\"([^\"]*)\"", RegexOptions.Compiled).Groups[1].Value;
                    gsi.Community_Thumbnail = WebUtility.HtmlDecode(ttt);

                    gsi.Community_Only = "1";

                    ttt = RgxComm.Match(html).Groups[1].Value;
                    gsi.Community_Id = GetStreamInfo.GetChNo(ttt);
                    ttt = RgxComm.Match(html).Groups[2].Value;
                    gsi.Community_Title = WebUtility.HtmlDecode(ttt);

                    gsi.Provider_Id   = providertype;
                    gsi.Provider_Name = "公式生放送";
                    if (providertype == "user")
                    {
                        ttt               = RgxUser.Match(html).Groups[1].Value;
                        gsi.Provider_Id   = GetStreamInfo.GetChNo(ttt);
                        ttt               = RgxUser.Match(html).Groups[2].Value;
                        gsi.Provider_Name = WebUtility.HtmlDecode(ttt);
                    }
                    else if (providertype == "channel" || providertype == "official")
                    {
                        ttt = RgxChName.Match(html).Groups[1].Value;
                        gsi.Community_Id = GetStreamInfo.GetChNo(ttt);
                        ttt = RgxChName.Match(html).Groups[2].Value;
                        gsi.Community_Title = WebUtility.HtmlDecode(ttt);

                        ttt = RgxChUser.Match(html).Groups[1].Value;
                        if (!string.IsNullOrEmpty(ttt))
                        {
                            gsi.Provider_Name = WebUtility.HtmlDecode(ttt);
                        }
                    }
                    gsi.Status = "ok";
                }
                else
                {
                    var ttt = WebUtility.HtmlDecode(Regex.Match(html, "<script +id=\"embedded-data\" +data-props=\"([^\"]*)\"></script>", RegexOptions.Compiled).Groups[1].Value);
                    //Clipboard.SetText(ttt);
                    var dprops = JObject.Parse(ttt);
                    ttt       = Regex.Match(html, "<title>([^<]*)</title>", RegexOptions.Compiled).Groups[1].Value;
                    ttt       = Regex.Replace(ttt, "(.*) - (ニコニコ生放送|実験放送)$", "$1");
                    gsi.Title = WebUtility.HtmlDecode(ttt);
                    //Clipboard.SetText(dprops.ToString());
                    var dprogram = (JObject)dprops["program"];
                    //gsi.LiveId = dprogram["nicoliveProgramId"].ToString();
                    //gsi.Title = dprogram["title"].ToString();
                    gsi.Description         = dprogram["description"].ToString();
                    gsi.Provider_Id         = providertype;
                    gsi.Provider_Name       = "公式生放送";
                    gsi.Community_Thumbnail = dprogram["thumbnail"]["small"].ToString();
                    JToken aaa;
                    if (dprogram.TryGetValue("supplier", out aaa))
                    {
                        gsi.Provider_Name = dprogram["supplier"]["name"].ToString();
                        if (providertype == "user")
                        {
                            gsi.Provider_Id = GetStreamInfo.GetChNo(dprogram["supplier"]["pageUrl"].ToString());
                        }
                    }
                    gsi.Community_Only  = dprogram["isFollowerOnly"].ToString();
                    gsi.Community_Id    = providertype;
                    gsi.Community_Title = "公式生放送";
                    if (dprops["socialGroup"].Count() > 0)
                    {
                        gsi.Community_Id    = dprops["socialGroup"]["id"].ToString();
                        gsi.Community_Title = dprops["socialGroup"]["name"].ToString();
                        //gsi.Community_Thumbnail = dprops["socialGroup"]["thumbnailSmallImageUrl"].ToString();
                    }
                    gsi.Status = "ok";
                }
            }
            catch (WebException Ex)
            {
                DebugWrite.WriteWebln(nameof(GetStreamInfo2Async), Ex);
                gsi.Error = Ex.Status.ToString();
                return(gsi);
            }
            catch (Exception Ex) //その他のエラー
            {
                DebugWrite.Writeln(nameof(GetStreamInfo2Async), Ex);
                gsi.Error = Ex.Message;
                return(gsi);
            }

            return(gsi);
        }
Exemplo n.º 10
0
        public async Task <IList <GetStreamInfo> > ReadCateApiAsync(string url, string cate, DateTime now)
        {
            var min_time = now.AddMinutes(-8);
            //var max_time = now.AddMinutes(5);
            var lgsi = new List <GetStreamInfo>();

            if (string.IsNullOrEmpty(url))
            {
                return(lgsi);
            }

            try
            {
                var i       = 0;
                var end_flg = false;
                while (i < 9 && end_flg == false)
                {
                    var cateurl = string.Format(url, cate, i.ToString());
                    var xhtml   = await _wc.DownloadStringTaskAsync(cateurl).Timeout(_wc.timeout);

                    if (string.IsNullOrEmpty(xhtml))
                    {
                        break;
                    }

                    var data = JObject.Parse(xhtml);
                    if ((string )data["meta"]["status"] != "200" ||
                        data["data"].Count() < 1)
                    {
                        end_flg = true; break;
                    }
                    foreach (var item in data["data"])
                    {
                        if ((string )item["liveCycle"] != "ON_AIR")
                        {
                            continue;
                        }
                        var gsi = new GetStreamInfo();
                        gsi.Title      = (string )item["title"];
                        gsi.LiveId     = (string )item["id"];
                        gsi.Col12      = GetUnixMsecToDateTime(item["beginAt"].ToString());
                        gsi.Start_Time = gsi.Col12.ToString();
                        Debug.WriteLine(gsi.LiveId + ": " + gsi.Start_Time.ToString());
                        gsi.Description         = "";
                        gsi.Community_Thumbnail = (string )item["socialGroup"]["thumbnailUrl"];
                        gsi.Community_Title     = (string )item["socialGroup"]["name"];
                        gsi.Community_Id        = (string )item["socialGroup"]["id"];
                        gsi.Community_Only      = item["isFollowerOnly"].ToString().ToLower();
                        gsi.Provider_Type       = (string )item["providerType"];
                        gsi.Provider_Name       = (string )item["programProvider"]["name"];
                        gsi.Provider_Id         = "";
                        if ((string )item["providerType"] == "community")
                        {
                            gsi.Provider_Id = (string )item["programProvider"]["id"];
                        }
                        gsi.Col15 = cate;
                        if (gsi.Col12 < min_time)
                        {
                            end_flg = true; break;
                        }
                        lgsi.Add(gsi);
                    }
                    i++;
                    await Task.Delay(1000);
                }
            }
            catch (WebException Ex)
            {
                DebugWrite.WriteWebln(nameof(ReadCateApiAsync), Ex);
                return(lgsi);
            }
            catch (Exception Ex) //その他のエラー
            {
                DebugWrite.Writeln(nameof(ReadCateApiAsync), Ex);
                return(lgsi);
            }
            return(lgsi);
        }