美文网首页
2019-05-09 mac上网易云音乐.uc!文件变成.mp3

2019-05-09 mac上网易云音乐.uc!文件变成.mp3

作者: zxh123456 | 来源:发表于2019-05-09 14:20 被阅读0次

mac上网易云音乐.uc!文件变成.mp3(在线听歌的缓存直接生成.mp3)

 //mac云音乐保存路径
    // @"/Users/{你的用户名}/Library/Containers/com.netease.163music/Data/Library/Caches/online_play_cache"
    //源文件夹
    NSString *inPutFileRoot = @"/Users/mac/Desktop/未命名文件夹 6";
    //输出文件夹
    NSString *outPutFileRoot = @"/Users/mac/Desktop/未命名文件夹 7/";
   
    //读取需要解密的所有文件路径
    NSFileManager *manger = [NSFileManager defaultManager];
    NSArray *arr = [manger subpathsAtPath:inPutFileRoot];
    //循环解密
    for (NSString *path in arr) {
        //如果不是uc!结尾,不解密
        if (![path hasSuffix:@"uc!"]) {
            continue;
        }
        //截取musicID
        NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"-_-_"];
        NSString *mID = [path substringToIndex:[path rangeOfCharacterFromSet:set].location];
        //请求网络,获取音乐名字
        NSURLSession *session = [NSURLSession sharedSession];
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.imjad.cn/cloudmusic/?type=detail&id=%@",mID]];
        NSURLSessionDataTask *downsession = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            //获取音乐名字
            NSDictionary *res = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
            NSArray *songs = res[@"songs"];
            NSDictionary *firstOb = songs[0];
            NSDictionary *al = firstOb[@"al"];
            NSString *name = al[@"name"];
            //读取数据data
            NSData *tempData = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",inPutFileRoot,path]];
            //解密数据
            Byte *testByte = (Byte *)[tempData bytes];
            for(int i=0;i<[tempData length];i++){
                testByte[i] = testByte[i] ^ 0xa3;
            }
            //生成新数据
            NSData *newData = [NSData dataWithBytes:testByte length:tempData.length];
            //拼接目标文件名字
            NSString *outPutFileName = [NSString stringWithFormat:@"%@%@.mp3",outPutFileRoot,name];
            //写文件
            [newData writeToFile:outPutFileName  atomically:YES];
        }];
        
        [downsession resume];
    }

相关文章

网友评论

      本文标题:2019-05-09 mac上网易云音乐.uc!文件变成.mp3

      本文链接:https://www.haomeiwen.com/subject/qpewoqtx.html