diff --git a/MusicLyricApp/Bean/Constants.cs b/MusicLyricApp/Bean/Constants.cs
index 450c71b..a80bbea 100644
--- a/MusicLyricApp/Bean/Constants.cs
+++ b/MusicLyricApp/Bean/Constants.cs
@@ -61,7 +61,7 @@ public static string GetContent(TypeEnum typeEnum)
list.Add("当毫秒的占位符为 S 或 SS 时,『毫秒截位规则』配置生效");
break;
case TypeEnum.OUTPUT_SETTING:
- list.Add("您可自行调整『输出文件名』配置,系统预设的元变量有:");
+ list.Add("您可自行调整『保存文件名』配置,系统预设的元变量有:");
list.Add("${id} -> 歌曲 ID");
list.Add("${index} -> 歌曲位于搜索结果中的索引序号");
list.Add("${name} -> 歌曲名");
@@ -76,7 +76,7 @@ public static string GetContent(TypeEnum typeEnum)
list.Add("-----");
list.Add("您可自行决定输出哪些歌词类型,通过勾选复选框进行启用和关闭");
list.Add("拖拽最左侧的箭头可以调整输出的顺序");
- list.Add("罗马音功能需要安装罗马音插件,非原始译文类型需要指定翻译 API");
+ list.Add("罗马音功能需要安装罗马音插件;非原始译文类型需要指定翻译 API");
break;
case TypeEnum.DEFAULT:
default:
diff --git a/MusicLyricApp/Bean/SettingBase.cs b/MusicLyricApp/Bean/SettingBase.cs
index f36d968..3204d56 100644
--- a/MusicLyricApp/Bean/SettingBase.cs
+++ b/MusicLyricApp/Bean/SettingBase.cs
@@ -39,6 +39,11 @@ public class ConfigBean
///
public bool IgnorePureMusicInSave = true;
+ ///
+ /// 对于 "独立" 歌词格式,保存在不同的文件中
+ ///
+ public bool SeparateFileForIsolated = false;
+
///
/// 输出文件名格式
///
diff --git a/MusicLyricApp/MainForm.cs b/MusicLyricApp/MainForm.cs
index d12c40e..f4991d0 100644
--- a/MusicLyricApp/MainForm.cs
+++ b/MusicLyricApp/MainForm.cs
@@ -8,6 +8,7 @@
using System.Reflection;
using System.Text;
using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
using MusicLyricApp.Api.Music;
using MusicLyricApp.Bean;
@@ -574,11 +575,7 @@ private async void SingleSave()
try
{
- using (var sw = new StreamWriter(saveDialog.FileName, false, GlobalUtils.GetEncoding(_globalSearchInfo.SettingBean.Param.Encoding)))
- {
- await sw.WriteAsync(await LyricUtils.GetOutputContent(saveVo.LyricVo, _globalSearchInfo));
- await sw.FlushAsync();
- }
+ await WriteToFile(saveDialog.FileName, saveVo.LyricVo);
MessageBox.Show(string.Format(ErrorMsg.SAVE_COMPLETE, 1, 0), "提示");
}
@@ -626,12 +623,9 @@ private async void BatchSave()
}
var path = filePath + '/' + GlobalUtils.GetOutputName(saveVo, _globalSearchInfo.SettingBean.Config.OutputFileNameFormat) + fileSuffix;
- using(var sw = new StreamWriter(path, false, GlobalUtils.GetEncoding(_globalSearchInfo.SettingBean.Param.Encoding)))
- {
- await sw.WriteAsync(await LyricUtils.GetOutputContent(lyricVo, _globalSearchInfo));
- await sw.FlushAsync();
- success.Add(item.Key);
- }
+
+ await WriteToFile(path, lyricVo);
+ success.Add(item.Key);
}
MessageBox.Show(string.Format(ErrorMsg.SAVE_COMPLETE, success.Count, skipCount), "提示");
@@ -653,6 +647,37 @@ private async void BatchSave()
UpdateLrcTextBox(log.ToString());
}
+ private async Task WriteToFile(string path, LyricVo lyricVo)
+ {
+ var encoding = GlobalUtils.GetEncoding(_globalSearchInfo.SettingBean.Param.Encoding);
+
+ var res = await LyricUtils.GetOutputContent(lyricVo, _globalSearchInfo);
+
+ if (res.Count == 1)
+ {
+ using (var sw = new StreamWriter(path, false, encoding))
+ {
+ await sw.WriteAsync(res[0]);
+ await sw.FlushAsync();
+ }
+ }
+ else
+ {
+ var doxIndex = path.LastIndexOf(".", StringComparison.Ordinal);
+ var suffix = path.Substring(doxIndex);
+ path = path.Substring(0, doxIndex);
+
+ for (var i = 0; i < res.Count; i++)
+ {
+ using (var sw = new StreamWriter(path + " - " + i + suffix, false, encoding))
+ {
+ await sw.WriteAsync(res[i]);
+ await sw.FlushAsync();
+ }
+ }
+ }
+ }
+
/**
* 保存按钮点击事件
*/
@@ -695,7 +720,7 @@ private async void UpdateLrcTextBox(string replace)
}
else
{
- Console_TextBox.Text = await LyricUtils.GetOutputContent(lyricVo, _globalSearchInfo);
+ Console_TextBox.Text = GlobalUtils.MergeStr(await LyricUtils.GetOutputContent(lyricVo, _globalSearchInfo));
}
}
}
diff --git a/MusicLyricApp/SettingForm.Designer.cs b/MusicLyricApp/SettingForm.Designer.cs
index 16e7317..5085205 100644
--- a/MusicLyricApp/SettingForm.Designer.cs
+++ b/MusicLyricApp/SettingForm.Designer.cs
@@ -66,6 +66,7 @@ private void AfterInitializeComponent()
// 输出设置
IgnorePureMusicInSave_CheckBox.Checked = _settingBean.Config.IgnorePureMusicInSave;
+ SeparateFileForIsolated_CheckBox.Checked = _settingBean.Config.SeparateFileForIsolated;
OutputName_TextBox.Text = _settingBean.Config.OutputFileNameFormat;
// 应用设置
@@ -138,6 +139,7 @@ private void InitializeComponent()
this.Column1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Output_GroupBox = new System.Windows.Forms.GroupBox();
+ this.SeparateFileForIsolated_CheckBox = new System.Windows.Forms.CheckBox();
this.OutputName_TextBox = new System.Windows.Forms.TextBox();
this.label10 = new System.Windows.Forms.Label();
this.IgnorePureMusicInSave_CheckBox = new System.Windows.Forms.CheckBox();
@@ -619,6 +621,7 @@ private void InitializeComponent()
//
// Output_GroupBox
//
+ this.Output_GroupBox.Controls.Add(this.SeparateFileForIsolated_CheckBox);
this.Output_GroupBox.Controls.Add(this.OutputName_TextBox);
this.Output_GroupBox.Controls.Add(this.label10);
this.Output_GroupBox.Controls.Add(this.IgnorePureMusicInSave_CheckBox);
@@ -632,6 +635,15 @@ private void InitializeComponent()
this.Output_GroupBox.TabStop = false;
this.Output_GroupBox.Text = "输出设置";
//
+ // SeparateFileForIsolated_CheckBox
+ //
+ this.SeparateFileForIsolated_CheckBox.Location = new System.Drawing.Point(226, 61);
+ this.SeparateFileForIsolated_CheckBox.Name = "SeparateFileForIsolated_CheckBox";
+ this.SeparateFileForIsolated_CheckBox.Size = new System.Drawing.Size(202, 17);
+ this.SeparateFileForIsolated_CheckBox.TabIndex = 39;
+ this.SeparateFileForIsolated_CheckBox.Text = "“独立”歌词格式分文件保存";
+ this.SeparateFileForIsolated_CheckBox.UseVisualStyleBackColor = true;
+ //
// OutputName_TextBox
//
this.OutputName_TextBox.Location = new System.Drawing.Point(222, 125);
@@ -645,13 +657,13 @@ private void InitializeComponent()
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(65, 12);
this.label10.TabIndex = 37;
- this.label10.Text = "输出文件名";
+ this.label10.Text = "保存文件名";
//
// IgnorePureMusicInSave_CheckBox
//
this.IgnorePureMusicInSave_CheckBox.Location = new System.Drawing.Point(226, 23);
this.IgnorePureMusicInSave_CheckBox.Name = "IgnorePureMusicInSave_CheckBox";
- this.IgnorePureMusicInSave_CheckBox.Size = new System.Drawing.Size(93, 29);
+ this.IgnorePureMusicInSave_CheckBox.Size = new System.Drawing.Size(93, 17);
this.IgnorePureMusicInSave_CheckBox.TabIndex = 36;
this.IgnorePureMusicInSave_CheckBox.Text = "跳过纯音乐";
this.IgnorePureMusicInSave_CheckBox.UseVisualStyleBackColor = true;
@@ -710,6 +722,8 @@ private void InitializeComponent()
this.PerformLayout();
}
+ private System.Windows.Forms.CheckBox SeparateFileForIsolated_CheckBox;
+
private System.Windows.Forms.CheckBox AggregatedBlurSearchCheckBox;
private System.Windows.Forms.TextBox BaiduTranslateAppId_TextBox;
diff --git a/MusicLyricApp/SettingForm.cs b/MusicLyricApp/SettingForm.cs
index 5a4cb13..2105ad3 100644
--- a/MusicLyricApp/SettingForm.cs
+++ b/MusicLyricApp/SettingForm.cs
@@ -78,6 +78,7 @@ private void Close_Btn_Click(object sender, EventArgs e)
// 输出设置
_settingBean.Config.IgnorePureMusicInSave = IgnorePureMusicInSave_CheckBox.Checked;
+ _settingBean.Config.SeparateFileForIsolated = SeparateFileForIsolated_CheckBox.Checked;
_settingBean.Config.OutputFileNameFormat = OutputName_TextBox.Text;
// 应用设置
diff --git a/MusicLyricApp/Utils/GlobalUtils.cs b/MusicLyricApp/Utils/GlobalUtils.cs
index 419ea35..55cc355 100644
--- a/MusicLyricApp/Utils/GlobalUtils.cs
+++ b/MusicLyricApp/Utils/GlobalUtils.cs
@@ -331,6 +331,11 @@ public static int toInt(string str, int defaultValue)
return result;
}
+ public static string MergeStr(IEnumerable strList)
+ {
+ return string.Join(Environment.NewLine, strList);
+ }
+
public static List GetEnumList() where T : Enum
{
return Enum.GetValues(typeof(T)).OfType().ToList();
diff --git a/MusicLyricApp/Utils/LyricUtils.cs b/MusicLyricApp/Utils/LyricUtils.cs
index c40be42..dabfaa5 100644
--- a/MusicLyricApp/Utils/LyricUtils.cs
+++ b/MusicLyricApp/Utils/LyricUtils.cs
@@ -25,28 +25,38 @@ public abstract class LyricUtils
///
///
///
- public static async Task GetOutputContent(LyricVo lyricVo, SearchInfo searchInfo)
+ public static async Task> GetOutputContent(LyricVo lyricVo, SearchInfo searchInfo)
{
var param = searchInfo.SettingBean.Param;
var dotType = param.DotType;
var timestampFormat = param.OutputFileFormat == OutputFormatEnum.SRT ? param.SrtTimestampFormat : param.LrcTimestampFormat;
- var voList = await FormatLyric(lyricVo.Lyric, lyricVo.TranslateLyric, searchInfo);
+ var voListList = await FormatLyric(lyricVo.Lyric, lyricVo.TranslateLyric, searchInfo);
if (searchInfo.SettingBean.Param.EnableVerbatimLyric)
{
- voList = FormatSubLineLyric(voList, timestampFormat, dotType);
+ for (var i = 0; i < voListList.Count; i++)
+ {
+ voListList[i] = FormatSubLineLyric(voListList[i], timestampFormat, dotType);
+ }
}
+
+ var res = new List();
- if (param.OutputFileFormat == OutputFormatEnum.SRT)
+ foreach (var voList in voListList)
{
- return SrtUtils.LrcToSrt(voList, timestampFormat, dotType, lyricVo.Duration);
- }
- else
- {
- return string.Join(Environment.NewLine, from o in voList select o.Print(timestampFormat, dotType));
+ if (param.OutputFileFormat == OutputFormatEnum.SRT)
+ {
+ res.Add(SrtUtils.LrcToSrt(voList, timestampFormat, dotType, lyricVo.Duration));
+ }
+ else
+ {
+ res.Add(string.Join(Environment.NewLine, from o in voList select o.Print(timestampFormat, dotType)));
+ }
}
+
+ return res;
}
///
@@ -143,17 +153,19 @@ private static List FormatSubLineLyric(List vos, strin
/// 原始的译文内容
/// 处理参数
///
- private static async Task> FormatLyric(string originLrc, string translateLrc, SearchInfo searchInfo)
+ private static async Task>> FormatLyric(string originLrc, string translateLrc, SearchInfo searchInfo)
{
var outputLyricsTypes = searchInfo.SettingBean.Config.DeserializationOutputLyricsTypes();
var showLrcType = searchInfo.SettingBean.Param.ShowLrcType;
var searchSource = searchInfo.SettingBean.Param.SearchSource;
var ignoreEmptyLyric = searchInfo.SettingBean.Param.IgnoreEmptyLyric;
+ var res = new List>();
+
// 未配置任何输出
if (outputLyricsTypes.Count == 0)
{
- return new List();
+ return res;
}
var originLyrics = SplitLrc(originLrc, searchSource, ignoreEmptyLyric);
@@ -163,7 +175,8 @@ private static async Task> FormatLyric(string originLrc, strin
// 仅输出原文
if (outputLyricsTypes.Count == 1 && originLyricsOutputSortInConfig != -1)
{
- return originLyrics;
+ res.Add(originLyrics);
+ return res;
}
// 原始译文歌词的空行没有意义,指定 true 不走配置
@@ -176,33 +189,44 @@ private static async Task> FormatLyric(string originLrc, strin
{
lyricsComplexList.Insert(originLyricsOutputSortInConfig, originLyrics);
}
-
- var res = new List();
+ var single = new List();
switch (showLrcType)
{
case ShowLrcTypeEnum.STAGGER:
foreach (var each in lyricsComplexList)
{
- res = SortLrc(res, each, true);
+ single = SortLrc(single, each, true);
}
break;
case ShowLrcTypeEnum.ISOLATED:
- foreach (var each in lyricsComplexList)
+ if (searchInfo.SettingBean.Config.SeparateFileForIsolated)
+ {
+ res.AddRange(lyricsComplexList);
+ }
+ else
{
- res.AddRange(each);
+ foreach (var each in lyricsComplexList)
+ {
+ single.AddRange(each);
+ }
}
break;
case ShowLrcTypeEnum.MERGE:
foreach (var each in lyricsComplexList)
{
- res = MergeLrc(res, each, searchInfo.SettingBean.Param.LrcMergeSeparator, true);
+ single = MergeLrc(single, each, searchInfo.SettingBean.Param.LrcMergeSeparator, true);
}
break;
default:
throw new NotSupportedException("not support showLrcType: " + showLrcType);
}
+ if (single.Count > 0)
+ {
+ res.Add(single);
+ }
+
return res;
}