Last active
December 5, 2021 04:50
-
-
Save chenxuuu/53d4444f3fc931d3d0d57d7fe83b832f to your computer and use it in GitHub Desktop.
(niceloo.com)优路教育视频批量下载+解码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Linq; | |
using System.Net; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
using System.Threading.Tasks; | |
namespace VideoConvertTool | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
while(true) | |
{ | |
Stream steam = Console.OpenStandardInput(); | |
Console.SetIn(new StreamReader(steam, Encoding.Default, false, 500000)); | |
Console.WriteLine("输入网页部分内容:"); | |
string input = Console.ReadLine(); | |
Console.WriteLine("请等待程序运行"); | |
MatchCollection matchs = Reg_solve(input, | |
"data-vid=\\\"(?<link>.*?)_f(.*?)title=(.*?)>(?<name>.*?)</a>"); | |
foreach (Match item in matchs) | |
{ | |
if (item.Success) | |
{ | |
Console.WriteLine("正在处理" + item.Groups["link"].Value+","+ item.Groups["name"].Value); | |
string linkCode = item.Groups["link"].Value; | |
string link = "http://hls.videocc.net/" + linkCode.Substring(0, 10) + | |
"/"+ linkCode.Substring(linkCode.Length-1)+ "/" + linkCode + "_1.m3u8"; | |
Console.WriteLine("正在获取" + link); | |
string decodeData = HttpGet(link, ""); | |
FileStream fs = new FileStream("i.m3u8", FileMode.Create, FileAccess.ReadWrite); //可以指定盘符,也可以指定任意文件名,还可以为word等文件 | |
StreamWriter sw = new StreamWriter(fs); // 创建写入流 | |
sw.Write(decodeData); | |
sw.Close(); //关闭文件 | |
//ffmpeg -protocol_whitelist http,file,crypto,tcp -i i.m3u8 -c copy new.mp4 | |
RunCmd("ffmpeg", "-protocol_whitelist http,file,crypto,tcp -i i.m3u8 -c copy " + item.Groups["name"].Value + ".mp4"); | |
Console.WriteLine(item.Groups["name"].Value + "解密完成"); | |
} | |
} | |
Console.WriteLine("跑完了,请重开"); | |
Console.ReadLine(); | |
} | |
} | |
/// <summary> | |
/// 运行cmd命令 | |
/// 会显示命令窗口 | |
/// </summary> | |
/// <param name="cmdExe">指定应用程序的完整路径</param> | |
/// <param name="cmdStr">执行命令行参数</param> | |
static bool RunCmd(string cmdExe, string cmdStr) | |
{ | |
bool result = false; | |
try | |
{ | |
using (Process myPro = new Process()) | |
{ | |
//指定启动进程是调用的应用程序和命令行参数 | |
ProcessStartInfo psi = new ProcessStartInfo(cmdExe, cmdStr); | |
myPro.StartInfo = psi; | |
myPro.Start(); | |
myPro.WaitForExit(); | |
result = true; | |
} | |
} | |
catch | |
{ | |
} | |
return result; | |
} | |
/// <summary> | |
/// GET 请求与获取结果 | |
/// </summary> | |
public static string HttpGet(string Url, string postDataStr) | |
{ | |
try | |
{ | |
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr); | |
request.Method = "GET"; | |
request.ContentType = "text/html;charset=UTF-8"; | |
request.Timeout = 5000; | |
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); | |
Stream myResponseStream = response.GetResponseStream(); | |
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8); | |
string retString = myStreamReader.ReadToEnd(); | |
myStreamReader.Close(); | |
myResponseStream.Close(); | |
return retString; | |
} | |
catch { } | |
return ""; | |
} | |
public static MatchCollection Reg_solve(string str, string regstr) | |
{ | |
Regex reg = new Regex(regstr, RegexOptions.IgnoreCase); | |
return reg.Matches(str); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
您好,请问这个可以下载至本地观看嘛?