播放器解析源代码(2)

接上文.....

 

//处理歌曲名中如果包含歌词

         NSMutableString *tmp=[NSMutableString stringWithString:SongsName];

         NSRange range=[tmp rangeOfString:@"<br><fontcolor="#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;

 

 

          }

          //[tmprelease];

 

          //NSLog(@"t=%@, %@ , %@",SongsName,SongsSinger,SongsAlbum);

 

         //好,现在开始发春了!

         NSString *FinalStr =[[[NSString alloc] initWithFormat:@"<>%@<分割>%@<分割>%@<分割>%@<分割>%@<分割>%@",

                             SongsName,SongsSinger,SongsAlbum,SongsURL,SongsSpeed,SongsSize]autorelease];

          FinalStr =[FinalStr stringByReplacingOccurrencesOfString:@"<fontcolor="#c60a00">"withString:@""];

          FinalStr =[FinalStr stringByReplacingOccurrencesOfString:@"</font>" withString:@""];

          FinalStr =[FinalStr stringByReplacingOccurrencesOfString:@"</a>" withString:@""];

          FinalStr =[FinalStr stringByReplacingOccurrencesOfString:@"<ahref="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=  [myEncodeURLcStringcStringWithEncoding: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:@"varencurl = ""];

 

   myArr =[[myArr objectAtIndex:1] componentsSeparatedByString:@"",newurl = "";"];

 

   [myResponseStr release];

 

   return [self decodeBaiduURL:[myArr objectAtIndex:0]];

 

}

@end



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值