Home > php教程 > php手册 > 将酷狗krc歌词解析并转换为lrc歌词php源码

将酷狗krc歌词解析并转换为lrc歌词php源码

WBOY
Release: 2016-06-06 20:21:20
Original
1181 people have browsed it

这篇文章主要介绍了krc歌词解析并转换为lrc歌词的php实现方法,需要的朋友可以参考下

最近在进行一次对酷狗音乐歌词采集时发现酷狗音乐的歌词直接浏览都是“乱码”,自己平时所见的歌词都是lrc格式的文本,,这种酷狗专用的krc格式的显然是经过特别处理过的,平时用酷狗听音乐也没仔细看他的歌词有什么不同,只是与天天静听等不同的是可以逐字高亮显示歌词。

对酷狗的flash播放器进行反编译,发现这段krc解密的ActionScript代码:

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

根据这段代码可以很快转换成php解析代码:

$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

上面的$krc_content为krc歌词压缩加密的文本内容,得到了解析后的krc明文文本歌词$krc_text,然后就可以很容易的转换成lrc歌词了,如下:

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

简单示例如下:

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template