/** * Parse and convert krc lyrics to lrc lyrics * $ Name: krc2lrc 2014-4-18 qaulau <qaulau@hotmail.com> $ * * @ Param string $ krc_content-encrypted krc lyrics * @ Param string $ the lrc lyric connection character after glue processing. The default value is line break n. */ Function krc2lrc ($ krc_content, $ glue = "n "){ $ EnKey = array (64, 71, 97,119, 94, 50,116, 71, 81, 54, 49, 45,206,210,110,105 ); $ Krc_content = substr ($ krc_content, 4 ); $ Len = strlen ($ krc_content ); $ Krc_compress = ''; For ($ k = 0; $ k <$ len; $ k ++ ){ $ Krc_compress. = chr (ord ($ krc_content [$ k]) ^ $ enKey [$ k % 16]); } $ Krc_text = gzuncompress ($ krc_compress ); Preg_match_all ("/[(ar | ti | offset) :(. +)]/", $ krc_text, $ matches ); $ Lrc_text = implode ($ glue, $ matches [0]). $ glue; Preg_match_all ("/[(d {0, 8}), (d {0, 8})] (. +)/", $ krc_text, $ matches ); Unset ($ krc_text, $ krc_compress, $ krc_content, $ enKey ); If (! Empty ($ matches [1]) { Foreach ($ matches [1] as $ k => $ v ){ List ($ seconds, $ millis) = explode ('.', $ v/1000 ); $ Lrc_time = date ('I: S', 1388534400 + $ seconds).'. '. substr ($ millis ); $ Lrc_cont = preg_replace ("/<d {}, d {}, d {}>/", '', $ matches [3] [$ k]); $ Lrc_text. = "[{$ lrc_time}] {$ lrc_cont} {$ glue }"; } } Return $ lrc_text; } |