本帖最后由 a5582323 于 2020-3-12 17:41 编辑
直链抓取方法来自https://www.52pojie.cn/thread-1120994-1-1.html
底下有人回复要可执行程序,我就动手写了个,等我写完再去看原UP主已经更新了,我写都写了,就发出来吧。
文件默认保存到C:\Users\Administrator\Desktop\{videoId}.mp4
获取到的直链,在电脑上打开时用chrome,F12,左上角第二个图标选择手机模式,否则打不开
链接: https://pan.baidu.com/s/1k0Cl94jOKiAI9v5799O78w 提取码: sixk
程序基于.net4.6,运行不起来检查.net环境
[C#] 纯文本查看 复制代码 using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using FSLib.Network.Http;
namespace 抖音无水印下载
{
public partial class Form1 : Form
{
HttpClient _client = new HttpClient( );
public Form1()
{
InitializeComponent();
_client.Setting.UserAgent =
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1";
_client.Setting.Accept =
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
_client.Setting.AcceptEncoding = "gzip, deflate, br";
}
/// <summary>
/// 直链获取,方法见文章中链接
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGet_Click(object sender, EventArgs e)
{
var s = _client.Create<string>(HttpMethod.Get, tbUrl.Text, "https://www.baidu.com", allowAutoRedirect: true);
s.Send();
if (s.IsValid())
{
var itemId = Regex.Match(s.Result, @"itemId: ""(.+?)"",").Groups[1].Value;
var dytk = Regex.Match(s.Result, @"dytk: ""(.+?)""").Groups[1].Value;
string u = $@"https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={itemId}&dytk={dytk}";
s = _client.Create<string>(HttpMethod.Get, u);
s.Send();
if (s.IsValid())
{
string videoId = Regex.Matches(s.Result, @"(?<=""uri"":"")\w{32}(?="")")[0].Groups[0].Value;
textBox1.Text =
$"https://aweme.snssdk.com/aweme/v1/play/?video_id={videoId}&line=0&ratio=540p&media_type=4&vr_type=0&improve_bitrate=0&is_play_url=1&is_support_h265=0&source=PackSourceEnum_PUBLISH";
Down(videoId);
}
}
}
/// <summary>
/// 根据获取到的直链下载视频
/// </summary>
/// <param name="videoId">作为保存文件名</param>
private void Down(string videoId)
{
try
{
var file = _client.Create<ResponseFileContent>(
HttpMethod.Get, textBox1.Text,
saveToFile: $@"C:\Users\Administrator\Desktop\{videoId}.mp4", allowAutoRedirect: true);
file.Send();
axWindowsMediaPlayer1.URL = $@"C:\Users\Administrator\Desktop\{videoId}.mp4";
axWindowsMediaPlayer1.Ctlcontrols.play();
}
catch (Exception ex)
{
MessageBox.Show("下载/保存/播放文件时失败" + ex.ToString());
}
}
/// <summary>
/// 测试方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
Down( Regex.Match( textBox1.Text, @"video_id=(.+?)&").Groups[1].Value );
}
}
}
|