全网短视频去水印解析提取视频

这里介绍如何处理短视频水印,目前支持解析抖音,快手,火山,今日头条,全民,微博等20多个平台视频

string parseUrl = "http://v.mkadmin.cn/videovip/analysis";
string linkUrl = "#在抖音,记录美好生活#现在的女人吧都单身,个个都挺优秀,有人约也不去,有人追也不同意,因为把精力全放在了事业上,所以优秀的人才单着 http://v.douyin.com/aHKKF5/ 复制此链接,打开【抖音短视频】,直接观看视频!";

var timestamp = DateTimeHelper.ConvertDateTimeInt(DateTime.Now);
var random = (new Random()).Next(1000, 9999);
var clientAppId = "2d386e5b3bd54d56b4e83137725a490f";
var clientSecretKey = "e55375800a0643619302ccf8b56a35a1a2d2fc0be35e4bb68d00d5b4f8b4bd2e";

var sign = SecurityHelper.Md5Encrypt($"{timestamp}{random}{clientSecretKey}");
var param = new
{
    timestamp = timestamp,
    random = random,
    clientAppId = clientAppId,
    sign = sign,
    data = new
    {
        linkUrl = linkUrl
    }
};
Console.WriteLine($"解析地址:{linkUrl}");
Console.WriteLine();
var data = WebHelper.SubmitForm(parseUrl, param);
Console.WriteLine($"解析结果:{data}");
Console.ReadLine();
public static class SecurityHelper
{
    /// 
    /// 描述:Md5加密
    /// 
    /// 
    /// 
    public static string Md5Encrypt(this string value)
    {
        return Md5Encrypt(value, Encoding.UTF8).ToUpper();
    }

    /// 
    /// 描述:Md5加密
    /// 
    /// 
    /// 
    /// 
    public static string Md5Encrypt(this string value, Encoding encoding)
    {
        using (var md5 = MD5.Create())
        {
            var data = md5.ComputeHash(encoding.GetBytes(value));
            var sBuilder = new StringBuilder();
            foreach (var t in data)
            {
                sBuilder.Append(t.ToString("x2"));
            }
            return sBuilder.ToString();
        }
    }
}

Http请求通用类

public static class WebHelper
{
    /// 
    /// 描述:发送Http请求
    /// 
    /// 
    public static string SubmitForm(string url, object data, string method = "Post", string contentType = "application/json",
            NameValueCollection headValueCollection = null, Encoding encoding = null, DateTime? requestDate = null)
    {
        //读取返回消息
        var result = string.Empty;

        HttpWebRequest request = null;
        HttpWebResponse response = null;
        Stream reqStream = null;
        Stream resStream = null;

        try
        {
            if (encoding == null) encoding = Encoding.UTF8;
            // get请求拼接url
            if (method.ToUpper() == "GET") url += url.Contains("?") ? "&" + data.ToUrlData() : "?" + data.ToUrlData();

            request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = method;
            request.ContentType = contentType;
            //设置为不需要等待服务器允许
            //request.ServicePoint.Expect100Continue = false;
            //request.KeepAlive = false;

            if (requestDate.HasValue) request.Date = requestDate.Value;
            if (null != headValueCollection) request.Headers.Add(headValueCollection);
            if (method.ToUpper() == "POST")
            {
                if (data == null) request.ContentLength = 0;
                else
                {
                    var dataArray = encoding.GetBytes(data.ToJson());
                    request.ContentLength = dataArray.Length;
                    reqStream = request.GetRequestStream();
                    reqStream.Write(dataArray, 0, dataArray.Length);
                }
            }

            response = (HttpWebResponse)request.GetResponse();
            resStream = response.GetResponseStream();
            if (resStream != null)
            {
                var reader = new StreamReader(resStream, encoding);
                result = reader.ReadToEnd();
            }
        }
        catch (Exception ex)
        {
            //LogHelper.Error("请求数据异常:", ex);
        }
        finally
        {
            resStream?.Close();
            reqStream?.Close();
            response?.Close();
            request?.Abort();
        }

         return result;
    }

    public static string ToJson(this object obj, string dateTimeFormat = "yyyy-MM-dd HH:mm:ss")
    {
        // 空对象返回
        if (null == obj) return string.Empty;

        try
        {
            // 日期时间格式化为空
            if (string.IsNullOrWhiteSpace(dateTimeFormat))
                    return JsonConvert.SerializeObject(obj);

            // 日期时间格式化
            var timeFormat = new IsoDateTimeConverter { DateTimeFormat = dateTimeFormat };
            return JsonConvert.SerializeObject(obj, Formatting.Indented, timeFormat);
        }
        catch (Exception ex)
        {
            throw new Exception("JsonHelper.ToJson():" + ex.Message);
        }
    }

    public static string ToUrlData(this object obj)
    {
        var type = obj.GetType();
        var properties = type.GetProperties();
        var data = string.Empty;

        foreach (var propertie in properties)
        {
            var value = propertie.GetValue(obj) ?? string.Empty;
            data += propertie.Name + "=" + value + "&";
        }
        data = data.Length > 0 ? data.Substring(0, data.Length - 1) : data;
        return data;
     }
}

解析结果:

全网短视频去水印解析提取视频_第1张图片

你可能感兴趣的:(C#,去水印)