Parse and convert krc lyrics of cool dog into lrc lyrics php source code

Source: Internet
Author: User
This article mainly introduces the php implementation method for krc lyrics parsing and converting to lrc lyrics, if you need it, you can refer to a recent collection of Codoy music lyrics and find that the lyrics of Codoy music are "garbled" directly, and the lyrics you usually see are 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.

Decompile the Flash player of Codoy and find the following codes of the event code 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, as shown below:

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,0,2); $lrc_cont = preg_replace("/
 
  /",'',$matches[3][$k]); $lrc_text .= "[{$lrc_time}]{$lrc_cont}{$glue}"; } } return $lrc_text;}
 

A simple example is as follows:

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

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.