Ejemplo n.º 1
0
        private void startRecording(string lvid, bool isPlayOnlyMode)
        {
            util.setProxy(cfg, form);
            isRecording = true;
            form.formAction(() => {
                form.urlText.Text = "https://live2.nicovideo.jp/watch/" + lvid;
                setRecModeForm(true);

                form.resetDisplay();
                recordingUrl = form.urlText.Text;
            }, false);

            rfu = new RecordFromUrl(this, isPlayOnlyMode);
            Task.Run(() => {
                try {
                    var _rfu = rfu;
                    util.debugWriteLine("rm rec 録画開始" + rfu);
                    util.debugWriteLine(form.urlText.Text);

                    var rfuCode = rfu.GetHashCode();
                    recordRunningList.Add(rfuCode);
                    //endcode 0-その他の理由 1-stop 2-最初に終了 3-始まった後に番組終了
                    var endCode = rfu.rec(form.urlText.Text, lvid);
                    util.debugWriteLine("endcode " + endCode);
                    recordRunningList.Remove(rfuCode);

                    endProcess(endCode, rfu == _rfu);
                } catch (Exception e) {
                    util.debugWriteLine(e.Message + e.Source + e.StackTrace + e.TargetSite);
                    rfu = null;
                    setRecModeForm(false);
                }
            });
        }
Ejemplo n.º 2
0
        /*
         * async Task<int> test(int a) {
         *      //util.debugWriteLine(a);
         *      //c += a;
         *      return a;
         * }
         */
        async public void rec()
        {
            util.debugWriteLine("rm");


            var lv     = util.getRegGroup(form.urlText.Text, "(lv\\d+(,\\d+)*)");
            var wssUrl = util.getRegGroup(form.urlText.Text, "^(wss://[^,\\s]+)");

            util.setLog(cfg, lv);
            util.debugWriteLine(util.versionStr + " " + util.versionDayStr);

            if (rfu == null)
            {
                var arr = form.urlText.Text.Split('|');
//              var arr = "C:\\Users\\zack\\Desktop\\c#project\\nicoNewStreamRecorderKakkoKariRepo2 9.26 tuujou a\\nicoNewStreamRecorderKakkoKari\\namaichi\\bin\\Debug\\rec\\株式会社ジャパンミュージックエージェンシー\\株式会社ジャパンミュージックエージェンシー_0.ts".Split('|');



                var lvid = lv;                //util.getRegGroup(form.urlText.Text, "(lv\\d+(,\\d+)*)", 1);
                if (lvid != null || wssUrl != null)
                {
                    var url = lvid != null ? ("http://live2.nicovideo.jp/watch/" + lvid) : wssUrl;
                    if (isPlayOnlyMode)
                    {
                        form.Invoke((MethodInvoker) delegate() {
                            form.urlText.Text = url;
                        });
                    }
                    else
                    {
                        form.urlText.Text = url;
                    }

//				if (lvid != null) form.urlText.Text = "https://cas.nicovideo.jp/user/77252622/lv313508832";
                }
                else
                {
                    if (isPlayOnlyMode)
                    {
                        form.Invoke((MethodInvoker) delegate() {
                            MessageBox.Show("not found lvid");
                        });
                    }
                    else
                    {
                        MessageBox.Show("not found lvid");
                    }
                    return;
                }

                form.setQualityList(new string[] {}, "");
                var q = form.qualityBox.Items;

                isRecording = true;
                if (isPlayOnlyMode)
                {
                    form.Invoke((MethodInvoker) delegate() {
                        form.recBtn.Text            = "中断";
                        form.urlText.Enabled        = false;
                        form.optionMenuItem.Enabled = false;

                        //form.resetDisplay();
                        recordingUrl = form.urlText.Text;
                    });
                }
                else
                {
                    form.recBtn.Text            = "中断";
                    form.urlText.Enabled        = false;
                    form.optionMenuItem.Enabled = false;

                    //form.resetDisplay();
                    recordingUrl = form.urlText.Text;
                }

                rfu = new RecordFromUrl(this);
                Task.Run(() => {
                    try {
                        var _rfu = rfu;
                        util.debugWriteLine("rm rec 録画開始" + rfu);

                        util.debugWriteLine(form);
                        util.debugWriteLine(form.urlText);
                        util.debugWriteLine(form.urlText.Text);

                        var rfuCode = rfu.GetHashCode();
                        recordRunningList.Add(rfuCode);
                        //endcode 0-その他の理由 1-stop 2-最初に終了 3-始まった後に番組終了
                        var endCode = rfu.rec(form.urlText.Text, lvid, wssUrl);
                        util.debugWriteLine("endcode " + endCode);
                        recordRunningList.Remove(rfuCode);

                        if (rfu == _rfu)
                        {
                            isRecording = false;
                            rfu         = null;
                            if (!form.IsDisposed && util.isShowWindow)
                            {
                                try {
                                    form.Invoke((MethodInvoker) delegate() {
                                        try {
                                            form.recBtn.Text            = "録画開始";
                                            form.urlText.Enabled        = true;
                                            form.optionMenuItem.Enabled = true;
                                        } catch (Exception e) {
                                            util.debugWriteLine(e.Message + " " + e.StackTrace + " " + e.Source + " " + e.TargetSite);
                                        }
                                    });
                                } catch (Exception e) {
                                    util.debugWriteLine(e.Message + " " + e.StackTrace + " " + e.Source + " " + e.TargetSite);
                                }
                            }

                            util.debugWriteLine("end rec " + rfu);
                            if (!isClickedRecBtn && endCode == 3)
                            {
                                Environment.ExitCode = 5;
                                if (util.isShowWindow)
                                {
                                    try {
                                        form.Invoke((MethodInvoker) delegate() {
                                            try {
                                                form.Close();
                                            } catch (Exception e) {
                                                util.debugWriteLine(e.Message + " " + e.StackTrace + " " + e.Source + " " + e.TargetSite);
                                            }
                                        });
                                    } catch (Exception e) {
                                        util.debugWriteLine(e.Message + " " + e.StackTrace + " " + e.Source + " " + e.TargetSite);
                                    }
                                }
                            }
                            hlsUrl = null;

                            recordingUrl = null;
                        }
                        if (bool.Parse(cfg.get("IscloseExit")) && endCode == 3)
                        {
                            rfu = null;
                            Environment.ExitCode = 5;
                            if (util.isShowWindow)
                            {
                                try {
                                    form.Invoke((MethodInvoker) delegate() {
                                        try {
                                            form.Close();
                                            form.addLogText("終了しました。");
                                        } catch (Exception e) {
                                            util.debugWriteLine(e.Message + " " + e.StackTrace + " " + e.Source + " " + e.TargetSite);
                                        }
                                    });
                                } catch (Exception e) {
                                    util.debugWriteLine(e.Message + " " + e.StackTrace + " " + e.Source + " " + e.TargetSite);
                                }
                            }
                        }
                        if (util.isStdIO && (endCode == 0 || endCode == 2 || endCode == 3))
                        {
                            form.Invoke((MethodInvoker) delegate() {
                                try {
                                    form.Close();
                                } catch (Exception e) {
                                    util.debugWriteLine(e.Message + " " + e.StackTrace + " " + e.Source + " " + e.TargetSite);
                                }
                            });
                        }
                    } catch (Exception e) {
                        util.debugWriteLine(e.Message + e.Source + e.StackTrace + e.TargetSite);
                        rfu = null;
                        form.Invoke((MethodInvoker) delegate() {
                            try {
                                form.recBtn.Text            = "録画開始";
                                form.urlText.Enabled        = true;
                                form.optionMenuItem.Enabled = true;
                            } catch (Exception ee) {
                                util.debugWriteLine(ee.Message + " " + ee.StackTrace + " " + ee.Source + " " + ee.TargetSite);
                            }
                        });
                    }
                });
            }
            else
            {
                stopRecording();
            }
        }
        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);
        }