private string getPageSourceFromNewCookie() { CookieGetter _cg = null; Task <CookieContainer[]> _cgtask = null; while (rm.rfu == rfu) { try { _cg = new CookieGetter(rm.cfg); _cgtask = _cg.getHtml5RecordCookie(url, isSub); _cgtask.Wait(); if (_cgtask == null || _cgtask.Result == null) { System.Threading.Thread.Sleep(3000); continue; } //container = _cgtask.Result[(isSub) ? 1 : 0]; container = _cgtask.Result[0]; return(_cg.pageSource); } catch (Exception e) { util.debugWriteLine(e.Message + " " + e.StackTrace); System.Threading.Thread.Sleep(3000); } // var _c = new System.Net.WebHeaderCollection(); // return util.getPageSource(url, ref _c, container); } return(""); }
public bool isEndedProgram() { var isPass = (DateTime.Now - lastEndProgramCheckTime < TimeSpan.FromSeconds(5)); addDebugBuf("ispass " + isPass + " lastendprogramchecktime " + lastEndProgramCheckTime); if (isPass) { return(false); } lastEndProgramCheckTime = DateTime.Now; var a = new System.Net.WebHeaderCollection(); var res = util.getPageSource(h5r.url, ref a, container); addDebugBuf("isendedprogram url " + h5r.url + " res==null " + (res == null)); if (res == null) { return(false); } if (res.IndexOf("user.login_status = 'not_login'") > -1) { addDebugBuf("isendprogram not login"); var cg = new CookieGetter(rm.cfg); var cgTask = cg.getHtml5RecordCookie(h5r.url, isSub); cgTask.Wait(); container = cgTask.Result[0]; res = util.getPageSource(h5r.url, container, null, false, 5000); res = System.Web.HttpUtility.HtmlDecode(res); var _webSocketInfo = h5r.getWebSocketInfo(res, isRtmp, rm.form, rm.form.getLatencyText(), rfu.wssUrl); isNoPermission = true; addDebugBuf("isendprogram login websocketInfo " + webSocketInfo[0] + " " + webSocketInfo[1]); if (_webSocketInfo[0] == null || _webSocketInfo[1] == null) { addDebugBuf(res); } else { webSocketInfo = _webSocketInfo; } return(false); } if (res == null) { return(false); } var type = util.getPageType(res); addDebugBuf("is ended program pagetype " + type); var isEnd = (type == 7 || type == 2 || type == 3 || type == 9); return(isEnd); }
async void loginBtn_Click(object sender, EventArgs e) { var cg = new rec.CookieGetter(cfg); var cc = await cg.getAccountCookie(mailText.Text, passText.Text); if (cc == null) { MessageBox.Show("login error", "", MessageBoxButtons.OK); return; } if (cc.GetCookies(TargetUrl)["user_session"] == null && cc.GetCookies(TargetUrl)["user_session_secure"] == null) { MessageBox.Show("no login", "", MessageBoxButtons.OK); } else { MessageBox.Show("login ok", "", MessageBoxButtons.OK); } //MessageBox.Show("aa"); }
private string getPageSourceFromNewCookie() { while (rm.rfu == rfu) { try { var _cg = new CookieGetter(rm.cfg); var _cgtask = _cg.getHtml5RecordCookie(url); _cgtask.Wait(); if (_cgtask == null || _cgtask.Result == null) { System.Threading.Thread.Sleep(3000); continue; } container = _cgtask.Result[0]; return(_cg.pageSource); } catch (Exception e) { util.debugWriteLine(e.Message + " " + e.StackTrace); System.Threading.Thread.Sleep(3000); } } return(""); }
private CookieContainer getCookie() { try { var url = "https://live2.nicovideo.jp/watch/" + lvid; for (var i = 0; i < 3; i++) { var cg = new CookieGetter(rm.cfg); var cgret = cg.getHtml5RecordCookie(url, true); cgret.Wait(); if (cgret == null || cgret.Result == null || cgret.Result[0] == null) { System.Threading.Thread.Sleep(1000); continue; } return(cgret.Result[0]); } } catch (Exception e) { util.debugWriteLine(e.Message + e.Source + e.StackTrace + e.TargetSite); } return(null); }
private void resetWebsocketInfo() { try { var cg = new CookieGetter(rm.cfg); var cgTask = cg.getHtml5RecordCookie(h5r.url, isSub); cgTask.Wait(); container = cgTask.Result[0]; var res = util.getPageSource(h5r.url, container, null, false, 5000); res = System.Web.HttpUtility.HtmlDecode(res); var _webSocketInfo = h5r.getWebSocketInfo(res, isRtmp, rm.form, rm.form.getLatencyText(), rfu.wssUrl); isNoPermission = true; addDebugBuf("resetWebsocketInfo " + _webSocketInfo[0] + " " + _webSocketInfo[1]); if (_webSocketInfo[0] == null || _webSocketInfo[1] == null) { addDebugBuf(res); } else { webSocketInfo = _webSocketInfo; } } catch (Exception e) { addDebugBuf("resetWebsocketInfo exception " + e.Message + e.Source + e.StackTrace + e.TargetSite); } }
private int getPageAfterFollow(string url, string lvid, ref JikkenRecorder jr, out CookieContainer cc) { Uri TargetUrl = new Uri("https://live.nicovideo.jp"); Uri TargetUrl2 = new Uri("https://live2.nicovideo.jp"); for (int i = 0; this == rm.rfu; i++) { try { var cg = new CookieGetter(rm.cfg); var cgret = cg.getHtml5RecordCookie(url); cgret.Wait(); if (cgret == null || cgret.Result == null) { System.Threading.Thread.Sleep(1000); continue; } cc = cgret.Result[0]; /* * var wc = new WebHeaderCollection(); * var referer = "http://live.nicovideo.jp/gate/" + lvid; * container.Add(TargetUrl, new Cookie("_gali", "jsFollowingAdMain")); * container.Add(TargetUrl2, new Cookie("_gali", "jsFollowingAdMain")); * // container.Add(TargetUrl, new Cookie("_gali", "all")); * // container.Add(TargetUrl2, new Cookie("_gali", "all")); * * res = util.getPageSource(url + "?ref=grel", ref wc, container, ""); * * var pagetype = util.getPageType(res); */ // var pagetype = getPageType(url + "?ref=grel"); // if (pagetype != 5) return pagetype; // if (res.IndexOf("会場のご案内") < 0) break; var _url = "https://live2.nicovideo.jp/watch/" + lvid; var req = (HttpWebRequest)WebRequest.Create(_url + "?ref=grel"); req.Proxy = util.httpProxy; req.AllowAutoRedirect = true; // req.Headers = getheaders; req.Referer = "https://live.nicovideo.jp/gate/" + lvid; req.Headers.Add("Accept-Encoding", "gzip,deflate"); req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; //var ccInd = (isSub) ? 1 : 0; //var ccInd = 0; cc.Add(TargetUrl, new Cookie("_gali", "box" + lvid)); if (cc != null) { req.CookieContainer = cc; } using (var _res = (HttpWebResponse)req.GetResponse()) using (var dataStream = _res.GetResponseStream()) using (var reader = new StreamReader(dataStream)) { res = reader.ReadToEnd(); var getheaders = _res.Headers; var resCookie = _res.Cookies; } isJikken = res.IndexOf("siteId":"nicocas") > -1; int pagetype; // if (isRtmp) pagetype = getRtmpPageType(res, isSub, out rr, cc); //pagetype = (isJikken) ? getJikkenPageType(res, out jr, cc) : util.getPageType(res); pagetype = (isJikken) ? 0 : util.getPageType(res); if (!isJikken && pagetype != 5 && pagetype != 9 && pagetype != 4) { return(pagetype); } if (isJikken && pagetype != 4) { return(pagetype); } util.debugWriteLine(i); } catch (Exception e) { util.debugWriteLine(e.Message + " " + e.StackTrace); } System.Threading.Thread.Sleep(3000); } cc = null; return(-1); }
public int getPageType(string url, bool isLogin, ref JikkenRecorder jr, out CookieContainer cc) { var dt = DateTime.Now; var isFirst = true; CookieGetter.isLoginCheck = true; while (this == rm.rfu) { try { if (isLogin && DateTime.Now - dt > TimeSpan.FromSeconds(15)) { // cc = null; // return -1; } if (isRtmpMain) { url = url.Replace("live2.nicovideo.jp", "live.nicovideo.jp"); } var cg = new CookieGetter(rm.cfg); var cgret = cg.getHtml5RecordCookie(url); cgret.Wait(); CookieGetter.isLoginCheck = false; //if (isSub && cg.id != null) id[1] = cg.id; if (cg.id != null) { id[0] = cg.id; } if (id[0] != null && id[1] != null && id[0] == id[1]) { rm.form.addLogText("メインアカウントとサブアカウントのIDが同じでした"); util.debugWriteLine("メインアカウントとサブアカウントのIDが同じでした"); cc = null; return(-2); } // cgret.ConfigureAwait(false); if (cgret == null || cgret.Result[0] == null) { util.debugWriteLine("cgret " + cgret); if (isLogin && isFirst) { rm.form.addLogText(cg.log); // rm.form.addLogText("ログインに失敗しました。"); isFirst = false; } if (bool.Parse(rm.cfg.get("IsdeleteExit"))) { cc = null; rm.rfu = null; rm.form.close(); return(2); } if (cg.reason != null) { cc = null; if (cg.reason == "not_login") { rm.form.formAction(() => MessageBox.Show("ログインに失敗しました。\n" + lvid)); } return(-1); } System.Threading.Thread.Sleep(3000); continue; } // if (cgret == null) return true; cc = cgret.Result[0]; util.debugWriteLine("container " + cc); res = cg.pageSource; // Uri TargetUrl = new Uri("http://live.nicovideo.jp/"); // util.debugWriteLine("1 " + container.GetCookieHeader(TargetUrl)); // TargetUrl = new Uri("http://live2.nicovideo.jp/"); // util.debugWriteLine("2 " + container.GetCookieHeader(TargetUrl)); //if (res.IndexOf("siteId":"nicolive2") > -1) { // if (isRtmp) return getRtmpPageType(res, isSub, out rr, cc); if (isRtmpMain) { //if (res.IndexOf("%3Cgetplayerstatus%20") > -1) { if (res.IndexOf("player_type = null") > -1) { if (res.IndexOf("\"timeshift_reservation") > -1) { return(9); } else if (res.IndexOf("\"Nicolive.WatchingReservation.confirm") > -1) { return(10); } return(2); } else if (res.IndexOf("player_type = 'flash'") > -1 && res.IndexOf("%3Cgetplayerstatus%20") > -1) { var _res = util.getRegGroup(res, "(%3Cgetplayerstatus%20.+?%3C%2Fgetplayerstatus%3E)"); _res = System.Net.WebUtility.UrlDecode(_res); var isTimeShift = true; var ret = util.getPageTypeRtmp(_res, ref isTimeShift, false); //isRtmpMain = true; return(ret); } else if (res.IndexOf("<!doctype html>") == -1) { var __url = "http://live.nicovideo.jp/api/getplayerstatus?v=" + lvid; var __res = util.getPageSource(__url, cc); var isTimeShift = true; var ret = util.getPageTypeRtmp(__res, ref isTimeShift, false); res += __res; return(ret); } } var isJikken = res.IndexOf("siteId":"nicocas") > -1; if (isJikken) { //実験放送なくし //return getJikkenPageType(res, out jr, cc); } else { var _pageType = util.getPageType(res); util.debugWriteLine(_pageType); return(_pageType); } } catch (Exception e) { util.debugWriteLine(e.Message + " " + e.StackTrace); System.Threading.Thread.Sleep(3000); if (isLogin) { rm.form.addLogText("ページの取得に失敗しました。"); isLogin = false; } } } cc = null; return(5); }
private string getProcessArgs(bool isRtmp2, bool isFirst) { testDebugWriteLine("getProcessArgs"); if (isRtmp2) { if (!isFirst && ((WebSocketRecorder)wr).isEndedProgram()) { return("end"); } var ret = "-vr " + rtmpUrl + " "; rm.hlsUrl = ret; ret += "-o \"" + util.getOkSJisOut(recFolderFile) + ".flv\""; util.debugWriteLine("getProcessArgs rtmp2Url exist " + ret); return(ret); } var url = "https://live.nicovideo.jp/api/getplayerstatus/" + lvid; while (rm.rfu == rfu && retryMode == 0 ) { var res = util.getPageSource(url, container, null, false, 3000); util.debugWriteLine(res + util.getMainSubStr(isSub, true)); if (res == null) { Task.Run(() => isEndedProgram()); Thread.Sleep(3000); testDebugWriteLine("getplayerstatus取得失敗"); continue; } if (res.IndexOf("<code>notlogin</code>") > -1) { var c = new CookieGetter(rm.cfg); var t = c.getHtml5RecordCookie(rfu.url); t.Wait(); if (t.Result != null && t.Result[0] != null) { container = t.Result[0]; } testDebugWriteLine("getplayerstatus not login"); continue; } var pageType = util.getPageTypeRtmp(res, ref isTimeshift, isSub); testDebugWriteLine("getplayerstatus 取得 " + pageType); if (pageType == 1) { Thread.Sleep(90000); continue; } if (!wr.isTimeShift && (pageType == 7 || pageType == 2)) { retryMode = 2; //test rm.form.addLogText(pageType + " " + res); return("end"); } if (pageType == 2 || pageType == 3) { return("no"); } if (pageType != 0 && pageType != 7) { Thread.Sleep(3000); continue; } var xml = new XmlDocument(); xml.LoadXml(res); // util.debugWriteLine(container.GetCookieHeader(new Uri(url))); var type = util.getRegGroup(res, "<provider_type>(.+?)</provider_type>"); // string rtmpurl = null, ticket = null; getTicketUrl(out rtmpUrl, out ticket); if (ticket == null) { Thread.Sleep(3000); continue; } var arg = getArgFromRes(xml, pageType, type, ticket, rtmpUrl); if (arg.IndexOf("?invalid") > -1) { Thread.Sleep(60000); continue; } testDebugWriteLine("rtmpdump 引数取得 " + ((arg == null) ? "失敗" : "成功")); if (arg == null) { continue; } return(arg); } Thread.Sleep(3000); return(null); }
public int getPageType(string url, bool isLogin, bool isSub, ref JikkenRecorder jr, out CookieContainer cc) { var dt = DateTime.Now; var isFirst = true; while (this == rm.rfu) { try { if (isLogin && DateTime.Now - dt > TimeSpan.FromSeconds(15)) { cc = null; return(-1); } if (isRtmpMain) { url = url.Replace("live2.nicovideo.jp", "live.nicovideo.jp"); } var cg = new CookieGetter(rm.cfg); var cgret = cg.getHtml5RecordCookie(url, isSub); cgret.Wait(); if (isSub && cg.id != null) { id[1] = cg.id; } if (!isSub && cg.id != null) { id[0] = cg.id; } if (id[0] != null && id[1] != null && id[0] == id[1]) { rm.form.addLogText("メインアカウントとサブアカウントのIDが同じでした"); util.debugWriteLine("メインアカウントとサブアカウントのIDが同じでした"); cc = null; return(-2); } // cgret.ConfigureAwait(false); if (cgret == null || cgret.Result[0] == null) { util.debugWriteLine("cgret " + cgret); if (isLogin && isFirst) { rm.form.addLogText(cg.log); // rm.form.addLogText("ログインに失敗しました。"); isFirst = false; } System.Threading.Thread.Sleep(3000); continue; } // if (cgret == null) return true; cc = cgret.Result[0]; util.debugWriteLine("container " + cc); res = cg.pageSource; // Uri TargetUrl = new Uri("http://live.nicovideo.jp/"); // util.debugWriteLine("1 " + container.GetCookieHeader(TargetUrl)); // TargetUrl = new Uri("http://live2.nicovideo.jp/"); // util.debugWriteLine("2 " + container.GetCookieHeader(TargetUrl)); //if (res.IndexOf("siteId":"nicolive2") > -1) { // if (isRtmp) return getRtmpPageType(res, isSub, out rr, cc); if (isRtmpMain) { if (res.IndexOf("%3Cgetplayerstatus%20") > -1) { //if (res.IndexOf("<getplayerstatus status=\"ok\"") > -1) { var _res = util.getRegGroup(res, "(%3Cgetplayerstatus%20.+?%3C%2Fgetplayerstatus%3E)"); _res = System.Net.WebUtility.UrlDecode(_res); //var _res = res; var isTimeShift = true; if (_res == null) { continue; } var ret = util.getPageTypeRtmp(_res, ref isTimeShift, false); return(ret); } } var isJikken = res.IndexOf("siteId":"nicocas") > -1; if (isJikken) { return(getJikkenPageType(res, isSub, out jr, cc)); } else { var _pageType = util.getPageType(res); util.debugWriteLine(_pageType); return(_pageType); } } catch (Exception e) { util.debugWriteLine(e.Message + " " + e.StackTrace); System.Threading.Thread.Sleep(3000); if (isLogin) { rm.form.addLogText("ページの取得に失敗しました。"); isLogin = false; } } } cc = null; return(5); /* * var req = (HttpWebRequest)HttpWebRequest.Create(url); * req.Timeout = 15000; * req.CookieContainer = this.container; * req.AllowAutoRedirect = false; * * var res = (HttpWebResponse)req.GetResponse(); * return (res.Headers.Get("Location") == null) ? false : true; */ }
private bool join(string comId, CookieContainer cc, MainForm form, config.config cfg, bool isPlayOnlyMode) { for (int i = 0; i < 5; i++) { //var myPageUrl = "https://www.nicovideo.jp/my"; var comUrl = "https://com.nicovideo.jp/community/" + comId; var url = "https://com.nicovideo.jp/motion/" + comId; var headers = new WebHeaderCollection(); headers.Add("Upgrade-Insecure-Requests", "1"); headers.Add("User-Agent", util.userAgent); try { var cg = new CookieGetter(cfg); var cgret = cg.getHtml5RecordCookie(url); cgret.Wait(); // cgret.ConfigureAwait(false); if (cgret == null || cgret.Result == null) { System.Threading.Thread.Sleep(3000); continue; } var _cc = cgret.Result[0]; // var _cc = cgret.Result[(isSub) ? 1 : 0]; // util.debugWriteLine(cg.pageSource); var res = util.getPageSource(url, _cc, comUrl); var isJidouShounin = res.IndexOf("自動承認されます") > -1; // var _compage = util.getPageSource(url, ref headers, cc); // var gateurl = "http://live.nicovideo.jp/gate/lv313793991"; // var __gatePage = util.getPageSource(gateurl, ref headers, cc); // var _compage2 = util.getPageSource(url, ref headers, cc); // util.debugWriteLine(cc.GetCookieHeader(new Uri(url))); var msg = (isJidouShounin ? "フォローを試みます。" : "自動承認ではありませんでした。"); form.addLogText(msg); if (!isJidouShounin) { return(false); } } catch (Exception e) { util.debugWriteLine(e.Message + e.Source + e.StackTrace + e.TargetSite); return(false); } try { var handler = new System.Net.Http.HttpClientHandler(); handler.UseCookies = true; handler.CookieContainer = cc; handler.Proxy = util.httpProxy; var http = new System.Net.Http.HttpClient(handler); http.DefaultRequestHeaders.Referrer = new Uri(url); var content = new System.Net.Http.FormUrlEncodedContent(new Dictionary <string, string> { { "mode", "commit" }, { "title", "フォローリクエスト" } }); var enc = Encoding.GetEncoding("UTF-8"); string data = "mode=commit&title=" + System.Web.HttpUtility.UrlEncode("フォローリクエスト", enc); byte[] postDataBytes = Encoding.ASCII.GetBytes(data); var req = (HttpWebRequest)WebRequest.Create(url); req.Method = "POST"; req.Proxy = util.httpProxy; req.CookieContainer = cc; req.Referer = url; req.ContentLength = postDataBytes.Length; req.ContentType = "application/x-www-form-urlencoded"; req.Headers.Add("Accept-Encoding", "gzip,deflate"); req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; // req.Headers.Add("Referer", url); using (var stream = req.GetRequestStream()) { try { stream.Write(postDataBytes, 0, postDataBytes.Length); } catch (Exception e) { util.debugWriteLine(e.Message + " " + e.StackTrace + " " + e.Source + " " + e.TargetSite); } } // stream.Close(); var res = req.GetResponse(); using (var resStream = new System.IO.StreamReader(res.GetResponseStream())) { var resStr = resStream.ReadToEnd(); var isSuccess = resStr.IndexOf("フォローしました") > -1; var _m = (isPlayOnlyMode) ? "視聴" : "録画"; form.addLogText((isSuccess ? "フォローしました。" + _m + "開始までしばらくお待ちください。" : "フォローに失敗しました。")); return(isSuccess); } // resStream.Close(); // Task<HttpResponseMessage> _resTask = http.PostAsync(url, content); // _resTask.Wait(); // var _res = _resTask.Result; // var resTask = _res.Content.ReadAsStringAsync(); // resTask.Wait(); // var res = resTask.Result; // var a = _res.Headers; // if (res.IndexOf("login_status = 'login'") < 0) return null; // var cc = handler.CookieContainer; } catch (Exception e) { form.addLogText("フォローに失敗しました。"); util.debugWriteLine(e.Message + e.StackTrace); continue; // return false; } } form.addLogText("フォローに失敗しました。"); util.debugWriteLine("フォロー失敗"); return(false); }