资讯详情

krc歌词文件解析

做卡拉ok在项目中,逐字歌词同步需要大量的高精度lrc目前国内有两个文件:专利kugou没有专利qq音乐。两者各推出了逐字同步歌词文件: krc和qrc。krc有加密处理,直接打开只能看到乱码。

找了很多资料,发现只有java半成品解密代码没有版本ios平台可用的。经过我半天努力,终于移植到ios平台。请注明转载个人劳动成果的来源。非常感谢。本文提供ios平台的krc解密解密解决方案。

//

// KRC.h

// iOSKRCDecoder

//

// Created by zeng songgen on 12-8-2.

// Copyright (c) 2012年 zeng songgen. All rights reserved.

//

#import

@interface KRC : NSObject

{

//FileStream fs;

/头部4字节

NSMutableData * HeadBytes;

//不同或加密内容

NSMutableData * EncodedBytes;

///解异或加密后ZIP数据

NSMutableData * ZipBytes;

//UNZIP后数据

NSData * UnzipBytes;

}

- (NSString *) Decode: (NSString * )filePath;

@end

//

// KRC.m

// iOSKRCDecoder

//

// Created by zeng songgen on 12-8-2.

// Copyright (c) 2012年 zeng songgen. All rights reserved.

//

#import "KRC.h"

#import "GTMNSData zlib.h"

@implementation KRC

//不同或加密 密钥

- (NSString *) Decode: (NSString * )filePath

{

NSString * EncKey = @"@Gaw^2tGQ61-?òni";

//char EncKey[] = { '@', 'G', 'a', 'w', '^', '2', 't', 'G', 'Q', '6', '1', '-', '?', 'ò', 'n', 'i' };

NSData * totalBytes = [[NSMutableData alloc] initWithContentsOfFile:filePath];

//HeadBytes = [[NSMutableData alloc] initWithData:[totalBytes subdataWithRange:NSMakeRange(0, 4)]];

EncodedBytes = [[NSMutableData alloc] initWithData:[totalBytes subdataWithRange:NSMakeRange(4, totalBytes.length - 4)]];

ZipBytes = [[NSMutableData alloc] initWithCapacity:EncodedBytes.length];

Byte * encodedBytes = EncodedBytes.mutableBytes;

int EncodedBytesLength = EncodedBytes.length;

for (int i = 0; i < EncodedBytesLength; i )

{

int l = i % 16;

char c = [EncKey characterAtIndex:l];

Byte b = (Byte)((encodedBytes[i]) ^ c);

[ZipBytes appendBytes:&b length:1];

}

UnzipBytes = [NSData gtm_dataByInflatingData:ZipBytes];

NSString * s = [[[NSString alloc] initWithData:UnzipBytes encoding:NSUTF8StringEncoding] autorelease];

return s;

}

@end

标签: 三极管krc101m

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

 锐单商城 - 一站式电子元器件采购平台  

 深圳锐单电子有限公司