Skip to content

Commit

Permalink
Merge pull request #150 from jitwxs/dev
Browse files Browse the repository at this point in the history
Release v5.7 Addition
  • Loading branch information
jitwxs authored Jan 2, 2023
2 parents 9a60a39 + 157d907 commit c726378
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 223 deletions.
9 changes: 8 additions & 1 deletion MusicLyricApp/Api/Translate/BaiduTranslateApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class BaiduTranslateApi : TranslateCacheableApi

/// <summary>
/// 初始化 API
/// https://fanyi-api.baidu.com/manage/developer
/// </summary>
/// <param name="appId">APP ID</param>
/// <param name="secret">密钥</param>
Expand Down Expand Up @@ -118,7 +119,13 @@ protected override ResultVo<string[]> Translate0(string[] inputs, LanguageEnum i
return new ResultVo<string[]>(outputs);
}

private string CastLanguageEnum(LanguageEnum languageEnum)
protected override bool IsSupport0(LanguageEnum inputLanguage, LanguageEnum outputLanguage)
{
// all support
return true;
}

private static string CastLanguageEnum(LanguageEnum languageEnum)
{
switch (languageEnum)
{
Expand Down
55 changes: 39 additions & 16 deletions MusicLyricApp/Api/Translate/CaiYunTranslateApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ public CaiYunTranslateApi(string token)

protected override ResultVo<string[]> Translate0(string[] inputs, LanguageEnum inputLanguage, LanguageEnum outputLanguage)
{
string transType;

switch (outputLanguage)
{
case LanguageEnum.CHINESE:
transType = "auto2zh";
break;
case LanguageEnum.ENGLISH:
transType = "auto2en";
break;
default:
// not support
return ResultVo<string[]>.Failure(ErrorMsg.TRANSLATE_LANGUAGE_NOT_SUPPORT);
}

var res = new string[inputs.Length];

var headers = new Dictionary<string, string>
Expand All @@ -63,7 +48,7 @@ protected override ResultVo<string[]> Translate0(string[] inputs, LanguageEnum i
var param = new Dictionary<string, object>
{
{ "source", input },
{ "trans_type", transType },
{ "trans_type", Cast(inputLanguage) + "2" + Cast(outputLanguage) },
{ "request_id", "demo" },
{ "detect", true },
};
Expand All @@ -85,5 +70,43 @@ protected override ResultVo<string[]> Translate0(string[] inputs, LanguageEnum i

return new ResultVo<string[]>(res);
}

protected override bool IsSupport0(LanguageEnum inputLanguage, LanguageEnum outputLanguage)
{
if (inputLanguage == LanguageEnum.CHINESE)
{
// 中文仅支持转英文和日文
return outputLanguage == LanguageEnum.ENGLISH || outputLanguage == LanguageEnum.JAPANESE;
}

if (inputLanguage == LanguageEnum.ENGLISH)
{
// 英文仅支持转中文
return outputLanguage == LanguageEnum.CHINESE;
}

if (inputLanguage == LanguageEnum.JAPANESE)
{
// 日文仅支持转中文
return outputLanguage == LanguageEnum.CHINESE;
}

return false;
}

private static string Cast(LanguageEnum language)
{
switch (language)
{
case LanguageEnum.CHINESE:
return "zh";
case LanguageEnum.ENGLISH:
return "en";
case LanguageEnum.JAPANESE:
return "ja";
default:
return "";
}
}
}
}
2 changes: 2 additions & 0 deletions MusicLyricApp/Api/Translate/ITranslateApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ namespace MusicLyricApp.Api.Translate
public interface ITranslateApi
{
string[] Translate(string[] inputs, LanguageEnum inputLanguage, LanguageEnum outputLanguage);

bool IsSupport(LanguageEnum inputLanguage, LanguageEnum outputLanguage);
}
}
9 changes: 8 additions & 1 deletion MusicLyricApp/Api/Translate/TranslateCacheableApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace MusicLyricApp.Api.Translate
public abstract class TranslateCacheableApi : ITranslateApi
{
protected abstract ResultVo<string[]> Translate0(string[] inputs, LanguageEnum inputLanguage, LanguageEnum outputLanguage);

protected abstract bool IsSupport0(LanguageEnum inputLanguage, LanguageEnum outputLanguage);

public string[] Translate(string[] inputs, LanguageEnum inputLanguage, LanguageEnum outputLanguage)
{
Expand Down Expand Up @@ -42,7 +44,12 @@ public string[] Translate(string[] inputs, LanguageEnum inputLanguage, LanguageE

return res;
}


public bool IsSupport(LanguageEnum inputLanguage, LanguageEnum outputLanguage)
{
return IsSupport0(inputLanguage, outputLanguage);
}

protected static string[][] ChunkArray(string[] inputs, int chunkSize)
{
var i = 0;
Expand Down
4 changes: 4 additions & 0 deletions MusicLyricApp/Bean/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public static string GetContent(TypeEnum typeEnum)
list.Add("${name} -> 歌曲名");
list.Add("${singer} -> 歌手名");
list.Add("${album} -> 专辑名");
list.Add("-----");
list.Add("您可自行决定输出哪些歌词类型,通过勾选复选框进行启用和关闭");
list.Add("拖拽最左侧的箭头可以调整输出的顺序");
list.Add("罗马音功能需要安装罗马音插件,非原始译文类型需要指定翻译 API");
break;
case TypeEnum.DEFAULT:
default:
Expand Down
27 changes: 9 additions & 18 deletions MusicLyricApp/Bean/MusicLyricsVO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,9 @@ namespace MusicLyricApp.Bean
// 双语歌词类型
public enum ShowLrcTypeEnum
{
[Description("仅显示原文")] ONLY_ORIGIN = 0,

[Description("仅显示译文(交错)")] ONLY_TRANS_STAGGER = 1,
[Description("仅显示译文(独立)")] ONLY_TRANS_ISOLATED = 2,
[Description("仅显示译文(合并)")] ONLY_TRANS_MERGE = 3,

[Description("优先原文(交错)")] ORIGIN_PRIOR_STAGGER = 4,
[Description("优先原文(独立)")] ORIGIN_PRIOR_ISOLATED = 5,
[Description("优先原文(合并)")] ORIGIN_PRIOR_MERGE = 6,

[Description("优先译文(交错)")] TRANSLATE_PRIOR_STAGGER = 7,
[Description("优先译文(独立)")] TRANSLATE_PRIOR_ISOLATED = 8,
[Description("优先译文(合并)")] TRANSLATE_PRIOR_MERGE = 9,
[Description("交错")] STAGGER = 0,
[Description("独立")] ISOLATED = 1,
[Description("合并")] MERGE = 2,
}

// 搜索来源
Expand Down Expand Up @@ -91,12 +81,13 @@ public enum TransLyricLostRuleEnum
[Description("填充原文")] FILL_ORIGIN = 2,
}

public enum TransTypeEnum
public enum LyricsTypeEnum
{
[Description("原始译文")] ORIGIN_TRANS = 0,
[Description("中文")] CHINESE = 1,
[Description("英文")] ENGLISH = 2,
[Description("罗马音")] ROMAJI = 3,
[Description("原文")] ORIGIN = 0,
[Description("原始译文")] ORIGIN_TRANS = 1,
[Description("中文译文")] CHINESE = 2,
[Description("英文译文")] ENGLISH = 3,
[Description("罗马音译文")] ROMAJI = 4,
}

public enum LanguageEnum
Expand Down
24 changes: 17 additions & 7 deletions MusicLyricApp/Bean/SettingBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

using System;
using System.Collections.Generic;
using System.Linq;

namespace MusicLyricApp.Bean
{
public class SettingBean
Expand Down Expand Up @@ -34,6 +38,11 @@ public class ConfigBean
/// 输出文件名格式
/// </summary>
public string OutputFileNameFormat = "${name} - ${singer}";

/// <summary>
/// 输出的歌词类型列表
/// </summary>
public string OutputLyricTypes = string.Join(",", new [] { (int) LyricsTypeEnum.ORIGIN, (int) LyricsTypeEnum.ORIGIN_TRANS });

/// <summary>
/// QQ 音乐 Cookie
Expand All @@ -46,6 +55,12 @@ public class ConfigBean
public string NetEaseCookie = "";

public TransConfigBean TransConfig = new TransConfigBean();

public List<LyricsTypeEnum> DeserializationOutputLyricsTypes()
{
return string.IsNullOrWhiteSpace(OutputLyricTypes) ? new List<LyricsTypeEnum>() :
OutputLyricTypes.Split(',').Select(e => (LyricsTypeEnum) Convert.ToInt32(e)).ToList();
}
}

public class TransConfigBean
Expand All @@ -59,12 +74,7 @@ public class TransConfigBean
/// 译文歌词匹配精度
/// </summary>
public int MatchPrecisionDeviation = 0;

/// <summary>
/// 译文类型
/// </summary>
public string TransType = "0";


/// <summary>
/// 罗马音转换模式
/// </summary>
Expand Down Expand Up @@ -106,7 +116,7 @@ public class PersistParamBean
/// <summary>
/// 歌词展示格式
/// </summary>
public ShowLrcTypeEnum ShowLrcType = ShowLrcTypeEnum.ONLY_ORIGIN;
public ShowLrcTypeEnum ShowLrcType = ShowLrcTypeEnum.STAGGER;

/// <summary>
/// 指定歌词合并的分隔符
Expand Down
23 changes: 18 additions & 5 deletions MusicLyricApp/MainForm.Designer.cs

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

4 changes: 1 addition & 3 deletions MusicLyricApp/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,7 @@ private void LrcType_ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
switch (_globalSearchInfo.SettingBean.Param.ShowLrcType = (ShowLrcTypeEnum)LrcType_ComboBox.SelectedIndex)
{
case ShowLrcTypeEnum.ONLY_TRANS_MERGE:
case ShowLrcTypeEnum.ORIGIN_PRIOR_MERGE:
case ShowLrcTypeEnum.TRANSLATE_PRIOR_MERGE:
case ShowLrcTypeEnum.MERGE:
LrcMergeSeparator_TextBox.ReadOnly = false;
LrcMergeSeparator_TextBox.BackColor = Color.White;
break;
Expand Down
Loading

0 comments on commit c726378

Please sign in to comment.