Skip to content

Commit

Permalink
Merge pull request #164 from jitwxs/dev
Browse files Browse the repository at this point in the history
Release v5.9
  • Loading branch information
jitwxs committed Feb 26, 2023
2 parents 2dcef3c + 59d6b17 commit 0f161cf
Show file tree
Hide file tree
Showing 19 changed files with 387 additions and 217 deletions.
16 changes: 8 additions & 8 deletions MusicLyricApp/Api/Music/MusicCacheableApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ public SearchSourceEnum Source()

public ResultVo<PlaylistVo> GetPlaylistVo(string playlistId)
{
return GlobalCache.Process(CacheType.PLAYLIST_VO, playlistId, () => GetPlaylistVo0(playlistId));
return GlobalCache.Process(Source(), CacheType.PLAYLIST_VO, playlistId, () => GetPlaylistVo0(playlistId));
}

public ResultVo<AlbumVo> GetAlbumVo(string albumId)
{
return GlobalCache.Process(CacheType.ALBUM_VO, albumId, () => GetAlbumVo0(albumId));
return GlobalCache.Process(Source(), CacheType.ALBUM_VO, albumId, () => GetAlbumVo0(albumId));
}

public Dictionary<string, ResultVo<SongVo>> GetSongVo(string[] songIds)
{
var result = GlobalCache.BatchQuery<string, SongVo>(CacheType.SONG_VO, songIds, out var notHitKeys)
.ToDictionary(pair => pair.Key, pair => new ResultVo<SongVo>(pair.Value));
var result = GlobalCache.BatchQuery<SongVo>(Source(), CacheType.SONG_VO, songIds,
out var notHitKeys).ToDictionary(pair => pair.Key, pair => new ResultVo<SongVo>(pair.Value));

foreach(var pair in GetSongVo0(notHitKeys))
{
Expand All @@ -49,7 +49,7 @@ public ResultVo<AlbumVo> GetAlbumVo(string albumId)

if (resultVo.IsSuccess())
{
GlobalCache.DoCache(CacheType.SONG_VO, songId, resultVo.Data);
GlobalCache.DoCache(Source(), CacheType.SONG_VO, songId, resultVo.Data);
}

result[songId] = pair.Value;
Expand All @@ -60,14 +60,14 @@ public ResultVo<AlbumVo> GetAlbumVo(string albumId)

public ResultVo<string> GetSongLink(string songId)
{
return GlobalCache.Process(CacheType.SONG_LINK, songId, () => GetSongLink0(songId));
return GlobalCache.Process(Source(), CacheType.SONG_LINK, songId, () => GetSongLink0(songId));
}

public ResultVo<LyricVo> GetLyricVo(string id, string displayId, bool isVerbatim)
{
ResultVo<LyricVo> CacheFunc() => GetLyricVo0(id, displayId, isVerbatim);

return GlobalCache.Process(CacheType.LYRIC_VO, GlobalUtils.GetSongKey(displayId, isVerbatim), CacheFunc);
return GlobalCache.Process(Source(), CacheType.LYRIC_VO, GlobalUtils.GetSongKey(displayId, isVerbatim), CacheFunc);
}

public ResultVo<SearchResultVo> Search(string keyword, SearchTypeEnum searchType)
Expand All @@ -76,7 +76,7 @@ public ResultVo<SearchResultVo> Search(string keyword, SearchTypeEnum searchType

ResultVo<SearchResultVo> CacheFunc() => Search0(keyword, searchType);

return GlobalCache.Process(CacheType.SEARCH_RESULT_VO, cacheKey, CacheFunc);
return GlobalCache.Process(Source(), CacheType.SEARCH_RESULT_VO, cacheKey, CacheFunc);
}
}
}
8 changes: 4 additions & 4 deletions MusicLyricApp/Api/Music/NetEaseMusicApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override ResultVo<PlaylistVo> GetPlaylistVo0(string playlistId)
if (resp.Code == 200)
{
// cache song
GlobalCache.DoCache(CacheType.NET_EASE_SONG, value => value.Id, resp.Playlist.Tracks);
GlobalCache.DoCache(Source(), CacheType.NET_EASE_SONG, value => value.Id, resp.Playlist.Tracks);

return new ResultVo<PlaylistVo>(resp.Convert());
}
Expand All @@ -51,7 +51,7 @@ protected override ResultVo<AlbumVo> GetAlbumVo0(string albumId)
if (resp.Code == 200)
{
// cache song
GlobalCache.DoCache(CacheType.NET_EASE_SONG, value => value.Id, resp.Songs);
GlobalCache.DoCache(Source(), CacheType.NET_EASE_SONG, value => value.Id, resp.Songs);
return new ResultVo<AlbumVo>(resp.Convert());
}
else
Expand All @@ -64,14 +64,14 @@ protected override ResultVo<AlbumVo> GetAlbumVo0(string albumId)
{
// 从缓存中查询 Song,并将非命中的数据查询后加入缓存
var cacheSongDict = GlobalCache
.BatchQuery<string, Song>(CacheType.NET_EASE_SONG, songIds, out var notHitKeys)
.BatchQuery<Song>(Source(), CacheType.NET_EASE_SONG, songIds, out var notHitKeys)
.ToDictionary(pair => pair.Key, pair => pair.Value);

foreach (var pair in _api.GetSongs(notHitKeys))
{
cacheSongDict.Add(pair.Key, pair.Value);
// add cache
GlobalCache.DoCache(CacheType.NET_EASE_SONG, pair.Key, pair.Value);
GlobalCache.DoCache(Source(), CacheType.NET_EASE_SONG, pair.Key, pair.Value);
}

var result = new Dictionary<string, ResultVo<SongVo>>();
Expand Down
6 changes: 3 additions & 3 deletions MusicLyricApp/Api/Music/QQMusicApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ protected override ResultVo<PlaylistVo> GetPlaylistVo0(string playlistId)
if (resp.Code == 0)
{
// cache song
GlobalCache.DoCache(CacheType.QQ_MUSIC_SONG, value => value.Id, resp.Cdlist[0].SongList);
GlobalCache.DoCache(CacheType.QQ_MUSIC_SONG, value => value.Mid, resp.Cdlist[0].SongList);
GlobalCache.DoCache(Source(), CacheType.QQ_MUSIC_SONG, value => value.Id, resp.Cdlist[0].SongList);
GlobalCache.DoCache(Source(), CacheType.QQ_MUSIC_SONG, value => value.Mid, resp.Cdlist[0].SongList);

return new ResultVo<PlaylistVo>(resp.Convert());
}
Expand Down Expand Up @@ -62,7 +62,7 @@ ResultVo<QQMusicBean.Song> SongCacheFunc()
return resp.IsIllegal() ? ResultVo<QQMusicBean.Song>.Failure(ErrorMsg.SONG_NOT_EXIST) : new ResultVo<QQMusicBean.Song>(resp.Data[0]);
}

var songRes = GlobalCache.Process(CacheType.QQ_MUSIC_SONG, songId, SongCacheFunc);
var songRes = GlobalCache.Process(Source(), CacheType.QQ_MUSIC_SONG, songId, SongCacheFunc);
if (songRes.IsSuccess())
{
result[songId] = new ResultVo<SongVo>(new SongVo
Expand Down
6 changes: 4 additions & 2 deletions MusicLyricApp/Api/Translate/TranslateCacheableApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace MusicLyricApp.Api.Translate
{
public abstract class TranslateCacheableApi : ITranslateApi
{
private const string PREFIX = "";

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

protected abstract bool IsSupport0(LanguageEnum inputLanguage, LanguageEnum outputLanguage);
Expand All @@ -17,7 +19,7 @@ public string[] Translate(string[] inputs, LanguageEnum inputLanguage, LanguageE
return new string[] {};
}

var cacheDict = GlobalCache.BatchQuery<string, string>(CacheType.TRANSLATE, inputs, out var notHitInputs);
var cacheDict = GlobalCache.BatchQuery<string>(PREFIX, CacheType.TRANSLATE, inputs, out var notHitInputs);

var httpRes = new string[] { };
if (notHitInputs.Length > 0)
Expand All @@ -36,7 +38,7 @@ public string[] Translate(string[] inputs, LanguageEnum inputLanguage, LanguageE

if (output != null)
{
GlobalCache.DoCache(CacheType.TRANSLATE, input, output);
GlobalCache.DoCache(PREFIX, CacheType.TRANSLATE, input, output);
}
}
res[index++] = output;
Expand Down
6 changes: 3 additions & 3 deletions MusicLyricApp/Bean/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace MusicLyricApp.Bean
{
public static class Constants
{
public const string Version = "v5.8";
public const string Version = "v5.9";

public static readonly string SettingPath = Environment.CurrentDirectory + "\\MusicLyricAppSetting.json";

Expand Down Expand Up @@ -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} -> 歌曲名");
Expand All @@ -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:
Expand Down
19 changes: 17 additions & 2 deletions MusicLyricApp/Bean/MusicLyricsVO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ public LyricTimestamp(long millisecond)
TimeOffset = millisecond;
}

public LyricTimestamp Add(long millisecond)
{
return new LyricTimestamp(TimeOffset + millisecond);
}

/// <summary>
/// 初始化 LyricTimestamp
/// </summary>
Expand Down Expand Up @@ -751,14 +756,24 @@ public class SearchInfo

public class InputSongId
{
public string QueryId { get; }

public string SongId { get; }

public SearchSourceEnum SearchSource { get; }

public SearchTypeEnum SearchType { get; }

public InputSongId(string songId, SearchSourceEnum searchSource)
public InputSongId(string queryId, SearchSourceEnum searchSource, SearchTypeEnum searchType)
{
SongId = songId;
QueryId = queryId;
SearchSource = searchSource;
SearchType = searchType;
}

public InputSongId (string songId, InputSongId other) : this(other.QueryId, other.SearchSource, other.SearchType)
{
SongId = songId;
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions MusicLyricApp/Bean/SettingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class ConfigBean
/// </summary>
public bool RememberParam = false;

/// <summary>
/// 聚合模糊搜索
/// </summary>
public bool AggregatedBlurSearch = false;

/// <summary>
/// 自读读取剪切板
/// </summary>
Expand All @@ -34,6 +39,11 @@ public class ConfigBean
/// </summary>
public bool IgnorePureMusicInSave = true;

/// <summary>
/// 对于 "独立" 歌词格式,保存在不同的文件中
/// </summary>
public bool SeparateFileForIsolated = false;

/// <summary>
/// 输出文件名格式
/// </summary>
Expand Down
94 changes: 48 additions & 46 deletions MusicLyricApp/BlurForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Data;
using System.Windows.Forms;
using MusicLyricApp.Bean;
using MusicLyricApp.Utils;

namespace MusicLyricApp
{
Expand All @@ -12,22 +13,21 @@ public partial class BlurForm : MusicLyricForm

private string[] _ids;

public BlurForm(SearchResultVo searchResultVo, MainForm mainForm)
public BlurForm(List<SearchResultVo> searchResList, MainForm mainForm)
{
_mainForm = mainForm;

InitializeComponent();

InitialDataGridView(searchResultVo);
InitialDataGridView(searchResList);
}

private void InitialDataGridView(SearchResultVo searchResultVo)
private void InitialDataGridView(List<SearchResultVo> searchResList)
{
var table = new DataTable();

var source = searchResultVo.SearchSource.ToDescription();

switch (searchResultVo.SearchType)
var searchType = searchResList[0].SearchType;
switch (searchType)
{
case SearchTypeEnum.SONG_ID:
// Add columns.
Expand All @@ -36,20 +36,6 @@ private void InitialDataGridView(SearchResultVo searchResultVo)
table.Columns.Add("专辑", typeof(string));
table.Columns.Add("时长", typeof(string));
table.Columns.Add("平台", typeof(string));

// Add rows.
var songVos = searchResultVo.SongVos;
_ids = new string[songVos.Count];

for (var i = 0; i < songVos.Count; i++)
{
var songVo = songVos[i];
var duration = new LyricTimestamp(songVo.Duration).PrintTimestamp("mm:ss", DotTypeEnum.DOWN);

_ids[i] = songVo.DisplayId;
table.Rows.Add(songVo.Title, string.Join(",", songVo.AuthorName), songVo.AlbumName,
duration, source);
}
break;
case SearchTypeEnum.ALBUM_ID:
// Add columns.
Expand All @@ -58,19 +44,6 @@ private void InitialDataGridView(SearchResultVo searchResultVo)
table.Columns.Add("歌曲数量", typeof(string));
table.Columns.Add("发行时间", typeof(string));
table.Columns.Add("平台", typeof(string));

// Add rows.
var albumVos = searchResultVo.AlbumVos;
_ids = new string[albumVos.Count];

for (var i = 0; i < albumVos.Count; i++)
{
var albumVo = albumVos[i];

_ids[i] = albumVo.DisplayId;
table.Rows.Add(albumVo.AlbumName, string.Join(",", albumVo.AuthorName), albumVo.SongCount,
albumVo.PublishTime, source);
}
break;
case SearchTypeEnum.PLAYLIST_ID:
// Add columns.
Expand All @@ -80,23 +53,52 @@ private void InitialDataGridView(SearchResultVo searchResultVo)
table.Columns.Add("歌曲数量", typeof(string));
table.Columns.Add("播放量", typeof(string));
table.Columns.Add("平台", typeof(string));

// Add rows.
var playlistVos = searchResultVo.PlaylistVos;
_ids = new string[playlistVos.Count];

for (var i = 0; i < playlistVos.Count; i++)
{
var playlistVo = playlistVos[i];

_ids[i] = playlistVo.DisplayId;
table.Rows.Add(playlistVo.PlaylistName, playlistVo.AuthorName, playlistVo.Description,
playlistVo.SongCount, playlistVo.PlayCount, source);
}
break;
}

var idList = new List<string>();

foreach (var searchResultVo in searchResList)
{
var searchSource = searchResultVo.SearchSource;
var idPrefix = GlobalUtils.SearchSourceKeywordDict[searchSource] + "/" + GlobalUtils.SearchTypeKeywordDict[searchSource][searchType];

switch (searchType)
{
case SearchTypeEnum.SONG_ID:
// Add rows.
foreach (var songVo in searchResultVo.SongVos)
{
var duration = new LyricTimestamp(songVo.Duration).PrintTimestamp("mm:ss", DotTypeEnum.DOWN);

idList.Add(idPrefix + songVo.DisplayId);
table.Rows.Add(songVo.Title, string.Join(",", songVo.AuthorName), songVo.AlbumName,
duration, searchSource.ToDescription());
}
break;
case SearchTypeEnum.ALBUM_ID:
// Add rows.
foreach (var albumVo in searchResultVo.AlbumVos)
{
idList.Add(idPrefix + albumVo.DisplayId);
table.Rows.Add(albumVo.AlbumName, string.Join(",", albumVo.AuthorName), albumVo.SongCount,
albumVo.PublishTime, searchSource.ToDescription());
}
break;
case SearchTypeEnum.PLAYLIST_ID:
// Add rows.
foreach (var playlistVo in searchResultVo.PlaylistVos)
{
idList.Add(idPrefix + playlistVo.DisplayId);
table.Rows.Add(playlistVo.PlaylistName, playlistVo.AuthorName, playlistVo.Description,
playlistVo.SongCount, playlistVo.PlayCount, searchSource.ToDescription());
}
break;
}
}

Blur_DataGridView.DataSource = table;
_ids = idList.ToArray();
}

private void BlurSearch_DataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
Expand Down

0 comments on commit 0f161cf

Please sign in to comment.