接上文.....
//
处理 :
歌曲名中如果包含歌词
NSMutableString *tmp = [NSMutableString stringWithString:SongsName];
NSRange range = [tmp rangeOfString:@"<br><font color="#999999" class=f10>"];
if (range.location != NSNotFound) {
range.length = SongsName.length - range.location;
//NSLog(@"%d !",range.length);
[tmp deleteCharactersInRange:range];
//NSLog(@"test =%@",tmp);
SongsName = tmp;
}
//[tmp release];
//NSLog(@"t= %@, %@ , %@",SongsName,SongsSinger,SongsAlbum);
//
好,现在开始发春了!
NSString * FinalStr = [[[NSString alloc] initWithFormat:@"<
头 >%@<
分割 >%@<
分割 >%@<
分割 >%@<
分割 >%@<
分割 >%@",
SongsName,SongsSinger,SongsAlbum,SongsURL,SongsSpeed,SongsSize]autorelease];
FinalStr = [FinalStr stringByReplacingOccurrencesOfString:@"<font color="#c60a00">"withString:@""];
FinalStr = [FinalStr stringByReplacingOccurrencesOfString:@"</font>" withString:@""];
FinalStr = [FinalStr stringByReplacingOccurrencesOfString:@"</a>" withString:@""];
FinalStr = [FinalStr stringByReplacingOccurrencesOfString:@"<a href="http://mp3.baidu.com/singerlist/" withString:@""];
FinalStr = [FinalStr stringByReplacingOccurrencesOfString:@" " withString:@""];
FinalStr = [FinalStr stringByReplacingOccurrencesOfString:@"'" withString:@"'"];
FinalStr = [FinalStr stringByReplacingOccurrencesOfString:@"<
头 > "withString:@"<
头 >"];
FinalStr = [FinalStr stringByReplacingOccurrencesOfString:@"<
头 >" withString:@""];
FinalStr = [FinalStr stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
FinalStr = [FinalStr stringByReplacingOccurrencesOfString:@"</td>" withString:@""];
FinalStr = [FinalStr stringByReplacingPercentEscapesUsingEncoding:enc];
//if ([SongsURL hasSuffix:@"3"]) {
[mySongs addObject:FinalStr];
//};
//]
}
@catch (NSException * e) {
//
没有错误处理,
发生错误就直接丢掉
}
@finally {
// none
}
};
[myResponseStr release];
return (NSArray *)mySongs;
}
+(NSString*)decodeBaiduURL:(NSString*)myEncodeURL{
// 我没学过
c ,没学过
c ,没学过
c ,写的太臃肿,太
sb 了,别骂我呀。
NSString * returnURL = [[[NSString alloc] initWithFormat:@""] autorelease];
//char *myCEncodeURL = [myEncodeURL cStringcStringWithEncoding:NSASCIIStringEncoding];
NSLog(@"input %@",myEncodeURL);
//
字串
static NSString * myConst = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
int pyl ; //
偏移量
//NSRange myRange = [myEncodeURL rangeOfString:@":"]; //
定位
协议标识符
UniChar myUniChr = [myEncodeURL characterAtIndex:0]; //
取出第一字符
//
转换类型
NSString * myChrAsStr = [[[NSString alloc] initWithFormat:@"%C",myUniChr] autorelease];
// 确定第一字符在字串中的位置
NSRange myRange2 = [myConst rangeOfString:myChrAsStr];
int myFirstChrLocation = myRange2.location;
//
计算偏移量
pyl = myFirstChrLocation - 33 ;
// 33 means "h" 's location .
NSLog(@"len = %d",myEncodeURL.length);
//
还原字串
//NSLog(@"pyl = %d",pyl);
for (int i=0; i<[myEncodeURL length]; i++) {
UniChar myTmpChr= [myEncodeURL characterAtIndex:i];
NSString * myTmpChrAsStr = [[[NSString alloc] initWithFormat:@"%C",myTmpChr] autorelease];
NSRange myTmpRange = [myConst rangeOfString: myTmpChrAsStr];
if (myTmpRange.location != NSNotFound) {
int newChrAsInt = myTmpRange.location - pyl;
//NSLog(@"pyl = %d , oldchr = %C , oldcount = %d, newcount = %d",pyl,myTmpChr,
//hai myTmpRange.location,newChrAsInt);
if (newChrAsInt<0) {
newChrAsInt = newChrAsInt + 62;
//NSLog(@"%d",newChrAsInt);
} else {
if (newChrAsInt>62) {
newChrAsInt = newChrAsInt % 62;
};
}
/// NSLog(@"! pyl = %d , oldchr = %C , oldcount = %d, newcount = %d",pyl,myTmpChr,
// myTmpRange.location,newChrAsInt);
myTmpChr = [myConst characterAtIndex:newChrAsInt];
};
//NSLog(@"%C",myTmpChr);
returnURL= [returnURL stringByAppendingFormat:@"%C",myTmpChr];
}
returnURL= [returnURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"output %@",returnURL);
return returnURL;
}
+(NSString*)DownPageURLToMusicFileURL:(NSString*)myDownpage{
NSURL * myURL = [NSURL URLWithString:myDownpage];
ASIHTTPRequest * myRequest = [[[ASIHTTPRequest alloc] initWithURL:myURL] autorelease];
[myRequest startSynchronous];
NSData * myResponseData = [myRequest responseData];
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString * myResponseStr = [[NSString alloc] initWithData:myResponseData encoding:enc];
//NSLog(@"resstr= %@", myResponseStr);
NSArray *myArr = [myResponseStr componentsSeparatedByString:@"var encurl = ""];
myArr = [[myArr objectAtIndex:1] componentsSeparatedByString:@"", newurl = "";"];
[myResponseStr release];
return [self decodeBaiduURL:[myArr objectAtIndex:0]];
}
@end