示例#1
0
        public void start()
        {
            container = getCookie();
            if (container == null)
            {
                rm.form.addLogText("補完用アカウントにログインできませんでした");
                return;
            }
            var res = getRes();

            if (res == null)
            {
                rm.form.addLogText("補完用アカウントでページを取得できませんでした");
                return;
            }
            var isChasable = util.getRegGroup(res, ""permissions":\\[[^\\]]*(CHASE_PLAY)") != null &&
                             res.IndexOf("isChasePlayEnabled":true") > -1;

            if (!isChasable)
            {
                rm.form.addLogText("補完用アカウントで追っかけ再生を取得できませんでした");
                return;
            }

            wr = getWebsocketRecorder(res);
            if (wr == null)
            {
                rm.form.addLogText("補完の設定に失敗しました");
            }
            try {
                wr.start();
                if (wr.isEndProgram)
                {
                    //rm.form.addLogText("補完を完了しました " + util.getRegGroup(name, ".+_(.*)"));
                    var _name = wr.rec.recFolderFile != null ? wr.rec.recFolderFile : name[0];
                    rm.form.addLogText("補完を完了しました " + _name);
                    return;
                }
            } catch (Exception e) {
                util.debugWriteLine(e.Message + e.Source + e.StackTrace + e.TargetSite);
            }
            rm.form.addLogText("補完に失敗しました");
        }
        private int html5Record(string res, bool isRtmp, int pageType)
        {
            //webSocketInfo 0-wsUrl 1-request
            //recFolderFileInfo host, group, title, lvid, communityNum
            //return 0-end stream 1-stop

            string[] webSocketRecInfo;
            recFolderFileInfo = null;


            var isNoPermission = false;

            while (rm.rfu == rfu)
            {
                var type           = util.getRegGroup(res, "\"content_type\":\"(.+?)\"");
                var data           = util.getRegGroup(res, "<script id=\"embedded-data\" data-props=\"([\\d\\D]+?)</script>");
                var isRtmpOnlyPage = res.IndexOf("%3Cgetplayerstatus%20") > -1 || res.IndexOf("<getplayerstatus ") > -1;
                if (isRtmpOnlyPage)
                {
                    isRtmp = true;
                }
                var isChasable = util.getRegGroup(res, "&quot;permissions&quot;:\\[[^\\]]*(CHASE_PLAY)") != null &&
                                 res.IndexOf("isChasePlayEnabled&quot;:true") > -1;
                var isChaseCheck = rm.form.isChaseChkBtn.Checked;
                if (isChaseCheck && (!isChasable || pageType != 0))
                {
                    rm.form.addLogText("追いかけ再生ができませんでした");
                    return(3);
                }
                //util.debugWriteLine(data);

                var isChase = isChaseRec(isChaseCheck, isChasable, data) && !isRtmp;
                if (isChase && !isRtmp)
                {
                    isTimeShift = true;
                }

                //;,&quot;permissions&quot;:[&quot;CHASE_PLAY&quot;],&quot;
                //var pageType = util.getPageType(res);
//				var pageType = pageType;
                util.debugWriteLine("pagetype " + pageType + " isChase" + isChase);

                if ((data == null && !isRtmpOnlyPage) || (pageType != 0 && pageType != 7))
                {
                    //processType 0-ok 1-retry 2-放送終了 3-その他の理由の終了
                    var processType = processFromPageType(pageType);
                    util.debugWriteLine("processType " + processType);
                    //if (processType == 0 || processType == 1) continue;
                    if (processType == 2)
                    {
                        return(3);
                    }
//					if (processType == 3) return 0;

                    System.Threading.Thread.Sleep(3000);

                    res = getPageSourceFromNewCookie();

                    continue;
                }

                data = (isRtmpOnlyPage) ? System.Web.HttpUtility.UrlDecode(res) :
                       System.Web.HttpUtility.HtmlDecode(data);

                long endTime, _openTime, serverTime, vposBaseTime;
//				DateTime programTime, jisa;
                openTime = endTime = _openTime = serverTime = vposBaseTime = 0;

                if (!getTimeInfo(data, ref openTime, ref endTime,
                                 ref _openTime, ref serverTime, ref vposBaseTime, isRtmpOnlyPage))
                {
                    return(3);
                }

                var programTime = util.getUnixToDatetime(endTime) - util.getUnixToDatetime(openTime);
                var jisa        = util.getUnixToDatetime(serverTime / 1000) - DateTime.Now;

                isFmp4 = data.IndexOf("\"providerType\":\"community\"") > -1 &&
                         pageType == 0 && !isTimeShift && false;

                //0-wsUrl 1-request
                webSocketRecInfo = getWebSocketInfo(data, isRtmp, isChase, isTimeShift, rm.form, isFmp4);
                util.debugWriteLine("websocketrecinfo " + webSocketRecInfo);
                if (!isRtmpOnlyPage && webSocketRecInfo == null)
                {
                    break;
                }

                util.debugWriteLine("isnopermission " + isNoPermission);
//				if (isNoPermission) webSocketRecInfo[1] = webSocketRecInfo[1].Replace("\"requireNewStream\":false", "\"requireNewStream\":true");
                recFolderFileInfo = getHtml5RecFolderFileInfo(data, type, isRtmpOnlyPage);


                //timeshift option
                timeShiftConfig = null;
                if (((isTimeShift && !isChase) || isChaseCheck) && !isRtmp)
                {
//						if (rm.ri != null) timeShiftConfig = rm.ri.tsConfig;
                    if (rm.argTsConfig != null)
                    {
                        timeShiftConfig = getReadyArgTsConfig(rm.argTsConfig.clone(), recFolderFileInfo[0], recFolderFileInfo[1], recFolderFileInfo[2], recFolderFileInfo[3], recFolderFileInfo[4], recFolderFileInfo[5], openTime, (int)(openTime - _openTime));
                    }
                    else
                    {
                        timeShiftConfig = getTimeShiftConfig(recFolderFileInfo[0], recFolderFileInfo[1], recFolderFileInfo[2], recFolderFileInfo[3], recFolderFileInfo[4], recFolderFileInfo[5], rm.cfg, openTime, isChase, _openTime);
                        if (timeShiftConfig == null)
                        {
                            return(2);
                        }
//							rm.cfg.set("IsUrlList", timeShiftConfig.isOutputUrlList.ToString().ToLower());
//							rm.cfg.set("openUrlListCommand", timeShiftConfig.openListCommand);
                    }
                }
                if (!isChaseCheck && isChase)
                {
                    timeShiftConfig = new TimeShiftConfig();
                }

                var isRealtimeChase = isChase && !isChaseCheck &&
                                      !(rm.form.args.Length > 0 && bool.Parse(rm.cfg.get("IsArgChaseRecFromFirst")));

                if (!rfu.isPlayOnlyMode)
                {
                    util.debugWriteLine("rm.rfu " + rm.rfu.GetHashCode() + " rfu " + rfu.GetHashCode());
                    if (recFolderFile == null)
                    {
                        recFolderFile = getRecFilePath(isRtmp);
                    }
                    if (recFolderFile == null || recFolderFile[0] == null)
                    {
                        //パスが長すぎ
                        rm.form.addLogText("パスに問題があります。 " + (recFolderFile != null ? recFolderFile[1] : ""));
                        util.debugWriteLine("too long path? " + (recFolderFile != null ? recFolderFile[1] : ""));
                        return(2);
                    }
                }
                else
                {
                    var fName = "a/" + util.getFileName(recFolderFileInfo[0], recFolderFileInfo[1], recFolderFileInfo[2], recFolderFileInfo[3], recFolderFileInfo[4], rm.cfg, openTime);
                    recFolderFile = new String[] { fName, fName, fName };                 //new string[]{"", "", ""};
                }

                //display set
                var rss = new RecordStateSetter(rm.form, rm, rfu, isTimeShift, false, recFolderFile, rfu.isPlayOnlyMode, isRtmpOnlyPage, isChase);
                Task.Run(() => {
                    rss.set(data, type, recFolderFileInfo);

                    //hosoInfo
                    if (rm.cfg.get("IshosoInfo") == "true" && !rfu.isPlayOnlyMode)
                    {
                        rss.writeHosoInfo();
                    }
                });

                util.debugWriteLine("form disposed" + rm.form.IsDisposed);
                util.debugWriteLine("recfolderfile test " + recFolderFileInfo);

                var fileName = System.IO.Path.GetFileName(recFolderFile[1]);
                rm.form.setTitle(fileName);


//				if (recFolderFile == null) continue;

                for (int i = 0; i < recFolderFile.Length; i++)
                {
                    util.debugWriteLine("recd " + i + " " + recFolderFileInfo[i]);
                }


                var userId = util.getRegGroup(res, "\"user\"\\:\\{\"user_id\"\\:(.+?),");
                if (userId == "null")
                {
                    userId = "guest";
                    rm.form.addLogText("非ログインで開始を試みます");
                }
                var isPremium = res.IndexOf("\"member_status\":\"premium\"") > -1;
                wsr    = new WebSocketRecorder(webSocketRecInfo, container, recFolderFile, rm, rfu, this, openTime, isTimeShift, lvid, timeShiftConfig, userId, isPremium, programTime, type, _openTime, isRtmp, isRtmpOnlyPage, isChase, isRealtimeChase, true, rss, vposBaseTime);
                rm.wsr = wsr;
                try {
                    isNoPermission = wsr.start();

                    if (rm.cfg.get("fileNameType") == "10" && (recFolderFile[1].IndexOf("{w}") > -1 || recFolderFile[1].IndexOf("{c}") > -1))
                    {
                        renameStatistics(rss);
                    }

                    rm.wsr = null;
                    if (wsr.isEndProgram)
                    {
                        if ((!isTimeShift || isChase) && rss.isWrite)
                        {
                            rss.writeEndTime(container, wsr.endTime);
                        }
                        return(3);
                    }
                } catch (Exception e) {
                    rm.form.addLogText("録画中に予期せぬ問題が発生しました " + e.Message + e.StackTrace + e.Source + e.TargetSite);
                    util.debugWriteLine("wsr start exception " + e.Message + e.StackTrace);
                }


                util.debugWriteLine(rm.rfu + " " + rfu + " " + (rm.rfu == rfu));
                if (rm.rfu != rfu || isRtmp)
                {
                    break;
                }

                res = getPageSourceFromNewCookie();
            }
            return(1);
        }
示例#3
0
        async private Task <int> html5Record(string res, bool isRtmp, int pageType)
        {
            //webSocketInfo 0-wsUrl 1-request
            //recFolderFileInfo host, group, title, lvid, communityNum
            //return 0-end stream 1-stop

            //		List<Cookie> cookies = context.getCookieStore().getCookies();
            //		for (Cookie cookie : cookies) System.out.println(cookie.getName() + " " + cookie.getValue());


            //		ExecutorService exec = Executors.newFixedThreadPool(1);



            string[] webSocketRecInfo;
            recFolderFileInfo = null;
            string[] recFolderFile = null;

//			Task displayTask = null;
//			var pageType = util.getPageType(res);
//			util.debugWriteLine("pagetype " + pageType);

            var lastSegmentNo = -1;

            var isNoPermission = false;

            while (rm.rfu == rfu)
            {
                var type = util.getRegGroup(res, "\"content_type\":\"(.+?)\"");
                var data = util.getRegGroup(res, "<script id=\"embedded-data\" data-props=\"([\\d\\D]+?)</script>");

                var isRtmpOnlyPage = res.IndexOf("%3Cgetplayerstatus%20") > -1;
                if (isRtmpOnlyPage)
                {
                    isRtmp = true;
                }
                if (isRtmpOnlyPage && isTimeShift)
                {
                    rm.hlsUrl = "timeshift";
                }
                //var pageType = util.getPageType(res);
//				var pageType = pageType;
                util.debugWriteLine("pagetype " + pageType + util.getMainSubStr(isSub));

                if (((data == null && !isRtmpOnlyPage) || (pageType != 0 && pageType != 7)) && url.IndexOf("wss://") == -1)
                {
                    //processType 0-ok 1-retry 2-放送終了 3-その他の理由の終了
                    var processType = processFromPageType(pageType);
                    util.debugWriteLine("processType " + processType + util.getMainSubStr(isSub));
                    //if (processType == 0 || processType == 1) continue;
                    if (processType == 2)
                    {
                        return(3);
                    }
//					if (processType == 3) return 0;

                    System.Threading.Thread.Sleep(3000);

                    res = getPageSourceFromNewCookie();

                    continue;
                }

                data = (isRtmpOnlyPage) ? System.Web.HttpUtility.UrlDecode(res) :
                       System.Web.HttpUtility.HtmlDecode(data);

                long endTime, _openTime, serverTime;
//				DateTime programTime, jisa;
                openTime = endTime = _openTime = serverTime = 0;

                if (rfu.wssUrl == null && !getTimeInfo(data, ref openTime, ref endTime,
                                                       ref _openTime, ref serverTime, isRtmpOnlyPage))
                {
                    return(3);
                }

                var programTime = util.getUnixToDatetime(endTime) - util.getUnixToDatetime(openTime);
                var jisa        = util.getUnixToDatetime(serverTime / 1000) - DateTime.Now;
                //			util.debugWriteLine(data);
                var latency = rm.form.getLatencyText();

                //0-wsUrl 1-request
                webSocketRecInfo = getWebSocketInfo(data, isRtmp, rm.form, latency, rfu.wssUrl);
                util.debugWriteLine("websocketrecinfo " + webSocketRecInfo);
                if (webSocketRecInfo == null && !isRtmpOnlyPage)
                {
                    continue;
                }

                util.debugWriteLine("isnopermission " + isNoPermission);
//				if (isNoPermission) webSocketRecInfo[1] = webSocketRecInfo[1].Replace("\"requireNewStream\":false", "\"requireNewStream\":true");
                //recFolderFileInfo = getHtml5RecFolderFileInfo(data, type, isRtmpOnlyPage);

                if (!isSub)
                {
                    //timeshift option

                    timeShiftConfig = null;
                    if (isTimeShift && !isRtmpOnlyPage)
                    {
                        if (rm.argTsConfig != null)
                        {
                            timeShiftConfig = rm.argTsConfig.clone();
                        }
                        else
                        {
                            timeShiftConfig = getTimeShiftConfig(null, null, null, null, null, null, rm.cfg, 0);
                        }
                        if (timeShiftConfig == null)
                        {
                            return(2);
                        }
                    }
                    recFolderFile = new string[] { "", "", "" };
                }
                else
                {
                    recFolderFile = new string[] { "", "", "" };
                }

                var userId    = util.getRegGroup(res, "\"user\"\\:\\{\"user_id\"\\:(.+?),");
                var isPremium = res.IndexOf("\"member_status\":\"premium\"") > -1;
                var wsr       = new WebSocketRecorder(webSocketRecInfo, container, recFolderFile, rm, rfu, this, openTime, lastSegmentNo, isTimeShift, lvid, timeShiftConfig, userId, isPremium, programTime, type, _openTime, isSub, isRtmp, latency);
                rm.wsr = wsr;
                try {
                    isNoPermission = wsr.start(isRtmpOnlyPage);
                    rm.wsr         = null;
                    if (wsr.isEndProgram)
                    {
                        //return (isTimeShift) ? 1 : 3;
                        return(3);
                    }
//					if (isTimeShift && wsr.isEndProgram)
//						return 1;
                } catch (Exception e) {
                    util.debugWriteLine("wsr start exception " + e.Message + e.StackTrace);
                }

//				System.Threading.Thread.Sleep(2000);

                util.debugWriteLine(rm.rfu + " " + rfu + " " + (rm.rfu == rfu));
                if (rm.rfu != rfu || isRtmp)
                {
                    break;
                }

                res = getPageSourceFromNewCookie();
            }
            return(1);
        }