软件简介
软件名称 | DouYinDownLoader |
---|---|
软件版本 | v1.0 |
软件类别 | 下载工具 |
适用平台 | Windows |
最近更新 | 2020.04.23 |
使用说明
支持分享的短链接和长链接
C#源代码
- using System;
- using System.ComponentModel;
- using System.IO;
- using System.Net;
- using System.Net.Http;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- using Newtonsoft.Json;
- namespace DouYinDownLoader
- {
- public partial class Form1 : Form
- {
- private static HttpClient httpClient;
- public Form1()
- {
- InitializeComponent();
- HttpClientHandler handler = new HttpClientHandler();
- handler.UseCookies = false;
- httpClient = new HttpClient(handler);
- httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1");
- }
- private async void button1_ClickAsync(object sender, EventArgs e)
- {
- var url = textBox1.Text.Trim();
- if (string.IsNullOrEmpty(url))
- {
- MessageBox.Show("网址不能为空");
- return;
- }
- var html = await httpClient.GetStringAsync(url);
- var match = Regex.Match(html, "itemId: \"(\\d+)\"");
- if (match.Success)
- {
- var itemId = match.Groups[1].ToString();
- var json = await httpClient.GetStringAsync($"https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={itemId}");
- var jsonObj = JsonConvert.DeserializeObject<dynamic>(json);
- if (jsonObj.status_code == 0)
- {
- var videoUrl = jsonObj.item_list[0].video.play_addr.url_list[0].ToString();
- var videoName = jsonObj.item_list[0].desc;
- var saveDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "videos");
- var saveFile = Path.Combine(saveDir, $"{videoName}.mp4");
- if (!Directory.Exists(saveDir))
- {
- Directory.CreateDirectory(saveDir);
- }
- if (!File.Exists(saveFile))
- {
- var downLoader = new WebClient();
- downLoader.Headers.Add("User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1");
- downLoader.DownloadFileAsync(new Uri(videoUrl), saveFile);
- downLoader.DownloadFileCompleted += DownLoader_DownloadFileCompleted;
- downLoader.DownloadProgressChanged += DownLoader_DownloadProgressChanged;
- }
- else
- {
- label1.Text = "文件已存在,无需重复下载!";
- }
- }
- else
- {
- MessageBox.Show("解析失败!");
- }
- }
- else
- {
- MessageBox.Show("未找到视频!");
- }
- }
- private void DownLoader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
- {
- label1.Text = $"下载中 {e.TotalBytesToReceive / 1024}kb - {e.BytesReceived / 1024}kb";
- progressBar1.Value = e.ProgressPercentage;
- }
- private void DownLoader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
- {
- label1.Text = "下载完成";
- }
- }
- }
附件下载
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。