修复SRT格式字幕覆盖问题

This commit is contained in:
nilaoda 2022-10-14 19:16:57 +08:00
parent 13a26d08a4
commit 2299241d9d
3 changed files with 6 additions and 12 deletions

View File

@ -52,7 +52,7 @@ namespace N_m3u8DL_RE.Common.Util
Logger.Debug(webRequest.Headers.ToString());
//手动处理跳转以免自定义Headers丢失
var webResponse = await AppHttpClient.SendAsync(webRequest, HttpCompletionOption.ResponseHeadersRead);
if (webResponse.StatusCode == HttpStatusCode.Found || webResponse.StatusCode == HttpStatusCode.Moved)
if (webResponse.StatusCode == HttpStatusCode.Found || webResponse.StatusCode == HttpStatusCode.Moved || webResponse.StatusCode == HttpStatusCode.SeeOther)
{
HttpResponseHeaders respHeaders = webResponse.Headers;
Logger.Debug(respHeaders.ToString());

View File

@ -433,7 +433,7 @@ namespace N_m3u8DL_RE.CommandLine
Environment.Exit(0);
}
var rootCommand = new RootCommand("N_m3u8DL-RE (Beta version) 20221011")
var rootCommand = new RootCommand("N_m3u8DL-RE (Beta version) 20221014")
{
Input, TmpDir, SaveDir, SaveName, BaseUrl, ThreadCount, DownloadRetryCount, AutoSelect, SkipMerge, SkipDownload, CheckSegmentsCount,
BinaryMerge, DelAfterDone, WriteMetaJson, AppendUrlParams, ConcurrentDownload, Headers, /**SavePattern,**/ SubOnly, SubtitleFormat, AutoSubtitleFix,

View File

@ -291,6 +291,10 @@ namespace N_m3u8DL_RE.DownloadManager
else if (streamSpec.MediaType == MediaType.AUDIO && streamSpec.Extension == "m4s") outputExt = ".m4a";
else if (streamSpec.MediaType != MediaType.SUBTITLES && streamSpec.Extension == "m4s") outputExt = ".mp4";
if (DownloaderConfig.MyOptions.SubtitleFormat == Enum.SubtitleFormat.SRT && outputExt == ".vtt")
{
outputExt = ".srt";
}
var output = Path.Combine(saveDir, saveName + outputExt);
//检测目标文件是否存在
@ -369,7 +373,6 @@ namespace N_m3u8DL_RE.DownloadManager
{
path = Path.ChangeExtension(path, ".srt");
subContentFixed = OtherUtil.WebVtt2Other(finalVtt, DownloaderConfig.MyOptions.SubtitleFormat);
output = Path.ChangeExtension(output, ".srt");
}
await File.WriteAllTextAsync(path, subContentFixed, Encoding.UTF8);
FileDic[keys.First()] = new DownloadResult()
@ -404,7 +407,6 @@ namespace N_m3u8DL_RE.DownloadManager
{
path = Path.ChangeExtension(path, ".srt");
subContentFixed = OtherUtil.WebVtt2Other(finalVtt, DownloaderConfig.MyOptions.SubtitleFormat);
output = Path.ChangeExtension(output, ".srt");
}
await File.WriteAllTextAsync(path, subContentFixed, Encoding.UTF8);
FileDic[firstKey] = new DownloadResult()
@ -412,8 +414,6 @@ namespace N_m3u8DL_RE.DownloadManager
ActualContentLength = subContentFixed.Length,
ActualFilePath = path
};
//修改输出后缀
output = Path.ChangeExtension(output, Path.GetExtension(path));
}
}
@ -437,7 +437,6 @@ namespace N_m3u8DL_RE.DownloadManager
{
path = Path.ChangeExtension(path, ".srt");
subContentFixed = OtherUtil.WebVtt2Other(finalVtt, DownloaderConfig.MyOptions.SubtitleFormat);
output = Path.ChangeExtension(output, ".srt");
}
await File.WriteAllTextAsync(path, subContentFixed, Encoding.UTF8);
FileDic[firstKey] = new DownloadResult()
@ -445,8 +444,6 @@ namespace N_m3u8DL_RE.DownloadManager
ActualContentLength = subContentFixed.Length,
ActualFilePath = path
};
//修改输出后缀
output = Path.ChangeExtension(output, Path.GetExtension(path));
}
//自动修复TTML mp4字幕
@ -474,7 +471,6 @@ namespace N_m3u8DL_RE.DownloadManager
{
path = Path.ChangeExtension(path, ".srt");
subContentFixed = OtherUtil.WebVtt2Other(finalVtt, DownloaderConfig.MyOptions.SubtitleFormat);
output = Path.ChangeExtension(output, ".srt");
}
await File.WriteAllTextAsync(path, subContentFixed, Encoding.UTF8);
FileDic[firstKey] = new DownloadResult()
@ -482,8 +478,6 @@ namespace N_m3u8DL_RE.DownloadManager
ActualContentLength = subContentFixed.Length,
ActualFilePath = path
};
//修改输出后缀
output = Path.ChangeExtension(output, Path.GetExtension(path));
}
bool mergeSuccess = false;