@@ -11,16 +11,15 @@ import Foundation
1111import LyricsCore
1212
1313extension Lyrics {
14-
1514 convenience init ? ( kugouKrcContent content: String ) {
1615 var idTags : [ IDTagKey : String ] = [ : ]
1716 var languageHeader : KugouKrcHeaderFieldLanguage ?
18- id3TagRegex. matches ( in: content) . forEach { match in
17+ for match in id3TagRegex. matches ( in: content) {
1918 guard let key = match [ 1 ] ? . content. trimmingCharacters ( in: . whitespaces) ,
20- let value = match [ 2 ] ? . content. trimmingCharacters ( in: . whitespaces) ,
21- !key. isEmpty,
22- !value. isEmpty else {
23- return
19+ let value = match [ 2 ] ? . content. trimmingCharacters ( in: . whitespaces) ,
20+ !key. isEmpty,
21+ !value. isEmpty else {
22+ continue
2423 }
2524 if key == " language " {
2625 if let data = Data ( base64Encoded: value) {
@@ -31,17 +30,17 @@ extension Lyrics {
3130 idTags [ . init( key) ] = value
3231 }
3332 }
34-
33+
3534 var lines : [ LyricsLine ] = krcLineRegex. matches ( in: content) . map { match in
3635 let timeTagStr = match [ 1 ] !. content
3736 let timeTag = TimeInterval ( timeTagStr) ! / 1000
38-
37+
3938 let durationStr = match [ 2 ] !. content
4039 let duration = TimeInterval ( durationStr) ! / 1000
41-
40+
4241 var lineContent = " "
4342 var attachment = LyricsLine . Attachments. InlineTimeTag ( tags: [ . init( index: 0 , time: 0 ) ] , duration: duration)
44- kugouInlineTagRegex. matches ( in: content, range: match [ 3 ] !. range) . forEach { m in
43+ for m in kugouInlineTagRegex. matches ( in: content, range: match [ 3 ] !. range) {
4544 let t1 = Int ( m [ 1 ] !. content) !
4645 let t2 = Int ( m [ 2 ] !. content) !
4746 let t = TimeInterval ( t1 + t2) / 1000
@@ -52,15 +51,15 @@ extension Lyrics {
5251 attachment. tags. append ( . init( index: lineContent. count, time: t) )
5352 }
5453 }
55-
54+
5655 let att = LyricsLine . Attachments ( attachments: [ . timetag: attachment] )
5756 return LyricsLine ( content: lineContent, position: timeTag, attachments: att)
5857 }
5958 guard !lines. isEmpty else {
6059 return nil
6160 }
6261 self . init ( lines: lines, idTags: idTags)
63-
62+
6463 // TODO: multiple translation
6564 if let transContent = languageHeader? . content. first? . lyricContent {
6665 transContent. prefix ( lines. count) . enumerated ( ) . forEach { index, item in
@@ -72,49 +71,3 @@ extension Lyrics {
7271 }
7372 }
7473}
75-
76-
77- extension Lyrics {
78-
79- convenience init ? ( qqmusicQrcContent content: String ) {
80- var idTags : [ IDTagKey : String ] = [ : ]
81- id3TagRegex. matches ( in: content) . forEach { match in
82- guard let key = match [ 1 ] ? . content. trimmingCharacters ( in: . whitespaces) ,
83- let value = match [ 2 ] ? . content. trimmingCharacters ( in: . whitespaces) ,
84- !key. isEmpty,
85- !value. isEmpty else {
86- return
87- }
88- idTags [ . init( key) ] = value
89- }
90-
91- let lines : [ LyricsLine ] = qrcLineRegex. matches ( in: content) . map { match in
92- let timeTagStr = match [ 1 ] !. content
93- let timeTag = TimeInterval ( timeTagStr) ! / 1000
94-
95- let durationStr = match [ 2 ] !. content
96- let duration = TimeInterval ( durationStr) ! / 1000
97-
98- var lineContent = " "
99- var attachment = LyricsLine . Attachments. InlineTimeTag ( tags: [ . init( index: 0 , time: 0 ) ] , duration: duration)
100- qqmusicInlineTagRegex. matches ( in: content, range: match [ 3 ] !. range) . forEach { m in
101- let t1 = Int ( m [ 2 ] !. content) ! - Int( timeTagStr) !
102- let t2 = Int ( m [ 3 ] !. content) !
103- let t = TimeInterval ( t1 + t2) / 1000
104- let fragment = m [ 1 ] !. content
105- let prevCount = lineContent. count
106- lineContent += fragment
107- if lineContent. count > prevCount {
108- attachment. tags. append ( . init( index: lineContent. count, time: t) )
109- }
110- }
111-
112- let att = LyricsLine . Attachments ( attachments: [ . timetag: attachment] )
113- return LyricsLine ( content: lineContent, position: timeTag, attachments: att)
114- }
115- guard !lines. isEmpty else {
116- return nil
117- }
118- self . init ( lines: lines, idTags: idTags)
119- }
120- }
0 commit comments