Skip to content

Commit 5836831

Browse files
committed
Support QQMusic Translation
1 parent 744d95a commit 5836831

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

Sources/LyricsService/Parser/QQMusicQrcDecrypter.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,12 @@ enum XMLUtils {
10331033
}
10341034

10351035
func decryptQQMusicQrc(_ data: String) -> String? {
1036-
try? QrcDecoder.decode(data)
1036+
do {
1037+
return try QrcDecoder.decode(data)
1038+
} catch {
1039+
print(error)
1040+
return nil
1041+
}
10371042
}
10381043

10391044
extension Array {

Sources/LyricsService/Provider/QQMusic.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ extension LyricsProviders.QQMusic: _LyricsProvider {
125125
lrc.metadata.artworkURL = URL(string: "http://imgcache.qq.com/music/photo/album/\(id % 100)/\(id).jpg")
126126
}
127127

128+
if let transEncryptedString = try? xmlDocument.nodes(forXPath: "//contentts").first?.stringValue,
129+
let transDecryptedString = decryptQQMusicQrc(transEncryptedString),
130+
let transLrc = Lyrics(transDecryptedString)
131+
{
132+
lrc.merge(translation: transLrc)
133+
}
134+
128135
// remove their kana tag. we don't need it.
129136
// lrc.idTags.removeValue(forKey: .qqMusicKana)
130137

Sources/LyricsService/Provider/Service.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension LyricsProviders.Service {
3131
#if canImport(Darwin)
3232
case .syair: return LyricsProviders.Syair()
3333
#endif
34-
default: return LyricsProviders.Unsupported()
34+
// default: return LyricsProviders.Unsupported()
3535
}
3636
}
3737
}

Tests/LyricsKitTests/LyricsKitTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import XCTest
22
@testable import LyricsService
33

4-
let testSong = "好久不见"
5-
let testArtist = "周杰伦"
4+
let testSong = "Good Time"
5+
let testArtist = "Owl City"
66
let duration = 305.0
77
let searchReq = LyricsSearchRequest(searchTerm: .info(title: testSong, artist: testArtist), duration: duration)
88

0 commit comments

Comments
 (0)