Exemple #1
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 #2
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);
                }
            }