public void GetExistedMusicTest([Random(0, MusicCount - 1, 5)] int id)
        {
            var expectedMusic = _fakeDbMusicData.Music.Find(f => f.Id == id);

            var actualMusic = _musicDetailedInfoService.GetMusic(id);

            actualMusic.Should().BeEquivalentTo(expectedMusic,
                                                options => options.ExcludingMissingMembers().Excluding(mus => mus.Duration));
            actualMusic.Musicians.Should().BeEquivalentTo(expectedMusic.Musicians,
                                                          options => options.ExcludingMissingMembers());
            actualMusic.Genres.Should().BeEquivalentTo(expectedMusic.Genres,
                                                       options => options.ExcludingMissingMembers());
        }
Esempio n. 2
0
 public CollectResult CollectSearch([FromQuery] string t, [FromQuery] string id, [FromQuery] int p, [FromQuery] int s)
 {
     if (string.IsNullOrEmpty(t))
     {
         return(new CollectResult
         {
             ErrorCode = 403,
             ErrorMsg = "请输入搜索类型"
         });
     }
     if (string.IsNullOrEmpty(id))
     {
         return(new CollectResult
         {
             ErrorCode = 403,
             ErrorMsg = "请输入歌单ID"
         });
     }
     if (p == 0)
     {
         p = 1;
     }
     if (s == 0)
     {
         s = 1000;
     }
     return(MusicService.GetMusic(t).CollectSearch(id, p, s));
 }
Esempio n. 3
0
 public ArtistResult SearchArtist([FromQuery] string t, [FromQuery] string id, [FromQuery] int p, [FromQuery] int s)
 {
     if (string.IsNullOrEmpty(t))
     {
         return(new ArtistResult
         {
             ErrorCode = 403,
             ErrorMsg = "请输入搜索类型"
         });
     }
     if (string.IsNullOrEmpty(id))
     {
         return(new ArtistResult
         {
             ErrorCode = 403,
             ErrorMsg = "请输入艺术家ID"
         });
     }
     if (p == 0)
     {
         p = 1;
     }
     if (s == 0)
     {
         s = 50;
     }
     return(MusicService.GetMusic(t).ArtistSearch(id, p, s));
 }
Esempio n. 4
0
 public SearchResult Search([FromQuery] string t, [FromQuery] string k, [FromQuery] int p, [FromQuery] int s)
 {
     if (string.IsNullOrEmpty(t))
     {
         return(new SearchResult
         {
             ErrorCode = 403,
             ErrorMsg = "请输入搜索类型"
         });
     }
     if (string.IsNullOrEmpty(k))
     {
         return(new SearchResult
         {
             ErrorCode = 403,
             ErrorMsg = "请输入关键词"
         });
     }
     if (p == 0)
     {
         p = 1;
     }
     if (s == 0)
     {
         s = 30;
     }
     return(MusicService.GetMusic(t).SongSearch(k, p, s));
 }
Esempio n. 5
0
 public SongResult SongSearch([FromQuery] string t, [FromQuery] string id)
 {
     if (string.IsNullOrEmpty(t) || string.IsNullOrEmpty(id))
     {
         return(null);
     }
     return(MusicService.GetMusic(t).GetSingleSong(id));
 }
Esempio n. 6
0
 public List <SongResult> SearchAlbum([FromQuery] string t, [FromQuery] string id)
 {
     if (string.IsNullOrEmpty(t) || string.IsNullOrEmpty(id))
     {
         Response.StatusCode = 403;
         return(null);
     }
     return(MusicService.GetMusic(t).AlbumSearch(id));
 }
Esempio n. 7
0
        public void Get(string path, [FromQuery] string sign)
        {
            if (CommonHelper.Md5(path + CommonHelper.SignKey) != sign)
            {
                Response.StatusCode = 403;
                return;
            }
            if (string.IsNullOrEmpty(path))
            {
                Response.StatusCode = 403;
                return;
            }
            var paths = path.Split('.');

            if (paths.Length != 2)
            {
                Response.StatusCode = 403;
                return;
            }
            var keys = paths[0].Split('_');

            if (keys.Length != 3)
            {
                Response.StatusCode = 403;
                return;
            }
            var linkInfo = MusicService.GetMusic(keys[0]).GetSongUrl(keys[2], keys[1], paths[1]);

            if (linkInfo == null)
            {
                Response.StatusCode = 404;
                return;
            }
            if (linkInfo.StartsWith("http://"))
            {
                Response.StatusCode = 302;
                Response.Headers.Add("Location", linkInfo);
            }
            else
            {
                if (string.IsNullOrEmpty(linkInfo))
                {
                    Response.StatusCode = 404;
                }
                else
                {
                    Response.StatusCode = 200;
                    Response.WriteAsync(linkInfo);
                }
            }
        }
Esempio n. 8
0
 public List <SongResult> CollectSearch([FromQuery] string t, [FromQuery] string id, [FromQuery] int p, [FromQuery] int s)
 {
     if (string.IsNullOrEmpty(t) || string.IsNullOrEmpty(id))
     {
         Response.StatusCode = 403;
         return(null);
     }
     if (p == 0)
     {
         p = 1;
     }
     if (s == 0)
     {
         s = 1000;
     }
     return(MusicService.GetMusic(t).CollectSearch(id, p, s));
 }
Esempio n. 9
0
 public List <SongResult> Search([FromQuery] string t, [FromQuery] string k, [FromQuery] int p, [FromQuery] int s)
 {
     if (string.IsNullOrEmpty(t) || string.IsNullOrEmpty(k))
     {
         Response.StatusCode = 403;
         return(null);
     }
     if (p == 0)
     {
         p = 1;
     }
     if (s == 0)
     {
         s = 30;
     }
     return(MusicService.GetMusic(t).SongSearch(k, p, s));
 }
Esempio n. 10
0
 public AlbumResult SearchAlbum([FromQuery] string t, [FromQuery] string id)
 {
     if (string.IsNullOrEmpty(t))
     {
         return(new AlbumResult
         {
             ErrorCode = 403,
             ErrorMsg = "请输入搜索类型"
         });
     }
     if (string.IsNullOrEmpty(id))
     {
         return(new AlbumResult
         {
             ErrorCode = 403,
             ErrorMsg = "请输入专辑ID"
         });
     }
     return(MusicService.GetMusic(t).AlbumSearch(id));
 }
Esempio n. 11
0
        private static string GetUrlFromThird(string id, string quality)
        {
            var singleSong = SearchSingle(id);
            var songListQq = MusicService.GetMusic("qq")
                             .SongSearch(singleSong.ArtistName + "-" + singleSong.SongName, 1, 30);
            SongResult song = null;

            if (songListQq != null)
            {
                song = songListQq.FirstOrDefault(t => CommonHelper.CompareStr(t.SongName, singleSong.SongName) &&
                                                 (CommonHelper.CompareStr(t.ArtistName, singleSong.ArtistName) || CommonHelper.CompareStr(t.AlbumName, singleSong.AlbumName)));
            }
            if (song == null)
            {
                var songList = MusicService.GetMusic("xm")
                               .SongSearch(singleSong.ArtistName + "-" + singleSong.SongName, 1, 30);
                song = songList.FirstOrDefault(t => CommonHelper.CompareStr(t.SongName, singleSong.SongName) &&
                                               (CommonHelper.CompareStr(t.ArtistName, singleSong.ArtistName) || CommonHelper.CompareStr(t.AlbumName, singleSong.AlbumName)));
                if (song == null)
                {
                    song = songListQq.FirstOrDefault(t => CommonHelper.CompareStr(t.SongName, singleSong.SongName));
                }
                if (song == null)
                {
                    song = songList.FirstOrDefault(t => CommonHelper.CompareStr(t.SongName, singleSong.SongName));
                }
            }
            if (song == null)
            {
                return("");
            }
            if (quality == "999000")
            {
                if (!string.IsNullOrEmpty(song.FlacUrl))
                {
                    return(song.FlacUrl);
                }
                if (!string.IsNullOrEmpty(song.ApeUrl))
                {
                    return(song.ApeUrl);
                }
                if (!string.IsNullOrEmpty(song.WavUrl))
                {
                    return(song.WavUrl);
                }
                if (!string.IsNullOrEmpty(song.SqUrl))
                {
                    return(song.SqUrl);
                }
                if (!string.IsNullOrEmpty(song.HqUrl))
                {
                    return(song.HqUrl);
                }
            }
            else if (quality == "320000" || quality == "192000")
            {
                if (!string.IsNullOrEmpty(song.SqUrl))
                {
                    return(song.SqUrl);
                }
            }
            return(song.LqUrl);
        }