コード例 #1
0
ファイル: FormMain.cs プロジェクト: ZhengyangXu/BiliRanking
        private void buttonDLold_Click(object sender, EventArgs e)
        {
            string[] lines = Regex.Split(textBoxAV.Text, "\r\n|\r|\n");
            tsd.Progressbar = verticalProgressBar1;
            Log.Info("获取所有视频信息");
            listb.Clear();
            foreach (string s in lines)
            {
                if (s != "")
                {
                    BiliInterfaceInfo info = BiliInterface.GetFlvInfo(s);
                    if (info.flvurl != null)
                    {
                        listb.Add(info);
                        //Log.Info("正在下载视频 - " + info.AVNUM);
                        //tsd = new TSDownload("http://www.bilibilijj.com/DownLoad/Cid/" + info.cid, System.Environment.CurrentDirectory +  @"\video\" + info.AVNUM + ".flv");
                        //tsd.Progressbar = progressBar1;
                        //tsd.Start();
                    }
                }
            }
            Log.Info("所有视频信息获取完成");
            Log.Info("开始批量下载");

            if (downloader != null && downloader.Status == DownloadStatus.Downloading)
            {
                downloader.Cancel();
            }
            timer1.Enabled = true;
            DlNextST();
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: ZhengyangXu/BiliRanking
        private void buttonDlMP4_Click(object sender, EventArgs e)
        {
            string[] lines = Regex.Split(textBoxAV.Text, "\r\n|\r|\n");

            timer1.Enabled  = true;
            tsd.Progressbar = verticalProgressBar1;

            Log.Info("获取所有视频MP4地址");

            foreach (string s in lines)
            {
                if (s != "")
                {
                    BiliInterfaceInfo info = BiliInterface.GetMP4info(s, 1); //TODO:多页视频

                    if (info != null)
                    {
                        listb.Add(info);
                    }
                }
            }
            Log.Info("所有视频MP4地址获取完成");
            Log.Info("开始批量下载");
            DlNext();
        }
コード例 #3
0
ファイル: FormMain.cs プロジェクト: ZhengyangXu/BiliRanking
 private void buttonDL_Click(object sender, EventArgs e)
 {
     string[] lines = Regex.Split(textBoxAV.Text, "\r\n|\r|\n");
     Log.Info("获取所有视频信息");
     listb.Clear();
     foreach (string s in lines)
     {
         if (s != "")
         {
             BiliInterfaceInfo info = BiliInterface.GetFlvInfo(s);
             if (info.flvurl != null)
             {
                 listb.Add(info);
             }
         }
     }
     Log.Info("所有视频信息获取完成");
     Log.Info("开始批量下载");
     timer1.Stop();
     try
     {
         tsd.Stop();
         //tsd.Progressbar = null;
     }
     catch { }
     //verticalProgressBar1.Maximum = 100;
     DlNext();
     //Log.Info("批量下载完成");
 }
コード例 #4
0
        public string DoReplace(string before, BiliInterfaceInfo info)
        {
            string after = before;

            after = after.Replace("<", "{");
            after = after.Replace(">", "}");

            after = after.Replace("{}", "\r\n");

            after = after.Replace("{huanhang}", "\r\n");
            after = after.Replace("{title}", info.title);
            after = after.Replace("{time}", info.created_at.Replace(" ", " ")); //半角换成全角
            after = after.Replace("{created_at}", info.created_at);
            after = after.Replace("{AVNUM}", info.AVNUM);
            after = after.Replace("{avnum}", info.avnum);
            after = after.Replace("{author}", info.author);
            after = after.Replace("{zongfen}", info.Fdefen.ToString());
            after = after.Replace("{paiming}", info.Fpaiming.Value.ToString("00"));
            after = after.Replace("{bofang}", info.play.ToString());
            after = after.Replace("{yingbi}", info.coins.ToString());
            after = after.Replace("{shoucang}", info.favorites.ToString());
            after = after.Replace("{danmu}", info.video_review.ToString());
            after = after.Replace("{pinglun}", info.review.ToString());
            after = after.Replace("{tag}", info.tag.ToString());
            after = after.Replace("{share}", info.share.ToString());
            after = after.Replace("{pic}", "{pic}" + info.AVNUM);

            return(after);
        }
コード例 #5
0
        private void dataGrid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!dataGrid.AllowDrop)
            {
                return;
            }
            rowIndex = GetCurrentRowIndex(e.GetPosition);
            if (rowIndex < 0)
            {
                return;
            }
            dataGrid.SelectedIndex = rowIndex;
            BiliInterfaceInfo selectedEmp = dataGrid.Items[rowIndex] as BiliInterfaceInfo;

            if (selectedEmp == null)
            {
                return;
            }
            textBlockDraging.Text = $"[{selectedEmp.Fpaiming}] {selectedEmp.AVNUM} - {selectedEmp.title}";
            DragDropEffects dragdropeffects = DragDropEffects.Move;

            if (DragDrop.DoDragDrop(dataGrid, selectedEmp, dragdropeffects)
                != DragDropEffects.None)
            {
                dataGrid.SelectedItem = selectedEmp;
            }
        }
コード例 #6
0
        private void dataGrid_Drop(object sender, DragEventArgs e)
        {
            popup1.IsOpen = false;

            if (rowIndex < 0)
            {
                return;
            }
            int index = this.GetCurrentRowIndex(e.GetPosition);

            if (index < 0)
            {
                return;
            }
            if (index == rowIndex)
            {
                return;
            }
            if (index == dataGrid.Items.Count - 1)
            {
                MessageBox.Show("This row-index cannot be drop");
                return;
            }

            List <BiliInterfaceInfo> bi = new List <BiliInterfaceInfo>();

            (dataGrid.ItemsSource as List <BiliInterfaceInfo>).ForEach(i => bi.Add(i)); //为了实现撤销需要深复制
            //List<BiliInterfaceInfo> bi = dataGrid.ItemsSource as List<BiliInterfaceInfo>;
            BiliInterfaceInfo changed = bi[rowIndex];

            bi.RemoveAt(rowIndex);
            bi.Insert(index, changed);
            SetNewData(bi);
        }
コード例 #7
0
        private void buttenGen_Click(object sender, RoutedEventArgs e)
        {
            BiliInterfaceInfo bi = BiliInterface.GetInfo(textBoxAv.Text);

            BiliInterface.GetFace(bi);
            BiliInterface.GetPic(bi);

            //text|font|ptSize|#colorcode|RightAlign TrueOrFalse|pointX|pointY|rectX|rectY|rectWidth|rectHeight|AutoOffsetY TrueOrFalse|MaxWidth

            List <TemplateInfo> tis = new List <TemplateInfo>();
            string text             = textBoxInfo.Text;

            text = Fubang.DoReplace(text, bi);
            var lines = Regex.Split(text, "\r\n|\r|\n");

            foreach (string line in lines)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                var          cells = Regex.Split(line, "[|]");
                TemplateInfo ti    = new TemplateInfo()
                {
                    text         = cells[0],
                    font         = new Font(cells[1], Convert.ToSingle(cells[2]), GraphicsUnit.Point),
                    brush        = new SolidBrush(ColorTranslator.FromHtml(cells[3])),
                    isRightAlign = bool.Parse(cells[4])
                };
                if (!ti.isRightAlign)
                {
                    ti.point = new PointF(Convert.ToSingle(cells[5]), Convert.ToSingle(cells[6]));
                }
                else
                {
                    ti.rectangle = new RectangleF(Convert.ToSingle(cells[7]), Convert.ToSingle(cells[8]), Convert.ToSingle(cells[9]), Convert.ToSingle(cells[10]));
                }
                if (cells.Length >= 12)
                {
                    ti.autoOffsetY = bool.Parse(cells[11]);
                }
                if (cells.Length >= 13)
                {
                    ti.maxWidth = Convert.ToSingle(cells[12]);
                }
                tis.Add(ti);
            }
            Zhubang zb = new Zhubang();

            System.Drawing.Image re;
            if (bgimg == null)
            {
                re = zb.GenStardustTemplate(tis);
            }
            else
            {
                re = zb.GenWithTemplate((System.Drawing.Image)bgimg.Clone(), tis);
            }
            imageMain.Source = ConvertDrawingImage2MediaImageSource(re);
        }
コード例 #8
0
        public void GetInfoAsyncTest()
        {
            BiliInterfaceInfo info = new BiliInterfaceInfo();

            info = AsyncHelper.RunSync(() => BiliInterface.GetInfoAsync("av2680512"));

            Assert.AreEqual(info.title, "【创刊号】哔哩哔哩月刊鬼畜排行榜#001");
        }
コード例 #9
0
ファイル: FormMain.cs プロジェクト: ZhengyangXu/BiliRanking
        private void 进入唧唧下载MP4ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //http://www.bilibilijj.com/Files/DownLoad/9626305.mp4
            BiliInterfaceInfo curr = ((List <BiliInterfaceInfo>)dataGridViewRAW.DataSource)[CurrentRowIndex];

            Process.Start($"http://www.bilibilijj.com/Files/DownLoad/{curr.cid}.mp4");
            string html = BiliInterface.GetHtml($"http://www.bilibilijj.com/Files/DownLoad/{curr.cid}.mp4");
        }
コード例 #10
0
ファイル: FormMain.cs プロジェクト: ZhengyangXu/BiliRanking
        private void  视频模板复制数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BiliInterfaceInfo curr     = ((List <BiliInterfaceInfo>)dataGridViewRAW.DataSource)[CurrentRowIndex];
            string            copytext = curr.play + "\r\n" + curr.coins + "\r\n" + curr.favorites + "\r\n" + curr.video_review + "\r\n" + curr.review;

            Clipboard.SetText(copytext);
            Log.Info(String.Format("已复制{0}的数据到剪贴板", curr.AVNUM));
        }
コード例 #11
0
ファイル: FormMain.cs プロジェクト: ZhengyangXu/BiliRanking
        private void  制标题和信息行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BiliInterfaceInfo curr     = ((List <BiliInterfaceInfo>)dataGridViewRAW.DataSource)[CurrentRowIndex];
            string            copytext = curr.title + "\r\n" + curr.created_at + "   " + curr.author + "   " + curr.avnum;

            Clipboard.SetText(copytext);
            Log.Info(String.Format("已复制{0}的标题和信息行到剪贴板", curr.AVNUM));
        }
コード例 #12
0
ファイル: FormMain.cs プロジェクト: ZhengyangXu/BiliRanking
        private void  制数据含中文ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BiliInterfaceInfo curr     = ((List <BiliInterfaceInfo>)dataGridViewRAW.DataSource)[CurrentRowIndex];
            string            copytext = String.Format("播放{0,11}\r\n硬币{1,11}\r\n收藏{2,11}\r\n弹幕{3,11}\r\n评论{4,11}", curr.play, curr.coins, curr.favorites, curr.video_review, curr.review);

            Clipboard.SetText(copytext);
            Log.Info(String.Format("已复制{0}的数据(含中文)到剪贴板", curr.AVNUM));
        }
コード例 #13
0
ファイル: FormMain.cs プロジェクト: ZhengyangXu/BiliRanking
        private void  制总分ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BiliInterfaceInfo curr     = ((List <BiliInterfaceInfo>)dataGridViewRAW.DataSource)[CurrentRowIndex];
            string            copytext = curr.Fdefen.ToString();

            Clipboard.SetText(copytext);
            Log.Info(String.Format("已复制{0}的总分到剪贴板", curr.AVNUM));
        }
コード例 #14
0
        private async void buttonInsert_Click(object sender, RoutedEventArgs e)
        {
            BiliInterfaceInfo bi = await BiliInterface.GetInfoTaskAsync(textBoxInsert.Text);

            if (bi.pic != null)
            {
                AddData(bi);
            }
        }
コード例 #15
0
        public void GetFlvInfoTest()
        {
            BiliInterfaceInfo info = new BiliInterfaceInfo();

            //info = BiliInterface.GetFlvInfo("av3153761");
            //TestContext.WriteLine(info.flvurl);
            //Debug.WriteLine(info.flvurl);
            info = BiliInterface.GetFlvInfo("av9472850");
            Assert.IsTrue(info.flvurl.Contains(".flv"));
        }
コード例 #16
0
        private void AddData(BiliInterfaceInfo info)
        {
            if (info == null)
            {
                return;
            }
            List <BiliInterfaceInfo> bi = GetData();

            bi.Add(info);
            SetNewData(bi);
        }
コード例 #17
0
        private void RemoveData(BiliInterfaceInfo info)
        {
            if (info == null)
            {
                return;
            }
            List <BiliInterfaceInfo> bi = GetData();

            //TODO: 更换新逻辑
            bi.Remove(info);
            SetNewData(bi);
        }
コード例 #18
0
 private string GenTimecode(BiliInterfaceInfo info)
 {
     try
     {
         return((TimeSpan.Parse(info.Tstart.Substring(0, info.Tstart.LastIndexOf(":"))).TotalSeconds + 2).ToString());
         //return (TimeSpan.Parse(info.Tstart.Split('.')[0]).TotalSeconds + 3).ToString();
     }
     catch
     {
         return("时间码解析失败");
     }
 }
コード例 #19
0
        public static int sortt(BiliInterfaceInfo x, BiliInterfaceInfo y)
        {
            int res = 0;

            if (x.Fdefen > y.Fdefen)
            {
                res = -1;
            }
            else
            {
                res = 1;
            }
            return(res);
        }
コード例 #20
0
        public string DoReplace(string before, BiliInterfaceInfo info)
        {
            string after = before;

            after = after.Replace("<", "{");
            after = after.Replace(">", "}");

            after = after.Replace("{}", "\r\n");

            after = after.Replace("{huanhang}", "\r\n");
            after = after.Replace("{title}", info.title);
            after = after.Replace("{time}", info.created_at.Replace(" ", " ")); //半角换成全角
            after = after.Replace("{created_at}", info.created_at);
            after = after.Replace("{avnum}", info.avnum);
            after = after.Replace("{author}", info.author);
            after = after.Replace("{zongfen}", info.Fdefen.ToString());
            after = after.Replace("{bofang}", info.play.ToString());
            after = after.Replace("{yingbi}", info.coins.ToString());
            after = after.Replace("{shoucang}", info.favorites.ToString());
            after = after.Replace("{danmu}", info.video_review.ToString());
            after = after.Replace("{pinglun}", info.review.ToString());
            after = after.Replace("{tag}", info.tag.ToString());
            after = after.Replace("{code}", GenCodeDanmaku(info));
            after = after.Replace("{timecode}", GenTimecode(info));

            after = after.Replace("{换行}", "\r\n");
            after = after.Replace("{标题}", info.title);
            after = after.Replace("{时间}", info.created_at.Replace(" ", " ")); //半角换成全角
            after = after.Replace("{半角时间}", info.created_at);
            after = after.Replace("{av号}", info.avnum); after = after.Replace("{AV号}", info.avnum);
            after = after.Replace("{作者}", info.author); after = after.Replace("{UP}", info.author);
            after = after.Replace("{总分}", info.Fdefen.ToString());
            after = after.Replace("{播放}", info.play.ToString());
            after = after.Replace("{硬币}", info.coins.ToString());
            after = after.Replace("{收藏}", info.favorites.ToString());
            after = after.Replace("{弹幕}", info.video_review.ToString());
            after = after.Replace("{评论}", info.review.ToString());
            after = after.Replace("{代码}", GenCodeDanmaku(info));
            after = after.Replace("{时间码}", GenTimecode(info));

            return(after);
        }
コード例 #21
0
        private string GenCodeDanmaku(BiliInterfaceInfo info)
        {
            string res = @"vtt=$.createButton(
{
    lifeTime:{lifetime},
    x:Player.width-180,
    width:150,
    y:Player.height-40,
    height:30,
    text:""跳转到该投稿"",
    onclick: function()
    {
        Player.jump(""{avnum}"", 1, true);
    }
});
v32.setStyle(""fillColors"",[0xFF0000,0xCCCCCC]);";

            res = res.Replace("{avnum}", info.avnum);

            return(res);
        }
コード例 #22
0
ファイル: FormQuickCopy.cs プロジェクト: SkiTiSu/BiliRanking
        public string DoReplace(string before, BiliInterfaceInfo info)
        {
            string after = before;

            after = after.Replace("<", "{");
            after = after.Replace(">", "}");

            after = after.Replace("{}", "\r\n");

            after = after.Replace("{huanhang}", "\r\n");
            after = after.Replace("{title}", info.title);
            after = after.Replace("{time}", info.created_at.Replace(" ", " ")); //半角换成全角
            after = after.Replace("{created_at}", info.created_at);
            after = after.Replace("{avnum}", info.avnum);
            after = after.Replace("{author}", info.author);
            after = after.Replace("{zongfen}", info.Fdefen.ToString());
            after = after.Replace("{bofang}", info.play.ToString());
            after = after.Replace("{yingbi}", info.coins.ToString());
            after = after.Replace("{shoucang}", info.favorites.ToString());
            after = after.Replace("{danmu}", info.video_review.ToString());
            after = after.Replace("{pinglun}", info.review.ToString());
            after = after.Replace("{tag}", info.tag.ToString());

            after = after.Replace("{换行}", "\r\n");
            after = after.Replace("{标题}", info.title);
            after = after.Replace("{时间}", info.created_at.Replace(" ", " ")); //半角换成全角
            after = after.Replace("{半角时间}", info.created_at);
            after = after.Replace("{av号}", info.avnum); after = after.Replace("{AV号}", info.avnum);
            after = after.Replace("{作者}", info.author); after = after.Replace("{UP}", info.author);
            after = after.Replace("{总分}", info.Fdefen.ToString());
            after = after.Replace("{播放}", info.play.ToString());
            after = after.Replace("{硬币}", info.coins.ToString());
            after = after.Replace("{收藏}", info.favorites.ToString());
            after = after.Replace("{弹幕}", info.video_review.ToString());
            after = after.Replace("{评论}", info.review.ToString());

            return after;
        }
コード例 #23
0
ファイル: Data.xaml.cs プロジェクト: levy258/BiliRanking
        private async void buttonGetPicUrl_Click(object sender, RoutedEventArgs e)
        {
            log.Info("开始更新封面头像地址(非下载)");
            ScoreType            st  = (ScoreType)((EnumerationExtension.EnumerationMember)comboBoxScoreType.SelectedItem).Value;
            IEnumerable <string> avs = SharedData.SortedAVs;

            BiliInterfaceInfo[] lls = await concurrentAsync(
                Convert.ToInt32(textBoxConcurrency.Text), //现在有限制了,不能弄那么快了
                avs,
                new Func <string, ScoreType, bool, Task <BiliInterfaceInfo> >(BiliInterface.GetInfoTaskAsync),
                st,
                toggleButtonUseKanb.IsChecked.GetValueOrDefault());

            List <BiliInterfaceInfo> ll = new List <BiliInterfaceInfo>();
            string failedAVs            = "";

            foreach (BiliInterfaceInfo info in lls)
            {
                if (info.pic != null)
                {
                    BiliInterfaceInfo oldinfo = SharedData.Infos.Where(x => x.avnum == info.avnum).First();
                    oldinfo.pic  = info.pic;
                    oldinfo.face = info.face;
                    oldinfo.mid  = info.mid;
                }
                else
                {
                    failedAVs += info.avnum + ";";
                }
            }
            if (failedAVs != "")
            {
                log.Warn("注意!下列视频数据未正确获取!\r\n" + failedAVs);
            }
            log.Info("更新封面头像地址完成");
        }
コード例 #24
0
        private void buttonImportCsv_Click(object sender, RoutedEventArgs e)
        {
            List <KeyValuePair <string, string> > propmap = new List <KeyValuePair <string, string> >();

            foreach (var column in dataGrid.Columns)
            {
                if (!string.IsNullOrEmpty(column.SortMemberPath))
                {
                    if (column.SortMemberPath != "avurl")
                    {
                        propmap.Add(new KeyValuePair <string, string>(column.Header.ToString(), column.SortMemberPath));
                    }
                    else
                    {
                        propmap.Add(new KeyValuePair <string, string>("AV号", "AVNUM"));
                    }
                }
            }
            MessageBox.Show("为了兼容csv,目前的方法存在限制,文本中不能含有小写逗号\",\",不可以含有小数\r\n请连同标题行复制到剪贴板后,点击确定", "锵锵锵");

            try
            {
                log.Info("开始读取剪贴板数据");
                var      dataobject            = Clipboard.GetDataObject();
                string   data_csv              = (string)dataobject.GetData(DataFormats.CommaSeparatedValue);
                string[] lines                 = Regex.Split(data_csv, "\r\n");
                string[] firstitems            = Regex.Split(lines[0], ",");
                List <BiliInterfaceInfo> blist = new List <BiliInterfaceInfo>();

                Window window = new Window
                {
                    Title   = "匹配",
                    Topmost = true,
                    Width   = 300,
                    Height  = 110 + 28 * firstitems.Length,
                    WindowStartupLocation = WindowStartupLocation.CenterScreen
                };
                Grid       grid          = new Grid();
                ComboBox[] comboBoxes    = new ComboBox[firstitems.Length];
                StackPanel stackPanelAll = new StackPanel {
                    Orientation = Orientation.Vertical
                };
                stackPanelAll.Children.Add(new TextBlock {
                    Text = "请手动匹配未识别的标题行与数据类型", Margin = new Thickness(5, 10, 0, 10)
                });
                for (int i = 0; i <= firstitems.Length - 1; i++)
                {
                    StackPanel stackPanel = new StackPanel {
                        Orientation = Orientation.Horizontal
                    };
                    stackPanel.Children.Add(new TextBlock {
                        Text = firstitems[i], Margin = new Thickness(5, 0, 10, 0), VerticalAlignment = VerticalAlignment.Center
                    });
                    comboBoxes[i] = new ComboBox
                    {
                        ItemsSource   = propmap,
                        MinWidth      = 100,
                        SelectedIndex = propmap.FindIndex(x => x.Key == firstitems[i])
                    };
                    stackPanel.Children.Add(comboBoxes[i]);
                    stackPanelAll.Children.Add(stackPanel);
                }
                Button buttonOK = new Button
                {
                    Content           = "OK",
                    Margin            = new Thickness(5, 0, 5, 5),
                    VerticalAlignment = VerticalAlignment.Bottom
                };
                buttonOK.Click += (ob, eb) =>
                {
                    window.Close();
                };
                grid.Children.Add(stackPanelAll);
                grid.Children.Add(buttonOK);
                window.Content = grid;
                window.ShowDialog();

                for (int i = 1; i <= lines.Length - 1; i++)
                {
                    string[] items = Regex.Split(lines[i], ",");
                    if (items.Length < firstitems.Length)
                    {
                        if (lines[i] != "\0")
                        {
                            log.Warn("该行数据不合法:" + lines[i]);
                        }
                        continue;
                    }
                    BiliInterfaceInfo info = new BiliInterfaceInfo();
                    for (int j = 0; j <= items.Length - 1; j++)
                    {
                        SetModelValue(((KeyValuePair <string, string>)comboBoxes[j].SelectedValue).Value, items[j], info);
                    }
                    blist.Add(info);
                }
                SetNewData(blist);
                string avs = "";
                foreach (BiliInterfaceInfo i in blist)
                {
                    avs += i.AVNUM + "\r\n";
                }
                SharedData.AVs = avs;
                log.Info("读取与转换完成");
            }
            catch (Exception ee)
            {
                log.Error("发生错误:" + ee.Message);
            }
        }
コード例 #25
0
        private void buttenGen_Click(object sender, RoutedEventArgs e)
        {
            BiliInterfaceInfo bi = new BiliInterfaceInfo()
            {
                AVNUM        = "AV10830407",
                title        = "【星尘二专收录曲】D!scolor【PV】",
                play         = 61531,
                video_review = 683,
                coins        = 2784,
                favorites    = 5386,
                review       = 806,
                share        = 261,
                Fdefen       = 390014,
                author       = "星尘Official",
                created_at   = "2017/05/26 10:12",
                aid          = 10830407,
                tag          = "",
                Fpaiming     = 1
            };

            //text|font|ptSize|#colorcode|RightAlign TrueOrFalse|pointX|pointY|rectX|rectY|rectWidth|rectHeight|AutoOffsetY TrueOrFalse|MaxWidth

            List <TemplateInfo> tis = new List <TemplateInfo>();
            string text             = textBoxInfo.Text;

            text = DoReplace(text, bi);
            var lines = Regex.Split(text, "\r\n|\r|\n");

            foreach (string line in lines)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                var          cells = Regex.Split(line, "[|]");
                TemplateInfo ti    = new TemplateInfo()
                {
                    text         = cells[0],
                    font         = new Font(cells[1], Convert.ToSingle(cells[2]), GraphicsUnit.Point),
                    brush        = new SolidBrush(ColorTranslator.FromHtml(cells[3])),
                    isRightAlign = bool.Parse(cells[4])
                };
                if (!ti.isRightAlign)
                {
                    ti.point = new PointF(Convert.ToSingle(cells[5]), Convert.ToSingle(cells[6]));
                }
                else
                {
                    ti.rectangle = new RectangleF(Convert.ToSingle(cells[7]), Convert.ToSingle(cells[8]), Convert.ToSingle(cells[9]), Convert.ToSingle(cells[10]));
                }
                if (cells.Length >= 12)
                {
                    ti.autoOffsetY = bool.Parse(cells[11]);
                }
                if (cells.Length >= 13)
                {
                    ti.maxWidth = Convert.ToSingle(cells[12]);
                }
                tis.Add(ti);
            }
            Zhubang zb = new Zhubang();

            System.Drawing.Image re;
            if (bgimg == null)
            {
                re = zb.GenStardustTemplate(tis);
            }
            else
            {
                re = zb.GenWithTemplate((System.Drawing.Image)bgimg.Clone(), tis);
            }
            imageMain.Source = ConvertDrawingImage2MediaImageSource(re);
        }
コード例 #26
0
ファイル: FormMain.cs プロジェクト: ZhengyangXu/BiliRanking
        private void buttonRAWReadExcel_Click(object sender, EventArgs e)
        {
            /*
             * if (openFileDialogExcel.ShowDialog() == DialogResult.OK)
             * {
             *  FileStream stream;
             *  try
             *  {
             *      stream = File.Open(openFileDialogExcel.FileName, FileMode.Open, FileAccess.Read);
             *  }
             *  catch (Exception ee)
             *  {
             *      Log.Error("读取时发生错误,文件没有关闭?" + ee.Message);
             *      return;
             *  }
             *
             *  IExcelDataReader excelReader;
             *
             *  if (Path.GetExtension(openFileDialogExcel.FileName) == ".xls")
             *  {
             *      Log.Debug("xls");
             *      excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
             *  }
             *  else
             *  {
             *      Log.Debug("xlsx");
             *      excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
             *  }
             *
             *  excelReader.IsFirstRowAsColumnNames = true;
             *  DataSet result = excelReader.AsDataSet();
             * }
             */
            //string data = Clipboard.GetText();
            MessageBox.Show("请一定将表格中的列按照内置表格中除去最后两列的方式排序(不能含有小写逗号\",\",不可以含有小数),\r\n然后将数据区域(不含标题)复制到剪贴板,点击确定\r\n//抱歉现在的方法可能太不人性化了,以后天书会改进的", "锵锵锵");
            try
            {
                Log.Info("开始读取剪贴板数据");
                var fmt_csv    = DataFormats.CommaSeparatedValue;
                var dataobject = Clipboard.GetDataObject();
                var stream     = (Stream)dataobject.GetData(fmt_csv);
                //var enc = System.Text.Encoding.GetEncoding(1252);
                var    enc      = Encoding.Default;
                var    reader   = new StreamReader(stream, enc);
                string data_csv = reader.ReadToEnd();

                string[] lines = Regex.Split(data_csv, "\r\n");
                List <BiliInterfaceInfo> blist = new List <BiliInterfaceInfo>();
                foreach (string line in lines)
                {
                    string[] items = Regex.Split(line, ",");
                    if (items.Length < 16)
                    {
                        if (line != "\0")
                        {
                            Log.Warn("该行数据不合法:" + line);
                        }
                        continue;
                    }
                    BiliInterfaceInfo info = new BiliInterfaceInfo();
                    info.Fpaiming     = int.Parse(items[0]);
                    info.AVNUM        = items[1];
                    info.title        = items[2];
                    info.play         = uint.Parse(items[3]);
                    info.video_review = uint.Parse(items[4]);
                    info.favorites    = uint.Parse(items[5]);
                    info.coins        = uint.Parse(items[6]);
                    info.review       = uint.Parse(items[7]);
                    info.author       = items[8];
                    info.created_at   = items[9];
                    info.typename     = items[10];
                    info.Fplay        = uint.Parse(items[11]);
                    info.Ffavorites   = uint.Parse(items[12]);
                    info.Fcoins       = uint.Parse(items[13]);
                    info.Freview      = uint.Parse(items[14]);
                    info.Fdefen       = uint.Parse(items[15]);
                    blist.Add(info);
                }

                dataGridViewRAW.DataSource = blist;
                textBoxAV.Text             = "";
                foreach (BiliInterfaceInfo i in blist)
                {
                    textBoxAV.Text += i.AVNUM + "\r\n";
                }
                Log.Info("读取与转换完成");
            }
            catch (Exception ee)
            {
                Log.Error("发生错误:" + ee.Message);
            }
        }