public async Task ShouldCellphoneLoginSuccess()
        {
            var api  = new MusicApi();
            var user = await api.LoginAsync(Configuration.Username, Configuration.Password);

            Assert.AreEqual(user.Name, Configuration.Nickname);
        }
        public async Task ShouldRecommendNotWorkWithoutLogin()
        {
            var api = new MusicApi();
            await Assert.ThrowsExceptionAsync <HttpRequestException>(api.RecommendAsync <Playlist>);

            api.Dispose();
        }
        public async Task ShouldCookiePersist()
        {
            var storage = new Storage();
            var api     = new MusicApi(storage);
            var user    = api.Me ?? await api.LoginAsync(Configuration.Username, Configuration.Password);

            api.Dispose();
            api = new MusicApi(storage);
            Assert.IsNotNull(api.Me);
            await api.RecommendAsync <Song>();
        }
Exemple #4
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="topId"></param>
        /// <param name="offset"></param>
        /// <param name="num"></param>
        public async Task InitFromJsonAsync(int topId, int offset, int num)
        {
            string res = await HttpClientHelper.GetAsync(MusicApi.GetTopList(topId, offset, num));

            try
            {
                JObject json = JObject.Parse(res);
                Date          = json["date"].ToString();
                TopId         = topId;
                Cursor        = json["cur_song_num"].ToObject <int>();
                TotalSong     = json["total_song_num"].ToObject <int>();
                Name          = json["topinfo"]["ListName"].ToString();
                Listennum     = json["topinfo"]["listennum"].ToString();
                H5CoverUrl    = json["topinfo"]["pic_h5"].ToString();
                AlbumCoverUrl = json["topinfo"]["pic_album"].ToString();
                Info          = json["topinfo"]["info"].ToString();
                var list = json["songlist"];
                if (list.Any())
                {
                    foreach (var song in list)
                    {
                        Song son = new Song();
                        son.Time = song["data"]["interval"].ToString();
                        var singers   = song["data"]["singer"];
                        var oneSinger = singers.First;
                        son.Singer = new Singer()
                        {
                            Id   = oneSinger["id"].ToString(),
                            Name = oneSinger["name"].ToString(),
                            MId  = oneSinger["mid"].ToString()
                        };
                        son.Id    = song["data"]["songid"].ToString();
                        son.MId   = song["data"]["songmid"].ToString();
                        son.Name  = song["data"]["songname"].ToString();
                        son.Album = new Album()
                        {
                            AlbumId  = song["data"]["albumid"].ToString(),
                            Name     = song["data"]["albumname"].ToString(),
                            Desc     = song["data"]["albumdesc"].ToString(),
                            CoverUrl = ""
                        };
                        Songs.Add(son);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemple #5
0
        public void GetSongList(int page)
        {
            DispatchService.Invoke(() =>
            {
                if (string.IsNullOrEmpty(txtSearch.Text))
                {
                    return;
                }


                try
                {
                    var jsonString  = MusicApi.Search(txtSearch.Text, 10, 10 * (page));
                    dynamic jsonObj = JsonConvert.DeserializeObject(jsonString);
                    var result      = jsonObj.result;
                    var songlist    = result.songs;
                    int j           = 1;
                    foreach (var item in songlist)
                    {
                        var album  = item.album;
                        var artist = album.artist;
                        DispatchService.Invoke(() =>
                        {
                            mySongList.Add(new Song
                            {
                                id    = 10 * page + j++,
                                apid  = item.id,
                                title = item.name,
                                path  = @"http://music.163.com/song/media/outer/url?id=" + item.id + ".mp3"
                            });
                        });
                    }
                    //Listview回到顶端
                    if (mySongList.Count > 0)
                    {
                        listViewSongList.ScrollIntoView(listViewSongList.Items[0]);

                        if (!playerInfo.IsShowList)
                        {
                            playerInfo.IsShowList = true;
                        }
                    }
                }
                catch (Exception)
                {
                }
            });
        }
Exemple #6
0
        static void Main(string[] args)
        {
            //IndexData data=new IndexData();
            //data.GetIndexData();
            var dsdasdas = MusicApi.GetIndexList();
            var fdf      = HttpClientHelper.GetAsync(dsdasdas).Result;
            var resss    = SearchApi.GetKeySuggest("李");
            var str      = MusicApi.GetKeySuggesUrl("修炼爱情");
            var ss       = HttpClientHelper.GetAsync(str).Result;
            var swe      = MusicApi.GetHotKey();
            var sdsad    = HttpClientHelper.GetAsync(swe).Result;
            var sds      = AlbumApi.InitBriefInfoAlbumAsync("2265047").Result;
            //var sss =
            //    MusicApi.GetSingerAlbum("000GGDys0yA0Nk", 0, 10);
            var     bir     = ImageHelper.DownAsync("http://y.gtimg.cn/music/photo_new/T002R500x500M000004Z9rf305fzyj.jpg").Result;
            SongApi songApi = new SongApi();

            songApi.InitAllListAsync().Wait();
            var lis = songApi.GetCover();

            foreach (var song in lis)
            {
                song.Album.GetAllInfor.BeginInvoke(string.Empty, null, null);
            }
            TopList top = new TopList();

            top.InitFromJsonAsync(4, 0, 10).Wait();
            var sss = MusicApi.GetTopList(4, 0, 30);

            var ssss = HttpClientHelper.GetAsync(sss).Result;

            JObject json = JObject.Parse(ssss);
            var     list = json["songlist"];

            foreach (var VARIABLE in list)
            {
            }

            var s = MusicApi.GetMusicianUrl(1, 200, NetMusic.Mode.MusicianType.cn_man, "L");

            var tt = HttpClientHelper.GetAsync(s).Result;
        }
Exemple #7
0
 public IActionResult Get(string type, string id)
 {
     try
     {
         string json    = MusicApi.Search(id, 1, 0, 1);
         var    jsonObj = JsonConvert.DeserializeObject <dynamic>(json);
         var    result  = jsonObj.result;
         if (result != null)
         {
             var songs = result.songs;
             if (songs != null)
             {
                 string musicId       = songs[0].id;
                 string detailjson    = MusicApi.Detail(musicId);
                 var    detailjsonObj = JsonConvert.DeserializeObject <dynamic>(detailjson);
                 string lyricjson     = MusicApi.Lyric(musicId);
                 var    lyricjsonObj  = JsonConvert.DeserializeObject <dynamic>(lyricjson);
                 string lyric         = string.Empty;
                 if (lyricjsonObj.nolyric == null && lyricjsonObj.uncollected == null)
                 {
                     lyric = lyricjsonObj.lrc.lyric;
                 }
                 var url    = $"http://music.163.com/song/media/outer/url?id={musicId}.mp3";
                 var name   = songs[0].name;
                 var artist = songs[0].artists[0].name;
                 var cover  = detailjsonObj.songs[0].album.picUrl;
                 return(Json(new { code = 0, url = url, name = name, artist = artist, cover = cover, lyric = lyric, msg = "" }));
             }
         }
         return(Json(new { code = 1, msg = "获取音乐链接失败" }));
     }
     catch (Exception ex)
     {
         return(Json(new { code = 1, msg = ex.ToString() }));
     }
 }
Exemple #8
0
        public string GetCover(string songId)
        {
            try
            {
                string detailjson = MusicApi.Detail(songId);
                if (string.IsNullOrEmpty(detailjson))
                {
                    haveLyric = false; return(null);
                }
                var detailjsonObj = JsonConvert.DeserializeObject <dynamic>(detailjson);
                if (detailjsonObj == null)
                {
                    haveLyric = false; return(null);
                }
                var    artists  = detailjsonObj.songs[0].artists;
                var    album    = detailjsonObj.songs[0].album.name;
                string duration = detailjsonObj.songs[0].duration;
                if (duration != null)
                {
                    try
                    {
                        TimeSpan ts = TimeSpan.FromMilliseconds(double.Parse(duration));
                        MaxLength            = ts.TotalSeconds;
                        txtTotalSeconds.Text = TimeSpanToDateTime(ts);
                    }
                    catch { }
                }

                if (album != null)
                {
                    playerInfo.Album = album;
                }

                //获取歌词
                string lyricjson    = MusicApi.Lyric(songId);
                var    lyricjsonObj = JsonConvert.DeserializeObject <dynamic>(lyricjson);
                string lyric        = string.Empty;
                if (lyricjsonObj != null && lyricjsonObj.nolyric == null && lyricjsonObj.uncollected == null)
                {
                    lyric = lrcTemp = lyricjsonObj.lrc.lyric;
                }
                else
                {
                    lyric = lrcTemp = string.Empty;
                }

                List <string> listArtists = new List <string>();
                if (artists != null)
                {
                    foreach (var item in artists)
                    {
                        listArtists.Add((string)item.name);
                    }
                    string strArtists = string.Join("/", listArtists);
                    mySongList[listViewSongList.SelectedIndex].artist = strArtists;
                }
                else
                {
                    mySongList[listViewSongList.SelectedIndex].artist = "未知";
                }


                //mySongList[listViewSongList.SelectedIndex].lyric = lyric;

                if (!string.IsNullOrEmpty(lyric))
                {
                    //byte[] array = Lrc.ByteArrayCut(Encoding.Default.GetBytes(lyric), 0x3f);
                    //将默认编码转到Unicode
                    byte[] arraydefalut = Encoding.UTF8.GetBytes(lyric);
                    byte[] arrayunicode = Encoding.Convert(Encoding.UTF8, Encoding.Unicode, arraydefalut);

                    MemoryStream stream = new MemoryStream(arrayunicode);
                    lrc       = Lrc.InitLrc(stream);
                    haveLyric = true;
                    //有歌词
                    DoShowLrc("");
                }
                else
                {
                    haveLyric = false;
                    DoShowLrc("没有歌词");
                }

                return(detailjsonObj.songs[0].album.picUrl);
            }
            catch (Exception)
            {
                haveLyric = false;
                DoShowLrc("歌词获取失败");

                return(string.Empty);
            }
        }
Exemple #9
0
        /// <summary>
        /// 同步方式获取首页的数据
        /// </summary>
        public void GetIndexData()
        {
            string indexUrl = MusicApi.GetIndexList();
            string indexRes = HttpClientHelper.GetAsync(indexUrl).Result;

            try
            {
                JObject resulJObject = JObject.Parse(indexRes);
                JToken  foucuses     = resulJObject["data"]["focus"];
                JToken  hotdisses    = resulJObject["data"]["hotdiss"]["list"];
                JToken  tops         = resulJObject["data"]["toplist"];
                if (foucuses != null)
                {
                    foreach (var foucuse in foucuses)
                    {
                        DispatcherHelper.CheckBeginInvokeOnUI((() =>
                        {
                            Foucuses.Add(new Focus()
                            {
                                Fid = foucuse["fid"].ToString(),
                                Id = foucuse["id"].ToString(),
                                JumpUrl = foucuse["jumpurl"].ToString(),
                                PicUrl = foucuse["pic"].ToString(),
                                Title = foucuse["title"].ToString(),
                                Type = foucuse["type"].ToString()
                            });
                        }));
                    }
                }
                if (hotdisses != null)
                {
                    foreach (var hotdiss in hotdisses)
                    {
                        DispatcherHelper.CheckBeginInvokeOnUI((() =>
                        {
                            Hotdisses.Add(new Hotdiss()
                            {
                                Author = hotdiss["author"].ToString(),
                                DissId = hotdiss["dissid"].ToString(),
                                DissName = hotdiss["dissname"].ToString(),
                                ImgUrl = hotdiss["imgurl"].ToString(),
                                ListenNum = hotdiss["listennum"].ToString()
                            });
                        }));
                    }
                }
                if (tops != null)
                {
                    foreach (var top in tops)
                    {
                        JToken      songs    = top["songlist"];
                        List <Song> songList = new List <Song>();
                        foreach (var song in songs)
                        {
                            songList.Add(new Song()
                            {
                                Singer = new Singer()
                                {
                                    Id   = song["singerid"].ToString(),
                                    Name = song["singername"].ToString(),
                                },
                                Id   = song["songid"].ToString(),
                                Name = song["songname"].ToString()
                            });
                        }
                        DispatcherHelper.CheckBeginInvokeOnUI((() =>
                        {
                            Tops.Add(new Top()
                            {
                                HeadPic_v12 = top["headPic_v12"].ToString(),
                                ListenNum = top["listennum"].ToString(),
                                ListName = top["ListName"].ToString(),
                                MacDetailPicUrl = top["MacDetailPicUrl"].ToString(),
                                ShowTime = top["showtime"].ToString(),
                                SongList = new ObservableCollection <Song>(songList)
                            });
                        }));
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemple #10
0
 public HttpResponseMessage PlayList(string id = null)
 {
     return(Json(MusicApi.PlayList(id)));
 }
Exemple #11
0
 public HttpResponseMessage MV(string id = null)
 {
     return(Json(MusicApi.MV(id)));
 }
Exemple #12
0
 public HttpResponseMessage Lyric(string id)
 {
     return(Json(MusicApi.Lyric(id)));
 }
Exemple #13
0
 public HttpResponseMessage Detail(string ids = null)
 {
     return(Json(MusicApi.Detail(ids)));
 }
Exemple #14
0
 public HttpResponseMessage TopPlaylist(string cat = "全部", int limit = 50, int offset = 0, string order = "hot")
 {
     return(Json(MusicApi.TPlayList(cat, limit, offset, order)));
 }
Exemple #15
0
 public HttpResponseMessage Search(string s = null, int limit = 30, int offset = 0, int type = 1)
 {
     return(Json(MusicApi.Search(s, limit, offset, type)));
 }
Exemple #16
0
 public static void AssemblyInitialize(TestContext context)
 {
     Api = new MusicApi(new Storage());
 }