//
// BaiduMusicBoxParser.h
//
// Created by scott.8an@gmail.com on 12-3-11.
// Copyright (c) 2012年. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ASIHTTPRequest.h"
#import "ASINetworkQueue.h"
#import "TFHpple.h"
#import "XPathQuery.h"
#import "TFHppleElement.h"
@interface BaiduMusicBoxParser : NSObject
+ (BaiduMusicBoxParser*)shareInstance;
/**
返回的数组结构:
[
{
album = "\U672a\U6765\U5c5e\U4e8e\U5b69\U5b50 \U4e2d\U5916\U540d\U66f2\U7cbe\U9009";
artist = "\U6768\U9e3f\U5e74";
"download_url" = "http://mp3.baidu.com/j?j=2&url=http%3A%2F%2Fzhangmenshiting.baidu.com%2Fdata2%2Fmusic%2F9405342%2F9405342.mp3%3Fxcode%3Dfdaccf3ade1f2d967110c329ab53b046";
quality = "MP3(3.9M)";
"song_name" = "we are the world";
},...
]
**/
- (NSArray*)baiduSongsInfoBySearchingSongName:(NSString *)name pageNumber:(int)pgNO;
//获取歌词
- (NSString*)lyricsWithSong:(NSString*)sName;
//获取百度歌手列表,从大写字母A~Z,其他为0
/**
[
"A"=[
AOK,
Alizee,...
],
"B"={
BOBO,
白雪,...
},...
]
**/
- (NSArray*)allArtistsListOfBaiduMp3;
- (NSArray*)artistsListOfBaiduMp3ByFilterCharacter:(NSString*)character;
@end
//
// BaiduMusicBoxParser.m
//
// Created by scott.8an@gmail.com on 12-3-11.
// Copyright (c) 2012年. All rights reserved.
//
#import "BaiduMusicBoxParser.h"
#import "GDataXMLNode.h"
static BaiduMusicBoxParser *parser_ = nil;
@interface BaiduMusicBoxParser (Private)
/**
返回的数组结构:
[
"http://box.zhangmen.baidu.com/m?word=mp3,,,[love+of+my+life]&gate=1&ct=134217728&tn=baidumt,love+of+my+life&si=love+of+my+life;;keith%20martin;;0;;0&lm=-1&attr=0,0&rf=zb&size=1992294",
...
]
sName:歌曲名称
pgNo:页数。默认为0.
**/
- (NSArray*)jumpToURLBySongName:(NSString*)sName pageNumber:(int)pgNo;
@end
@implementation BaiduMusicBoxParser
- (void)dealloc{
[super dealloc];
}
+ (BaiduMusicBoxParser*)shareInstance{
if (!parser_) {
parser_ = [[self alloc] init];
}
return parser_;
}
- (id)init{
if ([super init]) {
}
return self;
}
- (NSArray*)jumpToURLBySongName:(NSString*)sName pageNumber:(int)pgNo{
if(sName==nil || [sName length]==0)return nil;
if (pgNo<0) {
return nil;
}
//去除两端的空格
[sName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//把歌曲拼凑成格式如:love+of+my+life 的形式
NSArray *nameArr = [sName componentsSeparatedByString:@" "];
NSMutableString *newName = [NSMutableString stringWithCapacity:0];
if (nameArr && [nameArr count]) {
for (NSString *s in nameArr) {
[newName appendFormat:@"%@+",s];
}
//去掉最后一个 '+'号
if ([newName length]) {
[newName deleteCharactersInRange:NSMakeRange([newName length]-1, 1)];
}
}
//用户输入的是整个字符串,没有空格
if (nameArr && [nameArr count]==1) {
[newName appendString:[nameArr objectAtIndex:0]];
}
//组合地址并编码
NSString *requestURL = [NSString stringWithFormat:@"http://mp3.baidu.com/m?word=%@&lm=-1&f=ms&tn=baidump3&ct=134217728&lf=&rn=&pn=%i",newName,pgNo*30];
NSString *requestURLWithEnc = [requestURL stringByAddingPercentEscapesUsingEncoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000)];
//NSLog(@"===%@",requestURLWithEnc);
//发送请求,获得返回数据
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:requestURLWithEnc]];
[request startSynchronous];
if ([request error]) {
return nil;
}
//接收返回数据
//获取id = "songResults"的节点
TFHpple *helper = [TFHpple hppleWithHTMLData:[request responseData]];
NSString *xPathDescription = @"//*[@id=\"songResults\"]";
TFHppleElement *divElement = [helper peekAtSearchWithXPathQuery:xPathDescription];
NSArray *children = divElement.children;
//return
NSMutableArray *jumpToPageURLArray = [NSMutableArray arrayWithCapacity:0];
//获得table
TFHppleElement *tb = [children objectAtIndex:0];
NSArray *tbodyChildren = tb.children;
if (tbodyChildren && [tbodyChildren count]) {
for (TFHppleElement *trElement in tbodyChildren) {
NSArray *tdArr = trElement.children;
if (tdArr && [tdArr count]) {
for (TFHppleElement *tdNode in tdArr) {
//<td class="second">
if (tdNode && [[tdNode objectForKey:@"class"] isEqualToString:@"down"]) {
NSArray *tdNodeArr = tdNode.children;
if (tdNodeArr && [tdNodeArr count]) {
TFHppleElement *aNode = tdNode.firstChild;
if (aNode) {
//获得要跳转的地址
NSString *jumpToURL = [aNode objectForKey:@"href"];
if ([jumpToURL length]) {
[jumpToPageURLArray addObject:jumpToURL];
}
}
}
}
}
}
}
}
//跳转界面地址数组
//NSLog(@"共有跳转地址:%i个,它们是:%@",[jumpToPageURLArray count],jumpToPageURLArray);
if ([jumpToPageURLArray count]) {
return jumpToPageURLArray;
}
return nil;
}
- (NSArray*)baiduSongsInfoBySearchingSongName:(NSString *)name pageNumber:(int)pgNO{
if(name==nil || [name length]==0)return nil;
if (pgNO<0) return nil;
NSArray *jumpToURLArr = [self jumpToURLBySongName:name pageNumber:pgNO];
//获得跳转地址的数组
NSMutableArray *musicInfoArr = [NSMutableArray arrayWithCapacity:0];
if (jumpToURLArr && [jumpToURLArr count]) {
for (NSString *urlStr in jumpToURLArr) {
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlStr]];
[request startSynchronous];
//获得返回数据
NSData *responseData = [request responseData];
if (responseData) {
TFHpple *helper = [TFHpple hppleWithHTMLData:responseData];
if (helper) {
//获得歌曲的下载地址
NSString *xPath = @"//*[@id='downlink']";
TFHppleElement *downloadLinkNode = [helper peekAtSearchWithXPathQuery:xPath];
NSString *musicDownloadURI = [downloadLinkNode objectForKey:@"href"];
NSString *musicDownloadURL = [NSString stringWithFormat:@"http://mp3.baidu.com%@",musicDownloadURI];
//NSLog(@"======下载地址是:%@",musicDownloadURL);
if (musicDownloadURI && [musicDownloadURI length]) {
//获得歌手名字
/**<div class="songinfo-more">
<span class="singer gray">歌手:
<a href="http://mp3.baidu.com/singerlist/back ii back.html" target="_blank">back ii back</a>
</span>
<span class="album gray">所属专辑:
《<a href="http://mp3.baidu.com/albumlist/back ii back;;;;;;back ii back.html" target="_blank">back ii back</a>
》</span>
</div>
**/
NSString *aritistNameXpath = @"//*[@class='songinfo-more']";
TFHppleElement *aritistNameNode = [helper peekAtSearchWithXPathQuery:aritistNameXpath];
TFHppleElement *spanNode = aritistNameNode.firstChild;
TFHppleElement *aNode = spanNode.firstChild;
NSString *artistName = aNode.content;
//NSLog(@"*************歌手:%@",artistName);
//获得专辑名字
TFHppleElement *albumNode = [aritistNameNode.children objectAtIndex:1];
TFHppleElement *AaNode = albumNode.firstChild;
NSString *albumName = AaNode.content;
//NSLog(@"*************专辑:%@",albumName);
//获得歌曲的品质
/**
<div class="format gray">品质:<b>MP3(4.0M)</b></div>
**/
NSString *qulityXpath = @"//*[@class='format gray']";
TFHppleElement *qulityNode = [helper peekAtSearchWithXPathQuery:qulityXpath];
TFHppleElement *bNode = qulityNode.firstChild;
NSString *qulityDescription = bNode.content;
//NSLog(@"*************品质:%@",qulityDescription);
if (musicDownloadURI && [musicDownloadURI length]) {
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
[dic setObject:musicDownloadURL forKey:@"download_url"];
[dic setObject:name forKey:@"song_name"];
[dic setObject:artistName?artistName:[NSNull null] forKey:@"artist"];
[dic setObject:albumName?albumName:[NSNull null] forKey:@"album"];
[dic setObject:qulityDescription?qulityDescription:[NSNull null] forKey:@"quality"];
if ([dic count]) {
[musicInfoArr addObject:dic];
}
}
}
}
}
}
}
//NSLog(@"歌曲信息数组-------------%@",musicInfoArr);
if ([musicInfoArr count]) {
return musicInfoArr;
}
return nil;
}
- (NSString*)lyricsWithSong:(NSString*)sName {
return nil;
}
- (NSArray*)allArtistsListOfBaiduMp3{
return nil;
}
- (NSArray*)artistsListOfBaiduMp3ByFilterCharacter:(NSString*)character{
return nil;
}
@end
分享到:
相关推荐
百度音乐盒是一款集成了百度音乐服务的应用程序,用户可以通过它来搜索、播放和下载音乐。当你找到了想要的歌曲后,请确保你是在百度音乐盒内试听这首歌曲,以便能够进行下一步操作。试听歌曲时,你会看到一个包含...
百度音乐盒是一款集音乐搜索、播放、下载于一体的软件。在易语言中实现百度音乐盒的搜索功能,主要涉及网络请求、数据解析和用户界面展示等技术。 1. 网络请求:源码中会使用到HTTP协议进行网络交互,向百度音乐的...
- **特色应用**:百度易包括了音乐盒(提供正版音乐)、阅读器、地图、身边客户端等应用,满足用户在娱乐、阅读、导航和生活服务方面的需求。 - **重视本地化应用**:尽管百度强调云端能力,但许迎春指出,本地化...
在互联网上,许多网站提供免费的MP3音乐下载服务,用户可以根据自己的喜好找到合适的音乐。 上传MP3到免费的云存储平台是实现背景音乐链接的第一步。例如,可以使用阿里云盘、百度网盘等服务。这些平台通常允许用户...
它采用了先进的音频解码算法,确保音频信号的原始质量得到最大程度的保留。同时,它支持多种音频增强技术,如DSD转换、ASIO驱动支持等,为用户提供了一流的听觉享受。 在界面设计上,Foobar2000遵循极简主义,但...
"常见的应用程序图标ICO高清版.rar"这个压缩包文件,显然包含了多个知名应用的高清图标,例如QQ、Firefox浏览器、暴风影音、千千静听、迅雷下载工具以及酷我音乐盒等。这些图标设计精美,分辨率高,适合作为开发者或...
简介: 本次设计首先对单片机设计简易电子琴仔细...本次设计有一个创新,就是预先存放一段音乐程序在芯片内,整个设计既可以作电子琴用又可以作音乐盒用,且带显示功能。 PCB截图: 仿真图截图: 原理图截图: 元件清单:
手册中还详细介绍了国内各大门户视频网站、体育节目直播窗口、云存储服务以及环境音乐电台功能等的访问方法。 此外,文档还提到了“国内DNS破解使用手册”,这可能指的是绕过某些限制(如地区限制)来访问更多内容...
本次讲座由美国斯坦福大学MBA、百度公司前首席架构师、酷我公司的创始人雷鸣主讲,他将结合自己的实战经验和成功案例——酷我音乐盒,分享如何在Linux平台上构建高性能的系统。 #### 二、设计的艺术 1. **简洁与...
- **语音引擎**:选择成熟的语音识别引擎,如Google Speech API或百度语音API。 - **对话流程**:设计简单的对话流程,引导儿童与语音助手互动。 - **反馈机制**:根据用户的语音指令,提供相应的反馈,如播放...