Skip to content

Commit 2069268

Browse files
committed
Support query lyrics by each search results
1 parent f46ee9b commit 2069268

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

SourcePrivoder/Base/SourceProviderBase.cs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ public override Lyrics ProvideLyric(string artist, string title, int time, bool
3030

3131
var lyrics= PickLyric(artist, title, time, search_result,request_trans_lyrics, out SEARCHRESULT picked_result);
3232

33-
//过滤没有实质歌词内容的玩意,比如没有时间轴的歌词文本
34-
if (lyrics?.LyricSentencs?.Count==0)
35-
return null;
36-
3733
if (lyrics!=null&& Setting.EnableOutputSearchResult)
3834
{
3935
//output lyrics search result
@@ -68,23 +64,36 @@ public virtual Lyrics PickLyric(string artist, string title, int time, List<SEAR
6864

6965
if (search_result.Count == 0)
7066
return null;
67+
68+
Lyrics lyric_cont = null;
69+
SEARCHRESULT cur_result=null;
7170

72-
var result = search_result.First();
73-
74-
Utils.Debug($"* Picked music_id:{result.ID} artist:{result.Artist} title:{result.Title}");
71+
foreach (var result in search_result)
72+
{
73+
var content = Downloader.DownloadLyric(result, request_trans_lyrics);
74+
cur_result = result;
7575

76-
var lyric_cont = Downloader.DownloadLyric(result, request_trans_lyrics);
76+
if (string.IsNullOrWhiteSpace(content))
77+
continue;
7778

78-
if (string.IsNullOrWhiteSpace(lyric_cont))
79-
return null;
79+
lyric_cont = Parser.Parse(content);
8080

81-
picked_result = result;
81+
//过滤没有实质歌词内容的玩意,比如没有时间轴的歌词文本
82+
if (lyric_cont?.LyricSentencs?.Count == 0)
83+
continue;
84+
85+
Utils.Debug($"* Picked music_id:{result.ID} artist:{result.Artist} title:{result.Title}");
86+
break;
87+
}
8288

83-
var lyrics = Parser.Parse(lyric_cont);
89+
if (lyric_cont==null)
90+
return null;
8491

85-
WrapInfo(lyrics);
92+
picked_result = cur_result;
93+
94+
WrapInfo(lyric_cont);
8695

87-
return lyrics;
96+
return lyric_cont;
8897

8998
#region Wrap Methods
9099

@@ -100,9 +109,9 @@ void WrapInfo(Lyrics l)
100109
Title = title
101110
}, query_info = new Info()
102111
{
103-
Artist = result.Artist,
104-
Title=result.Title,
105-
ID=result.ID
112+
Artist = cur_result.Artist,
113+
Title= cur_result.Title,
114+
ID= cur_result.ID
106115
};
107116

108117
l.RawInfo = raw_info;

SourcePrivoder/QQMusic/QQMusicSearch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Song:SearchSongResultBase
2323

2424
public override string Title { get => title; }
2525
public string title { get; set; }
26-
public int id { get; set; }
26+
//public int id { get; set; }
2727
public string mid { get; set; }
2828
public override string ID { get => /*id.ToString();*/mid; }
2929

@@ -38,7 +38,7 @@ public class Song:SearchSongResultBase
3838

3939
public override string ToString()
4040
{
41-
return $"({id}){Artist} - {title} ({interval / 60}:{interval % 60})";
41+
return $"({ID}){Artist} - {title} ({interval / 60}:{interval % 60})";
4242
}
4343
}
4444

0 commit comments

Comments
 (0)