Krc lyrics of cool dog parsed and converted to lrc lyrics php version

Source: Internet
Author: User
Recently, when collecting the lyrics of Codoy music, we found that the lyrics of Codoy music are directly browsed by quot; garbled quot;. the lyrics we usually see are in lrc format, this krc format for cool dogs is obviously specially handled. we usually use cool dogs... recently, when collecting the lyrics of Codoy music, we found that the lyrics of Codoy music are all "garbled" and the lyrics we usually see are all in lrc format, this kind of krc format for Codoy is obviously specially handled. it is usually different to listen to music with Codoy, the only difference is that the lyrics can be highlighted by words.

So I searched and issued an existing semi-finished product decryption code for java, and tested whether it was "garbled! Therefore, only the most primitive method is used to decompile the Flash player of Codoon and find the following code of the codes decrypted by krc:

public function loaderCompleteHandler(param1:ByteArray) : void{  this.newkeyBytes = [64, 71, 97, 119, 94, 50, 116, 71, 81, 54, 49, 45, 206, 210, 110, 105];  var result:* = param1;  var krcBytes:* = new ByteArray();  result.position = 4;  result.readBytes(krcBytes);  var l:* = krcBytes.length;  var i:int;  while (i < l) {  krcBytes[i] = krcBytes[i] ^ this.newkeyBytes[i % this.newkeyBytes.length];   i = (i + 1);  } try {   krcBytes.uncompress();  } catch (error:SecurityError) {   errorfun("uncompressError");  return;  }  krcBytes.position = 0;  this.myLyric.dataStr = krcBytes.readUTFBytes(krcBytes.length);  this.successfun();  return;  }

Based on this code, you can quickly convert it into a php parsing code:

$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 );

The above $ krc_content is the krc lyrics compressed and encrypted text content. the parsed krc plaintext text lyrics $ krc_text can be easily converted into lrc lyrics. the code is as follows:

/*** Parse and convert krc lyrics to lrc lyrics * $ Name: krc2lrc 2014-4-18 qaulau
 
  
$ ** @ Param string $ kc_content-encrypted krc lyrics * @ param string $ lrc lyrics connected by glue. the default value is the linefeed 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 (! Emptyempty ($ matches [1]) {foreach ($ matches [1] as $ k => $ v) {list ($ seconds, $ millis) = explode ('. ', $ v/1000); $ lrc_time = date (' I: S', 1388534400 + $ seconds ). '. '. substr ($ millis, 0, 2); $ lrc_cont = preg_replace ("/
  
   
/",'', $ Matches [3] [$ k]); $ lrc_text. = "[{$ lrc_time}] {$ lrc_cont} {$ glue}" ;}} return $ lrc_text ;}
  
 

Simple example:

$content = file_get_contents('1.krc'); echo krc2lrc($content,'
');

Share with you to facilitate future query by persons with similar needs.


Address:

Reprinted at will, but please attach the article address :-)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.