|
<div id="cnblogs_post_body">改代码依赖于酷狗云音乐的api接口"http://cloud.kugou.com/app/getSearchResult.php?key={key}&pageNo={pageno}&pageSize={pagesize}"
贴上代码:
<div class="cnblogs_code" > 显示代码<div id="cnblogs_code_open_04d97f27-8ad8-4396-a3ab-f1822b0e5fc7" class="cnblogs_code_hide"> 1 using System; 2 using System.Text.RegularExpressions; 3 using System.Text; 4 using System.Collections; 5 using System.Net; 6 using System.IO; 7 using System.Net.Json; 8 9 public class Kugou10 {11 private static void Usage()12 {13 StringBuilder sb=new StringBuilder();14 sb.Append("Kugou /key:keyvalue [/pageno:pageno] [/pagesize:pagesize] /out:outfile\n");15 sb.Append("-key 关键字\n");16 sb.Append("-pageno 页号\n");17 sb.Append("-pagesize 页面大小\n");18 Console.WriteLine(sb.ToString());19 }20 private static Hashtable keys=new Hashtable();21 public static void Main(string[]args)22 {23 try24 {25 if(args.Length==0)26 {27 Usage();28 }29 else30 {31 foreach(string arg in args)32 {33 Regex re=new Regex(@"^/(.+):(.+)$",RegexOptions.IgnoreCase);34 Match match=re.Match(arg);35 GroupCollection gps=match.Groups;36 string key="";37 string value="";38 for(int i=1;i<gps.Count;i++)39 {40 if(i==1)41 {42 key=gps.Captures[0].Value;43 }44 else45 {46 value=gps.Captures[0].Value;47 }48 }49 keys.Add(key,value);50 }51 if(keys["key"]== null)52 {53 Console.WriteLine("没有输入key值!");54 return ;55 }56 if(keys["pageno"]==null)57 keys.Add("pageno","1");58 if(keys["pagesize"]==null)59 keys.Add("pagesize","1000");60 string url="http://cloud.kugou.com/app/getSearchResult.php?key="+keys["key"].ToString()+"&pageNo="+keys["pageno"].ToString()+"&pageSize="+keys["pagesize"].ToString();61 WebClient client=new WebClient();62 client.Encoding=Encoding.UTF8;63 string result=client.DownloadString(url);64 JSONObject obj=new JSONObject(result);65 JSONArray data=obj.getJSONArray("data");66 string table="<table border=\"1px\" cellspacing=\"0\">";67 table+="<tr><th>文件名</th><th>哈希值</th><th>拥有者</th><th>大小</th><th>比特率</th><th>拓展名</th><th>时长</th><th>位图id</th><th>行id</th></tr>";68 for(int i=0;i<data.length();i++)69 {70 JSONObject item=data.getJSONObject(i);71 table+="<tr>";72 table+="<th>"+item.getString("FileName")+"</th>";73 string u="http://cloud.kugou.com/singlePlayer/4/362/1/3/"+item.getString("Hash")+".swf";74 table+="<th><a href=\""+u+"\">"+u+"</a></th>";75 table+="<th>"+item.getString("Owner")+"</th>";76 table+="<th>"+item.getString("Size")+"</th>";77 table+="<th>"+item.getString("BitRate")+"</th>";78 table+="<th>"+item.getString("ExtName")+"</th>";79 table+="<th>"+item.getString("TimeLength")+"</th>";80 table+="<th>"+item.getString("Bitmap")+"</th>";81 table+="<th>"+item.getString("RowID")+"</th>";82 table+="</tr>";83 }84 table+="</table>";85 if(keys["out"]==null)86 {87 keys.Add("out","output.html");88 }89 File.WriteAllText(keys["out"].ToString(),table,Encoding.Default);90 Console.WriteLine("转换成功!");91 System.Diagnostics.Process.Start(@"C:\Program Files\Internet Explorer\iexplore.exe",Environment.CurrentDirectory+"\\"+keys["out"].ToString());92 }93 }catch(Exception e)94 {95 File.WriteAllText("log",e.StackTrace);96 }97 }98 } |
|