Exemple #1
0
 /// <summary>
 /// 歌词迷歌词来源
 /// </summary>
 /// <param name="SongName">必选,歌名</param>
 /// <param name="Singer">可选,歌手名,默认为空</param>
 /// <returns>歌词结果列表</returns>
 public static List <LrcResult> GeCiMiLrc(string SongName, string Singer = "")
 {
     try
     {
         List <LrcResult> rs = new List <LrcResult>();
         HttpWebRequest   Req;
         HttpWebResponse  Rep;
         if (Singer != "")
         {
             Req = (HttpWebRequest)WebRequest.Create(@"http://geci.me/api/lyric/" + HttpUtility.UrlEncode(SongName, Encoding.UTF8) + "/" + HttpUtility.UrlEncode(Singer, Encoding.UTF8));
         }
         else
         {
             Req = (HttpWebRequest)WebRequest.Create(@"http://geci.me/api/lyric/" + HttpUtility.UrlEncode(SongName, Encoding.UTF8));
         }
         Req.Timeout = 300000;
         Rep         = (HttpWebResponse)Req.GetResponse();
         StreamReader Reader = new StreamReader(Rep.GetResponseStream());
         string       str    = Reader.ReadToEnd();
         JObject      p      = JObject.Parse(str);
         foreach (var songinfo in p["result"])
         {
             string url      = songinfo["lrc"].ToString();
             string songname = UnicodeToGB(songinfo["song"].ToString());
             rs.Add(new LrcResult {
                 SongName = songname, Singer = Singer, Album = "", url = url, Relook = ""
             });
         }
         return(rs);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Exemple #2
0
 /// <summary>
 /// 百度音乐歌词搜索
 /// </summary>
 /// <param name="Query">必选,关键词</param>
 /// <param name="pn">可选,页码,默认为1</param>
 /// <returns>歌词结果列表</returns>
 public static List <LrcResult> BaiduLrc(string Query, int pn = 1)
 {
     try
     {
         List <LrcResult> rs = new List <LrcResult>();
         HttpWebRequest   Req;
         HttpWebResponse  Rep;
         Req = (HttpWebRequest)WebRequest.Create(@"http://music.baidu.com/search/lrc?key=" + HttpUtility.UrlEncode(Query, Encoding.UTF8) + @"&start=" + (20 * (pn - 1)).ToString());
         Rep = (HttpWebResponse)Req.GetResponse();
         StreamReader Reader = new StreamReader(Rep.GetResponseStream());
         string       str    = Reader.ReadToEnd();
         string[]     tmp    = Regex.Split(str, "<div class=\"song-content\">");
         for (int i = 1; i < tmp.Length; i++)
         {
             string songname = Regex.Split(Regex.Split(Regex.Split(Regex.Split(tmp[i], "<span class=\"song-title\">歌曲:")[1], "</span>")[0], "</a>")[0], "\">")[1].Replace("<em>", "").Replace("</em>", "").Replace("\t", "").Replace("\n", "");
             string singer   = Regex.Split(Regex.Split(tmp[i], "<span class=\"artist-title\">歌手:")[1], ">")[2].Replace("<em>", "").Replace("</em>", "").Replace("</a", "");
             string album    = Regex.Split(Regex.Split(tmp[i], "<span class=\"album-title\">")[1].Replace("<em>", "").Replace("</em>", ""), ">")[1].Replace("</a", "");
             string url      = @"http://music.baidu.com" + Regex.Split(Regex.Split(tmp[i], "<a class=\"down-lrc-btn { 'href':'")[1], "' }\" href=\"#\">下载LRC歌词</a>")[0];
             string relook   = Regex.Split(Regex.Split(Regex.Split(tmp[i], "<p id=\"lyricCont-")[1], "</p>")[0].Replace("<em>", "").Replace("</em>", "").Replace("<br />", "\r\n"), ">")[1];
             rs.Add(new LrcResult {
                 SongName = songname, Singer = singer, Album = album, url = url, Relook = relook
             });
         }
         return(rs);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Exemple #3
0
            /// <summary>
            /// 搜索函数
            /// </summary>
            /// <param name="Query">必选,关键字</param>
            /// <param name="PageNumber">可选,页码,默认为1</param>
            /// <param name="PageSize">可选,每页数据条数,默认为20</param>
            /// <returns>结果</returns>
            public static ResultData Search(string Query, int PageNumber = 1, int PageSize = 10)
            {
                HttpWebRequest  Req;
                HttpWebResponse Rep;

                try
                {
                    Req = (HttpWebRequest)WebRequest.Create(@"http://search.5sing.kugou.com/home/json?keyword=" + HttpUtility.UrlEncode(Query, Encoding.UTF8) + "&sort=1&page=" + PageNumber + "&filter=0&type=0");
                    Rep = (HttpWebResponse)Req.GetResponse();
                    StreamReader Reader = new StreamReader(Rep.GetResponseStream());
                    string       str    = Reader.ReadToEnd();
                    str = str.Replace("<em class=\\\\\\\"keyword\\\\\\\">", "").Replace("<\\/em>", "");
                    JObject    p      = JObject.Parse(str);
                    ResultData Result = new ResultData {
                        List1 = new List <SongListItem>()
                    };
                    Result.Tot = int.Parse(p["pageInfo"]["totalCount"].ToString());
                    foreach (var songinfo in p["list"])
                    {
                        SongListItem SLI = new SongListItem {
                            Album1 = "", Singer1 = songinfo["singer"].ToString(), SongId1 = songinfo["songId"].ToString(), SongName1 = songinfo["songName"].ToString(), Lrc1 = "", Quality1 = new QualityList(), Pic1 = new SongPic(), SongInterval1 = ""
                        };
                        SLI.Quality1.Qother = true;
                        SLI.Quality1.Sother = songinfo["songSize"].ToString();
                        SLI.Quality1.Fother = songinfo["typeEname"].ToString() + "-" + songinfo["songId"].ToString();
                        Result.List1.Add(SLI);
                    }
                    return(Result);
                }
                catch (Exception ex)
                {
                    return(new ResultData());
                }
            }
Exemple #4
0
 /// <summary>
 /// QQ音乐歌词搜索
 /// </summary>
 /// <param name="Query">必选,关键词</param>
 /// <param name="pn">可选,页码,默认为1</param>
 /// <param name="ps">可选,页码,默认为20</param>
 /// <returns></returns>
 public static List <LrcResult> QQMusicLrc(string Query, int pn = 1, int ps = 20)
 {
     try
     {
         List <LrcResult> rs = new List <LrcResult>();
         HttpWebRequest   Req;
         HttpWebResponse  Rep;
         Req = (HttpWebRequest)WebRequest.Create(@"http://c.y.qq.com/soso/fcgi-bin/search_cp?remoteplace=txt.yqq.center&format=json&t=7&p=" + pn + "&n=" + ps + "&w=" + HttpUtility.UrlEncode(Query, Encoding.UTF8));
         Rep = (HttpWebResponse)Req.GetResponse();
         StreamReader Reader = new StreamReader(Rep.GetResponseStream());
         string       str    = Reader.ReadToEnd();
         JObject      p      = JObject.Parse(str);
         foreach (var songinfo in p["data"]["lyric"]["list"])
         {
             string _singer = "";
             foreach (var singer in songinfo["singer"])
             {
                 _singer = _singer + "," + singer["name"].ToString();
             }
             _singer = _singer.Substring(0, _singer.Length - 1);
             string url      = "http://music.qq.com/miniportal/static/lyric/" + songinfo["songid"].ToString().Substring(songinfo["songid"].ToString().Length - 2, 2).Replace("0", "") + "/" + songinfo["songid"].ToString() + ".xml";
             string relook   = songinfo["content"].ToString().Replace("&lt;strong class=&quot;keyword&quot;&gt;", "").Replace("&lt;/strong&gt;", "").Replace("&lt;br/&gt;", "\r\n").Replace("&#39;", "'").Replace("&apos;", "'");
             string songname = songinfo["songname"].ToString();
             string album    = songinfo["albumname"].ToString();
             rs.Add(new LrcResult {
                 SongName = songname, Singer = _singer, Album = album, url = url, Relook = relook
             });
         }
         return(rs);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Exemple #5
0
            /// <summary>
            /// 获取歌曲文件(播放专用)
            /// </summary>
            /// <param name="SongId">歌曲ID</param>
            /// <param name="Quanlity">音质</param>
            /// <returns>歌曲地址</returns>
            public static string GetSong(string SongId, string Quanlity)
            {
                HttpWebRequest  Req;
                HttpWebResponse Rep;

                try
                {
                    byte[] param = Encoding.UTF8.GetBytes("param=" + Convert.ToBase64String(Encoding.UTF8.GetBytes("{\"key\":\"" + SongId + "\",\"rate\":\"128,192,256,320,flac\",\"linkType\":0,\"isCloud\":0,\"version\":\"10.1.8.3\"}")));
                    Req             = (HttpWebRequest)WebRequest.Create(@"http://musicmini2014.baidu.com/2016/app/link/getLinks.php");
                    Req.Method      = "POST";
                    Req.ContentType = "application/x-www-form-urlencoded";
                    Req.UserAgent   = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.2; WOW64; Trident/7.0)";
                    Stream reqstream = Req.GetRequestStream();
                    reqstream.Write(param, 0, param.Length);
                    reqstream.Close();
                    Rep = (HttpWebResponse)Req.GetResponse();
                    StreamReader Reader       = new StreamReader(Rep.GetResponseStream());
                    string       str          = Reader.ReadToEnd();
                    JObject      p            = JObject.Parse(str);
                    string[]     Songfilelist = Regex.Split(p["file_list"].ToString().Replace("[", "").Replace("]", "").Replace("\r\n", "").Replace(" ", ""), "},{");
#pragma warning disable CS0162 // 检测到无法访问的代码
                    for (int i = 0; i < Songfilelist.Length; i++)
#pragma warning restore CS0162 // 检测到无法访问的代码
                    {
                        if (i != 0 && i != Songfilelist.Length - 1)
                        {
                            Songfilelist[i] = "{" + Songfilelist[i] + "}";
                        }
                        else
                        {
                            if (i == 0 && i != Songfilelist.Length - 1)
                            {
                                Songfilelist[i] = Songfilelist[i] + "}";
                            }
                            else
                            {
                                if (i == Songfilelist.Length - 1 && i != 0)
                                {
                                    Songfilelist[i] = "{" + Songfilelist[i];
                                }
                            }
                        }
                        JObject songdinfo = JObject.Parse(Songfilelist[i]);
                        if (songdinfo["format"].ToString() == "flac")
                        {
                            return(@"http://zhangmenshiting.baidu.com/data2/music/" + songdinfo["file_id"] + @"/" + songdinfo["file_id"] + @".flac");
                        }
                        else
                        {
                            return(@"http://zhangmenshiting.baidu.com/data2/music/" + songdinfo["file_id"] + @"/" + songdinfo["file_id"] + @".mp3");
                        }
                    }
                    return("");
                }
                catch (Exception ex)
                {
                    return("");
                }
            }
Exemple #6
0
            /// <summary>
            /// 搜索函数
            /// </summary>
            /// <param name="Query">必选,关键字</param>
            /// <param name="PageNumber">可选,页码,默认为1</param>
            /// <param name="PageSize">可选,每页数据条数,默认为20</param>
            /// <returns>结果</returns>
            public static ResultData Search(string Query, int PageNumber = 1, int PageSize = 20)
            {
                HttpWebRequest  Req;
                HttpWebResponse Rep;

                try
                {
                    Req = (HttpWebRequest)WebRequest.Create(@"http://songsearch.kugou.com/song_search_v2?clientver=8018&keyword=" + HttpUtility.UrlEncode(Query, Encoding.UTF8) + @"&pagesize=" + PageSize + @"&page=" + PageNumber);
                    Rep = (HttpWebResponse)Req.GetResponse();
                    StreamReader Reader = new StreamReader(Rep.GetResponseStream());
                    string       str    = Reader.ReadToEnd();
                    JObject      p      = JObject.Parse(str);
                    ResultData   Result = new ResultData {
                        List1 = new List <SongListItem>()
                    };
                    Result.Tot = int.Parse(p["data"]["total"].ToString());
                    foreach (var songinfo in p["data"]["lists"])
                    {
                        SongListItem SLI = new SongListItem {
                            Album1 = songinfo["AlbumName"].ToString(), Singer1 = songinfo["SingerName"].ToString(), SongId1 = songinfo["ID"].ToString(), SongName1 = songinfo["SongName"].ToString(), Lrc1 = "", Quality1 = new QualityList(), Pic1 = new SongPic(), SongInterval1 = songinfo["Duration"].ToString()
                        };
                        SLI.Lrc1 = "http://lyrics.kugou.com/search?ver=1&man=yes&client=pc&keyword=" + HttpUtility.UrlEncode(songinfo["SingerName"].ToString() + "-" + songinfo["SongName"].ToString(), Encoding.UTF8) + "&duration=" + songinfo["Duration"].ToString() + "000&hash=" + songinfo["FileHash"].ToString();
                        if (songinfo["FileHash"].ToString() != "00000000000000000000000000000000")
                        {
                            SLI.Quality1.Q128 = true;
                            SLI.Quality1.S128 = songinfo["FileSize"].ToString();
                            SLI.Quality1.F128 = songinfo["FileHash"].ToString();
                        }
                        if (songinfo["HQFileHash"].ToString() != "00000000000000000000000000000000")
                        {
                            SLI.Quality1.Q320 = true;
                            SLI.Quality1.S320 = songinfo["HQFileSize"].ToString();
                            SLI.Quality1.F320 = songinfo["HQFileHash"].ToString();
                        }
                        if (songinfo["SQFileHash"].ToString() != "00000000000000000000000000000000")
                        {
                            SLI.Quality1.Ape  = true;
                            SLI.Quality1.Sape = songinfo["SQFileSize"].ToString();
                            SLI.Quality1.Fape = songinfo["SQFileHash"].ToString();
                        }
                        Result.List1.Add(SLI);
                    }
                    return(Result);
                }
                catch (Exception ex)
                {
                    return(new ResultData());
                }
            }
Exemple #7
0
            /// <summary>
            /// 获取文件参数
            /// </summary>
            /// <returns>vkey等,直接接在链接后即可</returns>
            public static string GetVkey()
            {
                HttpWebRequest  Req;
                HttpWebResponse Rep;

                try
                {
                    Req = (HttpWebRequest)WebRequest.Create(@"https://c.y.qq.com/base/fcgi-bin/fcg_musicexpress.fcg?json=3&guid=4450729731&g_tk=938407465&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=GB2312&notice=0&platform=yqq&needNewCode=0");
                    Rep = (HttpWebResponse)Req.GetResponse();
                    StreamReader Reader = new StreamReader(Rep.GetResponseStream());
                    string       str    = Reader.ReadToEnd();
                    JObject      p      = JObject.Parse(str);
                    return("?vkey=" + p["key"] + "&guid=4450729731&fromtag=30");
                }
                catch (Exception ex)
                {
                    return("");
                }
            }
Exemple #8
0
            /// <summary>
            /// 获取xcode值
            /// </summary>
            /// <param name="SongId">必选,歌曲ID</param>
            /// <returns>xcode值</returns>
            public static string GetXcode(string SongId)
            {
                HttpWebRequest  Req;
                HttpWebResponse Rep;

                try
                {
                    Req = (HttpWebRequest)WebRequest.Create(@"http://music.baidu.com/data/music/links?songIds=" + SongId);
                    Rep = (HttpWebResponse)Req.GetResponse();
                    StreamReader Reader = new StreamReader(Rep.GetResponseStream());
                    string       str    = Reader.ReadToEnd();
                    JObject      p      = JObject.Parse(str);
                    return(Regex.Split(Regex.Split(p["data"].First.ToString(), ":")[1], "\"")[1]);
                }
                catch (Exception ex)
                {
                    return("");
                }
            }
Exemple #9
0
            ///<summary>
            /// 获取地址
            /// </summary>
            /// <param name="LinkStr">连接字符串,储存在fother</param>
            /// <returns>歌曲地址</returns>
            public static string GetSong(string LinkStr)
            {
                HttpWebRequest  Req;
                HttpWebResponse Rep;

                try
                {
                    Req = (HttpWebRequest)WebRequest.Create(@"http://5sing.kugou.com/m/detail/" + LinkStr + "-1.html");
                    Rep = (HttpWebResponse)Req.GetResponse();
                    StreamReader Reader = new StreamReader(Rep.GetResponseStream());
                    string       str    = Reader.ReadToEnd();
                    str = Regex.Split(str, "<audio src=\"")[1];
                    str = Regex.Split(str, "\" id=\"player\" volume=\"0.5\"></audio>")[0];
                    return(str);
                }
                catch (Exception ex)
                {
                    return("");
                }
            }
Exemple #10
0
            /// <summary>
            /// 获取歌曲下载信息
            /// </summary>
            /// <param name="Hash">必选,歌曲Hash</param>
            /// <returns>歌曲地址</returns>
            public static string GetSongUrl(string Hash)
            {
                HttpWebRequest  Req;
                HttpWebResponse Rep;

                try
                {
                    Req = (HttpWebRequest)WebRequest.Create(@"http://trackercdn.kugou.com/i/?cmd=4&hash=" + Hash + @"&key=" + GetMd5HashStr(Hash + "kgcloud") + "&pid=1");
                    Rep = (HttpWebResponse)Req.GetResponse();
                    StreamReader Reader = new StreamReader(Rep.GetResponseStream());
                    string       str    = Reader.ReadToEnd();
                    System.Diagnostics.Debug.WriteLine(str);
                    JObject p = JObject.Parse(str);
                    return(p["url"].ToString());
                }
                catch (Exception ex)
                {
                    return("");
                }
            }
Exemple #11
0
            /// <summary>
            /// 搜索函数
            /// </summary>
            /// <param name="Query">必选,关键字</param>
            /// <param name="PageNumber">可选,页码,默认为1</param>
            /// <param name="PageSize">可选,每页数据条数,默认为20</param>
            /// <returns>结果</returns>
            public static ResultData Search(string Query, int PageNumber = 1, int PageSize = 20)
            {
                HttpWebRequest  Req;
                HttpWebResponse Rep;

                try
                {
                    Req = (HttpWebRequest)WebRequest.Create(@"http://c.y.qq.com/soso/fcgi-bin/search_cp?remoteplace=txt.yqq.center&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=" + PageNumber + "&n=" + PageSize + "&w=" + HttpUtility.UrlEncode(Query, Encoding.UTF8) + @"&format=json&inCharset=utf8&outCharset=utf-8&platform=yqq");
                    Rep = (HttpWebResponse)Req.GetResponse();
                    StreamReader Reader = new StreamReader(Rep.GetResponseStream());
                    string       str    = Reader.ReadToEnd();
                    JObject      p      = JObject.Parse(str);
                    ResultData   Result = new ResultData {
                        List1 = new List <SongListItem>()
                    };
                    Result.Tot = int.Parse(p["data"]["song"]["totalnum"].ToString());
                    foreach (var songinfo in p["data"]["song"]["list"])
                    {
                        SongListItem SLI = new SongListItem {
                            Album1 = songinfo["albumname"].ToString(), Singer1 = "", SongId1 = songinfo["songmid"].ToString(), SongName1 = songinfo["songname"].ToString(), Lrc1 = "", Quality1 = new QualityList(), Pic1 = new SongPic(), SongInterval1 = songinfo["interval"].ToString()
                        };
                        SLI.Pic1.Large1  = "https://y.gtimg.cn/music/photo_new/T002R800x800M000" + songinfo["albummid"].ToString() + ".jpg?max_age=2592000";
                        SLI.Pic1.Middle1 = "https://y.gtimg.cn/music/photo_new/T002R500x500M000" + songinfo["albummid"].ToString() + ".jpg?max_age=2592000";
                        SLI.Pic1.Small1  = "https://y.gtimg.cn/music/photo_new/T002R200x200M000" + songinfo["albummid"].ToString() + ".jpg?max_age=2592000";
                        SLI.Lrc1         = "https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?format=json&platform=yqq&g_tk=938407465&songmid=" + songinfo["songmid"].ToString();
                        if (int.Parse(songinfo["type"].ToString()) == 0)
                        {
                            if (int.Parse(songinfo["size128"].ToString()) != 0)
                            {
                                SLI.Quality1.Q128 = true;
                                SLI.Quality1.S128 = songinfo["size128"].ToString();
                                SLI.Quality1.F128 = "http://dl.stream.qqmusic.qq.com/M500" + songinfo["songmid"].ToString() + ".mp3";
                            }
                            if (int.Parse(songinfo["size320"].ToString()) != 0)
                            {
                                SLI.Quality1.Q320 = true;
                                SLI.Quality1.S320 = songinfo["size320"].ToString();
                                SLI.Quality1.F320 = "http://dl.stream.qqmusic.qq.com/M800" + songinfo["songmid"].ToString() + ".mp3";
                            }

                            //接口不支持获取无损歌曲
                            //if (int.Parse(songinfo["sizeape"].ToString()) != 0)
                            //{
                            //    SLI.Quality1.Ape = true;
                            //    SLI.Quality1.Sape = songinfo["sizeape"].ToString();
                            //    SLI.Quality1.Fape = "http://dl.stream.qqmusic.qq.com/A000" + songinfo["songmid"].ToString() + ".ape";
                            //}
                            //if (int.Parse(songinfo["sizeflac"].ToString()) != 0)
                            //{
                            //    SLI.Quality1.Flac = true;
                            //    SLI.Quality1.Sflac = songinfo["sizeflac"].ToString();
                            //    SLI.Quality1.Fflac = "http://dl.stream.qqmusic.qq.com/F000" + songinfo["songmid"].ToString() + ".flac";
                            //}
                        }
                        else
                        {
                            if (int.Parse(songinfo["type"].ToString()) == 2)
                            {
                                SLI.Quality1.Qother = true;
                                SLI.Quality1.Fother = songinfo["songurl"].ToString();
                            }
                        }
                        SLI.Singer1 = songinfo["singer"][0]["name"].ToString();
                        Result.List1.Add(SLI);
                    }
                    return(Result);
                }
                catch (Exception ex)
                {
                    return(new ResultData());
                }
            }
Exemple #12
0
            /// <summary>
            /// 获取歌曲文件
            /// </summary>
            /// <param name="Result">必选,搜索结果</param>
            /// <returns>结果</returns>
            public static SongListItem GetSong(SongListItem Result)
            {
                HttpWebRequest  Req;
                HttpWebResponse Rep;

                try
                {
                    byte[] param = Encoding.UTF8.GetBytes("param=" + Convert.ToBase64String(Encoding.UTF8.GetBytes("{\"key\":\"" + Result.SongId1 + "\",\"rate\":\"128,192,256,320,flac\",\"linkType\":0,\"isCloud\":0,\"version\":\"10.1.8.3\"}")));
                    Req             = (HttpWebRequest)WebRequest.Create(@"http://musicmini2014.baidu.com/2016/app/link/getLinks.php");
                    Req.Method      = "POST";
                    Req.ContentType = "application/x-www-form-urlencoded";
                    Req.UserAgent   = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.2; WOW64; Trident/7.0)";
                    Stream reqstream = Req.GetRequestStream();
                    reqstream.Write(param, 0, param.Length);
                    reqstream.Close();
                    Rep = (HttpWebResponse)Req.GetResponse();
                    StreamReader Reader = new StreamReader(Rep.GetResponseStream());
                    string       str    = Reader.ReadToEnd();
                    JObject      p      = JObject.Parse(str);
                    Result.Lrc1         = p["lyric_url"].ToString();
                    Result.Pic1.Large1  = p["album_image_url"].ToString();
                    Result.Pic1.Middle1 = Regex.Split(p["album_image_url"].ToString(), ",")[0] + ",w_250";
                    Result.Pic1.Small1  = p["small_album_image_url"].ToString();
                    string[] Songfilelist = Regex.Split(p["file_list"].ToString().Replace("[", "").Replace("]", "").Replace("\r\n", "").Replace(" ", ""), "},{");
                    for (int i = 0; i < Songfilelist.Length; i++)
                    {
                        if (i != 0 && i != Songfilelist.Length - 1)
                        {
                            Songfilelist[i] = "{" + Songfilelist[i] + "}";
                        }
                        else
                        {
                            if (i == 0 && i != Songfilelist.Length - 1)
                            {
                                Songfilelist[i] = Songfilelist[i] + "}";
                            }
                            else
                            {
                                if (i == Songfilelist.Length - 1 && i != 0)
                                {
                                    Songfilelist[i] = "{" + Songfilelist[i];
                                }
                            }
                        }
                        JObject songdinfo = JObject.Parse(Songfilelist[i]);
                        if (int.Parse(songdinfo["kbps"].ToString()) <= 320)
                        {
                            switch (int.Parse(songdinfo["kbps"].ToString()))
                            {
                            case 128:
                                Result.Quality1.F128 = @"http://zhangmenshiting.baidu.com/data2/music/" + songdinfo["file_id"] + @"/" + songdinfo["file_id"] + @".mp3";
                                Result.Quality1.S128 = songdinfo["size"].ToString();
                                break;

                            case 192:
                                Result.Quality1.F192 = @"http://zhangmenshiting.baidu.com/data2/music/" + songdinfo["file_id"] + @"/" + songdinfo["file_id"] + @".mp3";
                                Result.Quality1.S192 = songdinfo["size"].ToString();
                                break;

                            case 256:
                                Result.Quality1.F256 = @"http://zhangmenshiting.baidu.com/data2/music/" + songdinfo["file_id"] + @"/" + songdinfo["file_id"] + @".mp3";
                                Result.Quality1.S256 = songdinfo["size"].ToString();
                                break;

                            case 320:
                                Result.Quality1.F320 = @"http://zhangmenshiting.baidu.com/data2/music/" + songdinfo["file_id"] + @"/" + songdinfo["file_id"] + @".mp3";
                                Result.Quality1.S320 = songdinfo["size"].ToString();
                                break;
                            }
                        }
                        else
                        {
                            Result.Quality1.Fflac = @"http://zhangmenshiting.baidu.com/data2/music/" + songdinfo["file_id"] + @"/" + songdinfo["file_id"] + @".flac";
                            Result.Quality1.Sflac = songdinfo["size"].ToString();
                        }
                    }
                    return(Result);
                }
                catch (Exception ex)
                {
                    return(Result);
                }
            }
Exemple #13
0
            /// <summary>
            /// 搜索函数
            /// </summary>
            /// <param name="Query">必选,关键字</param>
            /// <param name="PageNumber">可选,页码,默认为1</param>
            /// <param name="PageSize">可选,每页数据条数,默认为20</param>
            /// <returns>结果</returns>
            public static ResultData Search(string Query, int PageNumber = 1, int PageSize = 20)
            {
                HttpWebRequest  Req;
                HttpWebResponse Rep;

                try
                {
                    Req = (HttpWebRequest)WebRequest.Create("http://tingapi.ting.baidu.com/v1/restserver/ting?from=webqpp_music&format=json&callback=&method=baidu.ting.search.common&query=" + HttpUtility.UrlEncode(Query, Encoding.UTF8) + @"&page_size=" + PageSize + @"&page_no=" + PageNumber);
                    Rep = (HttpWebResponse)Req.GetResponse();
                    StreamReader Reader = new StreamReader(Rep.GetResponseStream());
                    string       str    = Reader.ReadToEnd();
                    str = str.Replace("<em>", "").Replace(@"<\/em>", "");
                    JObject    p          = JObject.Parse(str);
                    string[]   Songlist   = Regex.Split(p["song_list"].ToString().Replace("[", "").Replace("]", "").Replace("\r\n", "").Replace(" ", ""), "},{");
                    JObject    SearchInfo = JObject.Parse(p["pages"].ToString());
                    ResultData Result     = new ResultData {
                        List1 = new List <SongListItem>()
                    };
                    Result.Tot = int.Parse(SearchInfo["total"].ToString());
                    for (int i = 0; i < Songlist.Length; i++)
                    {
                        if (i != 0 && i != Songlist.Length - 1)
                        {
                            Songlist[i] = "{" + Songlist[i] + "}";
                        }
                        else
                        {
                            if (i == 0 && i != Songlist.Length - 1)
                            {
                                Songlist[i] = Songlist[i] + "}";
                            }
                            else
                            {
                                if (i == Songlist.Length - 1 && i != 0)
                                {
                                    Songlist[i] = "{" + Songlist[i];
                                }
                            }
                        }
                        JObject      songinfo = JObject.Parse(Songlist[i]);
                        SongListItem SLI      = new SongListItem {
                            Album1 = songinfo["album_title"].ToString(), Singer1 = songinfo["author"].ToString(), SongId1 = songinfo["song_id"].ToString(), SongName1 = songinfo["title"].ToString(), Lrc1 = songinfo["lrclink"].ToString(), Quality1 = new QualityList(), Pic1 = new SongPic(), SongInterval1 = ""
                        };
                        string[] rate = songinfo["all_rate"].ToString().Split(',');
                        for (int j = 0; j < rate.Length; j++)
                        {
                            switch (rate[j])
                            {
                            case "128":
                                SLI.Quality1.Q128 = true;
                                break;

                            case "192":
                                SLI.Quality1.Q192 = true;
                                break;

                            case "256":
                                SLI.Quality1.Q256 = true;
                                break;

                            case "320":
                                SLI.Quality1.Q320 = true;
                                break;

                            case "flac":
                                SLI.Quality1.Flac = true;
                                break;

                            case "ape":
                                SLI.Quality1.Ape = true;
                                break;
                            }
                        }
                        Result.List1.Add(SLI);
                    }
                    return(Result);
                }
                catch (Exception ex)
                {
                    return(new ResultData());
                }
            }