Skip to content

Commit

Permalink
Merge pull request #40 from jitwxs/dev
Browse files Browse the repository at this point in the history
Release v3.6
  • Loading branch information
jitwxs authored Mar 12, 2022
2 parents af18ef1 + 451e82d commit d299bf3
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 100 deletions.
47 changes: 37 additions & 10 deletions WindowsFormsApp1/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 54 additions & 29 deletions WindowsFormsApp1/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public partial class MainForm : Form
// 输出文件名类型
OUTPUT_FILENAME_TYPE_ENUM output_filename_type_enum;

public const string Version = "v3.5";
// 输出文件类型
OUTPUT_FORMAT_ENUM output_format_enum;

public const string Version = "v3.6";

public MainForm()
{
Expand All @@ -44,6 +47,7 @@ public MainForm()
comboBox_diglossia_lrc.SelectedIndex = 0;
comboBox_search_type.SelectedIndex = 0;
comboBox_dot.SelectedIndex = 0;
comboBox_output_format.SelectedIndex = 0;

_api = new NetEaseMusicApiWrapper();
}
Expand All @@ -56,13 +60,14 @@ private void ReloadConfig()
{
_globalSearchInfo.InputIds[i] = ids[i].Trim();
}

_globalSearchInfo.SONG_IDS.Clear();
_globalSearchInfo.SearchType = search_type_enum;
_globalSearchInfo.OutputFileNameType = output_filename_type_enum;
_globalSearchInfo.ShowLrcType = show_lrc_type_enum;
_globalSearchInfo.Encoding = output_encoding_enum;
_globalSearchInfo.DotType = dot_type_enum;
_globalSearchInfo.OutputFileFormat = output_format_enum;
_globalSearchInfo.LrcMergeSeparator = splitTextBox.Text;
}

Expand Down Expand Up @@ -95,9 +100,22 @@ private Dictionary<long, SongVo> RequestSongVo(long[] songIds, out Dictionary<lo
foreach (var pair in datumDict)
{
var songId = pair.Key;

result[songId] = NetEaseMusicUtils.GetSongVo(pair.Value, songDict[songId], out var errorMsg);
errorMsgs[songId] = errorMsg;
var datum = pair.Value;

if (!songDict.TryGetValue(songId, out var song))
{
errorMsgs[songId] = ErrorMsg.SONG_NOT_EXIST;
continue;
}

result[songId] = new SongVo
{
Links = datum.Url,
Name = song.Name,
Singer = NetEaseMusicUtils.ContractSinger(song.Ar),
Album = song.Al.Name
};
errorMsgs[songId] = ErrorMsg.SUCCESS;
}

return result;
Expand Down Expand Up @@ -136,18 +154,19 @@ private void SearchBySongId(IEnumerable<long> songIds, out Dictionary<long, stri
{
return;
}

foreach (var pair in RequestSongVo(requestId.ToArray(), out var songVoErrorMsg))

var requestResult = RequestSongVo(requestId.ToArray(), out var songVoErrorMsg);
foreach (var errorPair in songVoErrorMsg)
{
var songId = pair.Key;

var errorMsg = songVoErrorMsg[songId];
var songId = errorPair.Key;
var errorMsg = errorPair.Value;

if (errorMsg == ErrorMsg.SUCCESS)
{
var lyricVo = RequestLyricVo(songId, _globalSearchInfo, out errorMsg);
if (errorMsg == ErrorMsg.SUCCESS)
{
NetEaseMusicCache.PutSaveVo(songId, new SaveVo(songId, pair.Value, lyricVo));
NetEaseMusicCache.PutSaveVo(songId, new SaveVo(songId, requestResult[songId], lyricVo));
errorMsgDict.Add(songId, ErrorMsg.SUCCESS);
continue;
}
Expand Down Expand Up @@ -244,11 +263,11 @@ private void BatchSearch(IEnumerable<long> ids)
_globalSaveVoMap.Add(songId, NetEaseMusicCache.GetSaveVo(songId));
}

log.Append("ID: " + songId + ", Result: " + message + "\r\n");
log.Append("ID: " + songId + ", Result: " + message).Append(Environment.NewLine);
}

log.Append("---Total:" + resultMaps.Count + ", Success:" + _globalSaveVoMap.Count + ", Failure:" +
(resultMaps.Count - _globalSaveVoMap.Count) + "---\r\n");
(resultMaps.Count - _globalSaveVoMap.Count) + "---").Append(Environment.NewLine);

UpdateLrcTextBox(log.ToString());
}
Expand Down Expand Up @@ -307,8 +326,9 @@ private void songUrlBtn_Click(object sender, EventArgs e)
if (saveVo != null)
{
link = saveVo.SongVo.Links ?? "failure";
}
log.Append($"ID: {songId}, Links: {link}\r\n");
}

log.Append($"ID: {songId}, Links: {link}").Append(Environment.NewLine);
}

UpdateLrcTextBox(log.ToString());
Expand Down Expand Up @@ -358,11 +378,11 @@ private void SingleSave(long songId)
}

saveDialog.FileName = outputFileName;
saveDialog.Filter = "lrc文件(*.lrc)|*.lrc|txt文件(*.txt)|*.txt";
saveDialog.Filter = output_format_enum.ToDescription();
if (saveDialog.ShowDialog() == DialogResult.OK)
{
var sw = new StreamWriter(saveDialog.FileName, false, NetEaseMusicUtils.GetEncoding(_globalSearchInfo.Encoding));
sw.Write(textBox_lrc.Text);
sw.Write(NetEaseMusicUtils.GetOutputContent(saveVo.LyricVo, _globalSearchInfo));
sw.Flush();
sw.Close();
MessageBox.Show(ErrorMsg.SAVE_SUCCESS, "提示");
Expand All @@ -383,7 +403,7 @@ private void BatchSave()
try
{
saveDialog.FileName = "直接选择保存路径即可,无需修改此处内容";
saveDialog.Filter = "lrc文件(*.lrc)|*.lrc|txt文件(*.txt)|*.txt";
saveDialog.Filter = output_format_enum.ToDescription();
if (saveDialog.ShowDialog() == DialogResult.OK)
{
string localFilePath = saveDialog.FileName;
Expand All @@ -394,12 +414,11 @@ private void BatchSave()

foreach (var item in _globalSaveVoMap)
{
string outputFileName = NetEaseMusicUtils.GetOutputName(item.Value.SongVo, _globalSearchInfo);
var saveVo = item.Value;
string outputFileName = NetEaseMusicUtils.GetOutputName(saveVo.SongVo, _globalSearchInfo);
string path = filePath + "/" + NetEaseMusicUtils.GetSafeFilename(outputFileName) + fileSuffix;
StreamWriter sw = new StreamWriter(path, false,
NetEaseMusicUtils.GetEncoding(_globalSearchInfo.Encoding));
sw.Write(NetEaseMusicUtils.GetOutputLyric(item.Value.LyricVo.Lyric, item.Value.LyricVo.TLyric,
_globalSearchInfo));
StreamWriter sw = new StreamWriter(path, false, NetEaseMusicUtils.GetEncoding(_globalSearchInfo.Encoding));
sw.Write(NetEaseMusicUtils.GetOutputContent(saveVo.LyricVo, _globalSearchInfo));
sw.Flush();
sw.Close();
}
Expand All @@ -416,8 +435,9 @@ private void BatchSave()
var log = new StringBuilder();
foreach (var songId in _globalSearchInfo.SONG_IDS)
{
log.Append(
$"ID: {songId}, Result: {(_globalSaveVoMap.ContainsKey(songId) ? "success" : "failure")}\r\n");
log
.Append($"ID: {songId}, Result: {(_globalSaveVoMap.ContainsKey(songId) ? "success" : "failure")}")
.Append(Environment.NewLine);
}

UpdateLrcTextBox(log.ToString());
Expand Down Expand Up @@ -583,11 +603,10 @@ private void UpdateLrcTextBox(string replace)
if (_globalSaveVoMap != null && _globalSaveVoMap.Count == 1)
{
// only loop one times
foreach (var item in _globalSaveVoMap)
foreach (var saveVo in _globalSaveVoMap.Values)
{
string outputLyric = NetEaseMusicUtils.GetOutputLyric(item.Value.LyricVo.Lyric,
item.Value.LyricVo.TLyric, _globalSearchInfo);
textBox_lrc.Text = outputLyric == "" ? ErrorMsg.LRC_NOT_EXIST : outputLyric;
var outputContent = NetEaseMusicUtils.GetOutputContent(saveVo.LyricVo, _globalSearchInfo);
textBox_lrc.Text = string.IsNullOrEmpty(outputContent) ? ErrorMsg.LRC_NOT_EXIST : outputContent;
}
}
}
Expand All @@ -611,5 +630,11 @@ private void textBox_lrc_KeyDown(object sender, KeyEventArgs e)
((TextBox)sender).SelectAll();
}
}

private void comboBox_output_format_SelectedIndexChanged(object sender, EventArgs e)
{
output_format_enum = (OUTPUT_FORMAT_ENUM)comboBox_output_format.SelectedIndex;
ReloadConfig();
}
}
}
Loading

0 comments on commit d299bf3

Please sign in to comment.