private void button2_Click(object sender, EventArgs e)
{
label2.Visible = true;
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem
{
URL = textBox1.Text.Trim(),
Host = "www.bilibili.com",
UserAgent = userAgent
};
var result = http.GetHtml(item);
string html = result.Html;
string gl = HttpHelper.GetBetweenHtml(html, "window.__playinfo__=", "</script><script>window.__INITIAL_STATE__");
title = HttpHelper.GetBetweenHtml(html, "<title data-vue-meta=\"true\">", "</title>");
root = (Root)HttpHelper.JsonToObject<Root>(gl);
if (root.code == 0)
{
RadioButton[] radioButton = new RadioButton[root.data.accept_description.Count];
//控件上边缘与容器上边缘的距离
int top = 6;
//记录循环,控件左上角相对于容器左上角的坐标
int i = 0;
int n = 0;
GroupBox gb = new GroupBox();
panel1.AutoScroll = true;
for (n = 0; n < root.data.accept_description.Count; n++)
{
radioButton[n] = new RadioButton();
button3.Visible = true;
if (n % 3 == 0 && n != 0)
{
top += 30;
i = 0;
}
if (n == 0)
{
radioButton[n].Checked = true;
}
radioButton[n].AutoSize = true;
radioButton[n].Top = top;
//控件左上角相对于容器左上角的坐标,以及每个控件之间的距离
radioButton[n].Location = new Point(i * 150 + 2, top);
// MessageBox.Show(name[n].ToString());
radioButton[n].Text = root.data.accept_description[n];
radioButton[n].Visible = true;
radioButton[n].Name = "radioButton" + n;
radioButton[n].Tag = n;
this.panel1.Controls.Add(radioButton[n]);
i++;
}
};
}
//点击下载按钮的代码
foreach (var item in panel1.Controls)
{
if (item is RadioButton)
{
RadioButton radio = item as RadioButton;
if (radio.Checked)
{
var tag = int.Parse(radio.Tag.ToString());
string videourl = root.data.dash.video.ToList()[tag].baseUrl;
string audiourl = root.data.dash.audio.ToList()[0].baseUrl;
//DownloadAudio(audiourl);
//DownloadVideo(videourl);
Thread thread = new Thread(new ParameterizedThreadStart(DownloadVideo));
thread.Start(videourl);
Thread thread2 = new Thread(new ParameterizedThreadStart(DownloadAudio));
thread2.Start(audiourl);
}
}
//合成代码
private void button4_Click(object sender, EventArgs e)
{
this.Invoke((EventHandler)delegate
{
textBox2.Text += DateTime.Now.ToString() + "合并中 请稍后...\r\n";
});
string path = textBox3.Text + guid ;
string avi = textBox3.Text +"合并视频";
string arguments = "-i " + path + ".avi -i " + path + ".aac -vcodec copy -acodec copy " + avi + ".avi";
//arguments = "-i " + path + ".avi -i " + path + ".aac -c:v copy -c:a aac -strict experimental " + avi + ".avi";
Process p = new Process();
p.StartInfo.FileName = "ffmpeg.exe";
p.StartInfo.Arguments = arguments;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
// p.StartInfo.RedirectStandardError = true;
p.ErrorDataReceived += new DataReceivedEventHandler(Output);//外部程序
p.Start();//启动线程
timer1.Enabled = true;
}
爬虫-哔哩哔哩-视频下载 源码
如果文章对你有帮助,欢迎点击上方按钮打赏作者
未经允许不得转载:军哥驿站 » 爬虫-哔哩哔哩-视频下载 源码