private void renameStatistics(RecordStateSetter rss)
        {
            try {
                wsr.setRealTimeStatistics();

                rss.renameStatistics(wsr.visitCount.Replace("-", ""), wsr.commentCount.Replace("-", ""));
            } catch (Exception e) {
                util.debugWriteLine(e.Message + e.Source + e.StackTrace + e.TargetSite);
            }
        }
Exemplo n.º 2
0
        public TimeShiftCommentGetter(string uri, string thread,
                                      string uriStore, string threadStore,
                                      string userId, RecordingManager rm,
                                      RecordFromUrl rfu, MainForm form,
                                      long openTime, string recFolderFile,
                                      string lvid, CookieContainer container,
                                      string programType, long _openTime,
                                      WebSocketRecorder rp, int startSecond,
                                      bool isVposStartTime, bool isRtmp,
                                      RtmpRecorder rr, RecordStateSetter rss,
                                      string roomName, TimeShiftConfig tsConfig)
        {
            this.uri    = uri;
            this.thread = thread;

            this.rm                  = rm;
            this.rfu                 = rfu;
            this.userId              = userId;
            this.form                = form;
            this.openTime            = openTime;
            this.recFolderFile       = recFolderFile;
            this.lvid                = lvid;
            this.container           = container;
            this.isGetXml            = bool.Parse(rm.cfg.get("IsgetcommentXml"));
            this.isGetCommentXmlInfo = bool.Parse(rm.cfg.get("IsgetcommentXmlInfo"));
            this.programType         = programType;
            this._openTime           = _openTime;
            this.rp                  = rp;
            this.startSecond         = startSecond;
            //this.tsConfig = tsConfig;
            this.isVposStartTime = isVposStartTime;
            this.isRtmp          = isRtmp;
            this.rr            = rr;
            isConvertSpace     = bool.Parse(rm.cfg.get("IsCommentConvertSpace"));
            isNormalizeComment = bool.Parse(rm.cfg.get("IsNormalizeComment"));
            this.roomName      = roomName;
            this.tsConfig      = tsConfig;

            this.uriStore    = uriStore;
            this.threadStore = threadStore;
        }
        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);
        }