1
mirror of https://github.com/nilaoda/N_m3u8DL-CLI synced 2025-09-15 02:00:49 +02:00

Compare commits

...

11 Commits
2.8.3 ... 2.8.6

Author SHA1 Message Date
nilaoda
0d6377d41b Update changelog.txt 2020-11-25 17:34:53 +08:00
nilaoda
9c76bdcbce 支持选择音轨 2020-11-25 17:34:12 +08:00
nilaoda
83915ff606 Update Global.cs 2020-11-25 14:12:46 +08:00
nilaoda
9cd4746f33 Update changelog.txt 2020-11-25 14:11:31 +08:00
nilaoda
33a5b917ac 修正MPD判断最高清晰度的逻辑 2020-11-25 14:08:40 +08:00
nilaoda
f69978bd82 修改芒果TV请求头 2020-11-23 21:53:41 +08:00
nilaoda
d9fd526886 Update changelog.txt 2020-11-23 21:53:26 +08:00
nilaoda
1cc8ecfaaf Update Global.cs 2020-11-23 21:30:12 +08:00
nilaoda
2bc2dde2ad 修改默认UA 2020-11-23 21:29:48 +08:00
nilaoda
c3ddcf9e0e Update Program.cs 2020-11-23 21:29:31 +08:00
nilaoda
ba5d20dd02 Update Parser.cs 2020-11-23 21:29:03 +08:00
5 changed files with 105 additions and 320 deletions

View File

@@ -32,7 +32,7 @@ namespace N_m3u8DL_CLI
/*===============================================================================*/
static Version ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
static string nowVer = $"{ver.Major}.{ver.Minor}.{ver.Build}";
static string nowDate = "20201122";
static string nowDate = "20201125";
public static void WriteInit()
{
Console.Clear();
@@ -110,7 +110,7 @@ namespace N_m3u8DL_CLI
HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
webRequest.Method = "GET";
if (NoProxy) webRequest.Proxy = null;
webRequest.UserAgent = "Mozilla/5.0 (Linux; U; Android 7.0; zh-cn; 15 Plus Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/9.4 Mobile Safari/537.36";
webRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36";
webRequest.Accept = "*/*";
webRequest.Headers.Add("Accept-Encoding", "gzip, deflate, br");
webRequest.Timeout = TimeOut; //设置超时
@@ -120,7 +120,7 @@ namespace N_m3u8DL_CLI
{
webRequest.UserAgent = "";
if (!url.Contains("/internettv/"))
webRequest.Referer = "https://player.mgtv.com/mgtv_v6_player/PlayerCore.swf";
webRequest.Referer = "https://www.mgtv.com";
webRequest.Headers.Add("Cookie", "MQGUID");
}
//添加headers
@@ -158,7 +158,7 @@ namespace N_m3u8DL_CLI
}
//文件过大则认为不是m3u8
if (webResponse.ContentLength != -1 && webRequest.ContentLength > 50 * 1024 * 1024) return "";
if (webResponse.ContentLength != -1 && webResponse.ContentLength > 50 * 1024 * 1024) return "";
if (webResponse.ContentEncoding != null
&& webResponse.ContentEncoding.ToLower() == "gzip") //如果使用了GZip则先解压
@@ -427,7 +427,7 @@ namespace N_m3u8DL_CLI
if (NoProxy) req.Proxy = null;
req.Headers.Add("Accept-Encoding", "gzip, deflate");
req.Accept = "*/*";
req.UserAgent = "Mozilla/5.0 (Linux; U; Android 7.0; zh-cn; 15 Plus Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/9.4 Mobile Safari/537.36";
req.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36";
//添加headers
if (headers != "")
{
@@ -536,11 +536,11 @@ namespace N_m3u8DL_CLI
{
request.UserAgent = "";
if (!url.Contains("/internettv/"))
request.Referer = "https://player.mgtv.com/mgtv_v6_player/PlayerCore.swf";
request.Referer = "https://www.mgtv.com";
request.Headers.Add("Cookie", "MQGUID");
}
else
request.UserAgent = "Mozilla/5.0 (Linux; U; Android 7.0; zh-cn; 15 Plus Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/9.4 Mobile Safari/537.36";
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36";
//下载部分字节
if (expectByte != -1)
request.AddRange("bytes", startByte, startByte + expectByte - 1);

View File

@@ -112,9 +112,9 @@ namespace N_m3u8DL_CLI
/// <param name="downDir">文件存储目录</param>
/// <param name="mpdUrl">MPD链接</param>
/// <param name="mpdContent">MPD内容</param>
/// <param name="customBase">自定义BaseUrl</param>
/// <param name="defaultBase">BaseUrl</param>
/// <returns></returns>
public static string Parse(string downDir, string mpdUrl, string mpdContent, string customBase = "")
public static string Parse(string downDir, string mpdUrl, string mpdContent, string defaultBase = "")
{
XmlDocument mpdDoc = new XmlDocument();
mpdDoc.LoadXml(mpdContent);
@@ -194,7 +194,7 @@ namespace N_m3u8DL_CLI
return url;
}
var mpdBaseUrl = string.IsNullOrEmpty(customBase) ? GetBaseUrl(mpdUrl) : customBase;
var mpdBaseUrl = string.IsNullOrEmpty(defaultBase) ? GetBaseUrl(mpdUrl) : defaultBase;
if (!string.IsNullOrEmpty(mpdBaseUrl) && !CheckBaseUrl())
{
if (!mpdBaseUrl.EndsWith("/") && !baseUrl.StartsWith("/"))
@@ -214,7 +214,7 @@ namespace N_m3u8DL_CLI
["Height"] = IntOrNull(GetAttribute("height")),
["Tbr"] = DoubleOrNull(bandwidth, 1000),
["Asr"] = IntOrNull(GetAttribute("audioSamplingRate")),
["Fps"] = IntOrNull(GetAttribute("audioSamplingRate")),
["Fps"] = IntOrNull(GetAttribute("frameRate")),
["Language"] = lang,
["Codecs"] = GetAttribute("codecs")
};
@@ -429,9 +429,68 @@ namespace N_m3u8DL_CLI
}
}
//排序
formatList.Sort((a, b) =>
{
return (a["Width"] + a["Height"]) * 1000 + a["Tbr"] > (b["Width"] + b["Height"]) * 1000 + b["Tbr"] ? -1 : 1;
});
//默认为最高码率的视频和音频
var bestVideo = SelectBestVideo(formatList);
var bestAudio = SelectBestAudio(formatList);
var audioLangList = new List<string>();
formatList.ForEach(f =>
{
if (f["Width"] == -1 && !audioLangList.Contains(f["Language"])) audioLangList.Add(f["Language"]);
});
if (audioLangList.Count > 1)
{
string Stringify(Dictionary<string, dynamic> f)
{
var type = f["Width"] == -1 && f["Height"] == -1 ? "Audio" : "Video";
var res = type == "Video" ? $"[{f["Width"]}x{f["Height"]}]" : "";
var id = $"[{f["FormatId"]}] ";
var tbr = $"[{((int)f["Tbr"]).ToString().PadLeft(4)} Kbps] ";
var asr = f["Asr"] != -1 ? $"[{f["Asr"]} Hz] " : "";
var fps = f["Fps"] != -1 ? $"[{f["Fps"]} fps] " : "";
var lang = string.IsNullOrEmpty(f["Language"]) ? "" : $"[{f["Language"]}] ";
var codecs = $"[{f["Codecs"]}] ";
return $"{type} => {id}{tbr}{asr}{fps}{lang}{codecs}{res}";
}
for (int i = 0; i < formatList.Count; i++)
{
Console.WriteLine("".PadRight(13) + $"[{i.ToString().PadLeft(2)}]. {Stringify(formatList[i])}");
LOGGER.CursorIndex++;
}
Console.CursorVisible = true;
LOGGER.PrintLine("Found Multiple Language Audio Tracks.\r\n" + "".PadRight(13) + "Please Select What You Want(Up to 1 Video and 1 Audio).");
Console.Write("".PadRight(13) + "Enter Numbers Separated By A Space: ");
var input = Console.ReadLine();
LOGGER.CursorIndex += 2;
Console.CursorVisible = false;
if (!string.IsNullOrEmpty(input))
{
bestVideo = new Dictionary<string, dynamic>() { ["Tbr"] = 0 };
bestAudio = new Dictionary<string, dynamic>() { ["Tbr"] = 0 };
foreach (var index in input.Split())
{
var n = 0;
int.TryParse(index, out n);
if (formatList[n]["Width"] == -1)
{
bestAudio = formatList[n];
}
else
{
bestVideo = formatList[n];
}
}
}
}
if (bestVideo.Keys.Count > 1 && bestAudio.Keys.Count > 1) //音视频
{
return GenerateMasterList(downDir, bestVideo, bestAudio);
@@ -442,7 +501,7 @@ namespace N_m3u8DL_CLI
}
else if (bestVideo.Keys.Count > 1) //仅有视频
{
return GenerateMasterList(downDir, bestAudio);
return GenerateMasterList(downDir, bestVideo);
}
else
{
@@ -472,26 +531,42 @@ namespace N_m3u8DL_CLI
//Video
if (m3u8.Contains("#EXT-VIDEO-WIDTH"))
{
var _path = Path.Combine(downDir, "bestVideo.m3u8");
var _path = Path.Combine(downDir, "mpdVideo.m3u8");
File.WriteAllText(_path, m3u8);
videoPath = new Uri(_path).ToString();
res = f["Width"] + "x" + f["Height"];
}
else
{
if (!Directory.Exists(downDir + "(Audio)"))
Directory.CreateDirectory(downDir + "(Audio)");
var _path = Path.Combine(downDir + "(Audio)", "bestAudio.m3u8");
var _path = Path.Combine(downDir, "mpdAudio.m3u8");
File.WriteAllText(_path, m3u8);
audioPath = new Uri(_path).ToString();
}
codecsList.Add(f["Codecs"]);
}
var content = $"#EXTM3U\r\n" +
$"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"{audioPath}\",GROUP-ID=\"default-audio-group\",NAME=\"stream_0\",AUTOSELECT=YES,CHANNELS=\"0\"\r\n" +
$"#EXT-X-STREAM-INF:BANDWIDTH={bandwidth},CODECS=\"{string.Join(",", codecsList)}\",RESOLUTION={res},AUDIO=\"default-audio-group\"\r\n" +
$"{videoPath}";
var content = "";
if (videoPath == "" && audioPath != "")
{
return audioPath;
}
else if (audioPath == "" && videoPath != "")
{
return videoPath;
}
else
{
if (!Directory.Exists(downDir + "(Audio)"))
Directory.CreateDirectory(downDir + "(Audio)");
var _path = Path.Combine(downDir + "(Audio)", "mpdAudio.m3u8");
File.Copy(new Uri(audioPath).LocalPath, _path);
audioPath = new Uri(_path).ToString();
content = $"#EXTM3U\r\n" +
$"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"{audioPath}\",GROUP-ID=\"default-audio-group\",NAME=\"stream_0\",AUTOSELECT=YES,CHANNELS=\"0\"\r\n" +
$"#EXT-X-STREAM-INF:BANDWIDTH={bandwidth},CODECS=\"{string.Join(",", codecsList)}\",RESOLUTION={res},AUDIO=\"default-audio-group\"\r\n" +
$"{videoPath}";
}
var _masterPath = Path.Combine(downDir, "master.m3u8");
File.WriteAllText(_masterPath, content);
return new Uri(_masterPath).ToString();
@@ -548,6 +623,7 @@ namespace N_m3u8DL_CLI
if (f["Tbr"] > bandwidth)
{
best = f;
bandwidth = f["Tbr"];
}
}
}
@@ -569,6 +645,7 @@ namespace N_m3u8DL_CLI
if (f["Tbr"] > bandwidth)
{
best = f;
bandwidth = f["Tbr"];
}
}
}

View File

@@ -864,9 +864,7 @@ namespace N_m3u8DL_CLI
/// <returns></returns>
public static string GetBaseUrl(string m3u8url, string headers)
{
if (!isQiQiuYun && Global.Get302(m3u8url, headers) != m3u8url)
m3u8url = Global.Get302(m3u8url, headers);
string url = Global.Get302(m3u8url);
string url = Global.Get302(m3u8url, headers);
if (url.Contains("?"))
url = url.Remove(url.LastIndexOf('?'));
url = url.Substring(0, url.LastIndexOf('/') + 1);

File diff suppressed because it is too large Load Diff

View File

@@ -287,4 +287,10 @@
- 修复BUG
2020年11月22日
- 解决HTTPS协议自动重定向后Referer丢失问题
- 新的任务速度监控逻辑
- 新的任务速度监控逻辑
2020年11月23日
- 将默认UA修改为 Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
- 修改芒果TV请求头
2020年11月25日
- 修正MPD判断最高清晰度的逻辑
- 在MPD输入下支持选择音轨