Ejemplo n.º 1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //初始化托盘图标
            NotifyIcon.NotifyIcon_Init();

            //读取任务列表
            Bas.LoadTasks();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取房间信息
        /// </summary>
        /// <param name="item">任务实例</param>
        /// <returns></returns>
        public static bool GetRoomInfo(ref Cls_WorkListItem item)
        {
            try
            {
                string str = Bas.GetBody(item.URL);
                if (!string.IsNullOrEmpty(str))
                {
                    Regex  reg     = new Regex("<script>window.__NEPTUNE_IS_MY_WAIFU__={.*}</script>");
                    string jsonstr = reg.Match(str).Value;
                    jsonstr = Regex.Split(Regex.Split(jsonstr, "window.__NEPTUNE_IS_MY_WAIFU__=")[1], "</script>")[0];

                    item.Platform = Cls_WorkListItem.PlatformType.Bilibili;

                    item.Roomid     = Bas.GetJsonValueByKey(jsonstr, "roomInitRes/data/room_id").ToString();
                    item.RoomStatus = (int)Bas.GetJsonValueByKey(jsonstr, "roomInitRes/data/live_status");
                    item.RoomTitle  = Bas.GetJsonValueByKey(jsonstr, "baseInfoRes/data/title").ToString();

                    if (item.RoomStatus == 1)
                    {
                        List <string> Urls = new List <string>();
                        foreach (Dictionary <string, object> i in (ArrayList)Bas.GetJsonValueByKey(jsonstr, "playUrlRes/data/durl"))
                        {
                            Urls.Add(Bas.GetJsonValueByKey(i, "url").ToString());
                        }
                        item.VideoUrl = Urls.ToArray();
                    }

                    item.IsSupportDanmu = true;

                    if (str.Contains("uname"))
                    {
                        item.Host = Regex.Split(new Regex("\"uname\":.*,").Match(str).Value, "\"")[3];
                    }
                    else
                    {
                        string strhost = Bas.GetBody("https://api.live.bilibili.com/live_user/v1/UserInfo/get_anchor_in_room?roomid=" + item.Roomid);
                        item.Host = Bas.GetJsonValueByKey(strhost, "data/info/uname").ToString();
                    }

                    item.CallPropertyChanged("RoomInfoLong");

                    return(true);
                }
                else
                {
                    item.Platform = Cls_WorkListItem.PlatformType.None;

                    item.CallPropertyChanged("RoomInfoLong");

                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
        private void Btn_Comfirm_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Properties.Settings.Default.IsBtnCloseToExit         = (bool)RB_Exit.IsChecked;
            Properties.Settings.Default.IsBtnCloseNotNoticeAgain = (bool)CB_NotAskAgain.IsChecked;

            if ((bool)RB_Exit.IsChecked)
            {
                Bas.Exit();
            }
            else
            {
                Application.Current.MainWindow.Hide();
            }

            Close();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取视频地址
        /// </summary>
        /// <param name="URL">直播间地址</param>
        /// <returns>视频地址集合</returns>
        public static string[] GetVideoURL(string URL)
        {
            string str     = Bas.GetBody(URL);
            Regex  reg     = new Regex("<script>window.__NEPTUNE_IS_MY_WAIFU__={.*}</script>");
            string jsonstr = reg.Match(str).Value;

            jsonstr = Regex.Split(Regex.Split(jsonstr, "window.__NEPTUNE_IS_MY_WAIFU__=")[1], "</script>")[0];

            List <string> Urls = new List <string>();

            foreach (Dictionary <string, object> i in (ArrayList)Bas.GetJsonValueByKey(jsonstr, "playUrlRes/data/durl"))
            {
                Urls.Add(Bas.GetJsonValueByKey(i, "url").ToString());
            }
            return(Urls.ToArray());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 查询直播间是否在播
        /// </summary>
        /// <param name="URL">直播间地址</param>
        /// <returns>是否在播</returns>
        public static bool IsLiving(string URL)
        {
            string str     = Bas.GetBody(URL);
            Regex  reg     = new Regex("<script>window.__NEPTUNE_IS_MY_WAIFU__={.*}</script>");
            string jsonstr = reg.Match(str).Value;

            jsonstr = Regex.Split(Regex.Split(jsonstr, "window.__NEPTUNE_IS_MY_WAIFU__=")[1], "</script>")[0];
            if ((int)Bas.GetJsonValueByKey(jsonstr, "roomInitRes/data/live_status") == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 关闭按钮鼠标弹起
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Btn_Close_MouseUp(object sender, MouseButtonEventArgs e)
 {
     if (Properties.Settings.Default.IsBtnCloseNotNoticeAgain)
     {
         if (Properties.Settings.Default.IsBtnCloseToExit)
         {
             Bas.Exit();
         }
         else
         {
             Hide();
         }
     }
     else
     {
         CloseBtnModeChoserWindow c = new CloseBtnModeChoserWindow();
         c.ShowDialog();
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 系统托盘图标初始化程序
        /// </summary>
        public static void NotifyIcon_Init()
        {
            NI = new System.Windows.Forms.NotifyIcon();

            NI.Icon = Properties.Resources.favicon;
            NI.Text = "录播姬";

            //打开菜单项
            System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("显示主窗口");
            open.Click += new EventHandler((s, e) => { Application.Current.MainWindow.Show(); Application.Current.MainWindow.Activate(); });

            //设置菜单项
            System.Windows.Forms.MenuItem setting = new System.Windows.Forms.MenuItem("设置");
            setting.Click += new EventHandler((s, e) => { SettingWindow ss = new SettingWindow(); ss.Show(); });

            //检查更新菜单项
            System.Windows.Forms.MenuItem checkupdate = new System.Windows.Forms.MenuItem("检查更新");
            checkupdate.Click += new EventHandler((s, e) => { });

            //关于菜单项
            System.Windows.Forms.MenuItem about = new System.Windows.Forms.MenuItem("关于");
            about.Click += new EventHandler((s, e) => { AboutWindow a = new AboutWindow(); a.ShowDialog(); });

            //退出菜单项
            System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("退出");
            exit.Click += new EventHandler((s, e) => { Bas.Exit(); });

            //关联托盘控件
            System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { open, setting, checkupdate, about, exit };
            NI.ContextMenu = new System.Windows.Forms.ContextMenu(childen);

            NI.Click             += new EventHandler((s, e) => { Application.Current.MainWindow.Show(); Application.Current.MainWindow.Activate(); });
            NI.BalloonTipClicked += new EventHandler((s, e) => { Application.Current.MainWindow.Show(); Application.Current.MainWindow.Activate(); });

            NI.Visible = true;
        }
 private void TB_URL_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
 {
     Bas.AnalysisURL(TB_URL.Text, ref Item);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 退出按钮点击
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Btn_Exit_Click(object sender, RoutedEventArgs e)
 {
     Bas.Exit();
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 获取文件正确的md5
 /// </summary>
 /// <returns>md5</returns>
 private static string GetMD5()
 {
     return(Bas.GetBody("https://leochen98.github.io/AutoLiveRecorder/md5.txt"));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 转码
 /// </summary>
 private void Transcode()
 {
     a : if (File.Exists(Properties.Settings.Default.SavePath + "\\ffmpeg.exe"))
     {
         Process p = new Process()
         {
             StartInfo = new ProcessStartInfo()
             {
                 FileName       = Properties.Settings.Default.SavePath + "\\ffmpeg.exe",
                 CreateNoWindow = true,
                 WindowStyle    = ProcessWindowStyle.Hidden,
                 Arguments      = "-i \"" + FileName + "\" -vcodec copy -acodec copy \"" + Bas.GetMP4FileName(FileName) + "\""
             }
         };
         p.Start();
     }
     else
     {
         WebClient c = new WebClient();
         c.DownloadFile("http://update.zhangbudademao.com/112/ffmpeg.exe", Properties.Settings.Default.SavePath + "\\ffmpeg.exe");
         goto a;
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// 执行录制
        /// </summary>
        /// <param name="FileName">文件路径</param>
        private void DoRecord(string FileName)
        {
            bool isFinished = false;

            try
            {
                client = new WebClient();

                Stream stream = client.OpenRead(new Uri(VideoUrl[0]));

                string tmpFileName = Bas.GetFreeTmpFileName(FileName);
                tmpFileList.Add(tmpFileName);
                writer = new FileStream(tmpFileName, FileMode.Create);

                long   tmpFileLength = 0;
                byte[] mbyte         = new byte[1024];
                int    readL         = stream.Read(mbyte, 0, 1024);
                while (readL != 0 && !IsRecorderAbortRequested)
                {
                    writer.Write(mbyte, 0, readL);//写文件
                    tmpFileLength += readL;
                    //文件分片
                    if (tmpFileLength >= 1073741824)
                    {
                        //关闭连接
                        client.Dispose();
                        //关闭文件
                        writer.Close();
                        //新建分片
                        DoRecord(FileName);
                        isFinished = true;
                        return;
                    }
                    readL = stream.Read(mbyte, 0, 1024);//读流
                }
                if (IsLiving() && !IsRecorderAbortRequested)
                {
                    DoRecord(FileName);
                }
                else
                {
                    Status = StatusCode.Arranging;
                }
            }
            catch
            {
                if (IsLiving() && !IsRecorderAbortRequested)
                {
                    DoRecord(FileName);
                }
                else
                {
                    Status = StatusCode.Arranging;
                }
            }
            finally
            {
                if (!isFinished)
                {
                    //关闭连接
                    client.Dispose();
                    //关闭文件
                    writer.Close();
                    //整理文件
                    ArrangeFile();
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 执行录制
        /// </summary>
        private void DoRecord()
        {
            bool isFinished = false;

            try
            {
                client = new WebClient();

                Stream stream = client.OpenRead(new Uri(VideoUrl[0]));

                if (!Directory.Exists(Properties.Settings.Default.SavePath))
                {
                    Directory.CreateDirectory(Properties.Settings.Default.SavePath);
                }
                FileName = Bas.GetFreeFileName(PlatformString + "-" + Roomid + "-" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second, "flv", Properties.Settings.Default.SavePath);
                string tmpFileName = Bas.GetFreeTmpFileName(FileName);
                tmpFileList.Add(tmpFileName);
                writer = new FileStream(tmpFileName, FileMode.Create);

                long   tmpFileLength = 0;
                byte[] mbyte         = new byte[1024];
                int    readL         = stream.Read(mbyte, 0, 1024);
                while (readL != 0 && !IsRecorderAbortRequested)
                {
                    writer.Write(mbyte, 0, readL);//写文件
                    tmpFileLength += readL;
                    //文件分片
                    if (tmpFileLength >= 1073741824)
                    {
                        //关闭流
                        stream = null;
                        //关闭连接
                        client.Dispose();
                        //关闭文件
                        writer.Close();
                        //新建分片
                        DoRecord(FileName);
                        isFinished = true;
                        return;
                    }
                    readL = stream.Read(mbyte, 0, 1024);//读流
                }
                if (IsLiving() && !IsRecorderAbortRequested)
                {
                    DoRecord(FileName);
                }
                else
                {
                    Status = StatusCode.Arranging;
                }
            }
            catch
            {
                if (IsLiving() && !IsRecorderAbortRequested)
                {
                    DoRecord(FileName);
                }
                else
                {
                    Status = StatusCode.Arranging;
                }
            }
            finally
            {
                if (!isFinished)
                {
                    //关闭连接
                    client.Dispose();
                    //关闭文件
                    writer.Close();
                    //整理文件
                    ArrangeFile();
                }
            }
        }