Example #1
0
        private static SearchResult Search(string key, int page, int size)
        {
            if (size > 20)
            {
                size = 20;
            }
            var result = new SearchResult
            {
                ErrorCode = 200,
                ErrorMsg  = "OK",
                KeyWord   = key,
                PageNum   = page,
                TotalSize = -1,
                Songs     = new List <SongResult>()
            };
            var t1 = Task.Factory.StartNew((() =>
            {
                var r1 = WyMusic.Search(key, page, size);
                if (r1?.Songs != null && r1.Songs.Count > 0)
                {
                    lock (result)
                    {
                        result.Songs.AddRange(r1.Songs);
                    }
                }
            }));
            var t2 = Task.Factory.StartNew((() =>
            {
                var r1 = XmMusic.Search(key, page);
                if (r1?.Songs != null && r1.Songs.Count > 0)
                {
                    lock (result)
                    {
                        result.Songs.AddRange(r1.Songs);
                    }
                }
            }));
            var t3 = Task.Factory.StartNew((() =>
            {
                var r1 = TtMusic.Search(key, page, size);
                if (r1?.Songs != null && r1.Songs.Count > 0)
                {
                    lock (result)
                    {
                        result.Songs.AddRange(r1.Songs);
                    }
                }
            }));

            Task.WaitAll(t1, t2, t3);
            if (result.Songs.Count > 0)
            {
                return(result);
            }
            result.ErrorCode = 404;
            result.ErrorMsg  = "没有找到符合要求的歌曲";
            return(result);
        }
Example #2
0
        private static string GetUrl(string id, string quality, string format)
        {
            if (format == "mp4" || format == "flv")
            {
                string mvId;
                string html;
                if (Regex.IsMatch(id, @"^\d+$"))
                {
                    var url = "http://www.xiami.com/song/" + id;
                    html = CommonHelper.GetHtmlContent(url);
                    if (string.IsNullOrEmpty(html))
                    {
                        return("");
                    }
                    mvId = Regex.Match(html, @"(?<=href=""/mv/)\w+(?="")").Value;
                }
                else
                {
                    mvId = id;
                }
                if (string.IsNullOrEmpty(mvId))
                {
                    return(null);
                }
                html = CommonHelper.GetHtmlContent("http://m.xiami.com/mv/" + mvId, 2);
                return(string.IsNullOrEmpty(html) ? "" : Regex.Match(html, @"(?<=<video src="")[^""]+(?=""\s*poster=)").Value);
            }
            var song = SearchSong(id);

            if (song == null)
            {
                return(null);
            }
            if (format == "lrc")
            {
                return(song.LrcUrl);
            }
            if (format == "jpg")
            {
                return(song.PicUrl);
            }
            if (string.IsNullOrEmpty(song.LqUrl) && string.IsNullOrEmpty(song.HqUrl))
            {
                song = TtMusic.GetXmSqUrl(song.ArtistName, song.SongName);
            }
            return(quality != "128" ? song.SqUrl : song.LqUrl);
        }
Example #3
0
 private static CollectResult SearchArtist(string type, string id, string page, string size)
 {
     IMusic music;
     switch (type)
     {
         case "wy":
             music = new WyMusic();
             break;
         case "xm":
             music = new XmMusic();
             break;
         case "tt":
             music = new TtMusic();
             break;
         default:
             return null;
     }
     return music.CollectSearch(id, Convert.ToInt32(page), Convert.ToInt32(size));
 }
Example #4
0
 private static string GetUrl(string type, string id, string quality, string format)
 {
     IMusic music;
     switch (type)
     {
         case "wy":
             music = new WyMusic();
             break;
         case "xm":
             music = new XmMusic();
             break;
         case "tt":
             music = new TtMusic();
             break;
         default:
             return null;
     }
     return music.GetSongUrl(id, quality, format);
 }
Example #5
0
 private static SongResult SearchSong(string type, string id)
 {
     IMusic music;
     switch (type)
     {
         case "wy":
             music = new WyMusic();
             break;
         case "xm":
             music = new XmMusic();
             break;
         case "tt":
             music = new TtMusic();
             break;
         default:
             return null;
     }
     return music.GetSingleSong(id);
 }
Example #6
0
 private static SearchResult Search(string type, string key, string page, string size)
 {
     IMusic music;
     switch (type)
     {
         case "wy":
             music = new WyMusic();
             break;
         case "xm":
             music = new XmMusic();
             break;
         case "tt":
             music = new TtMusic();
             break;
         default:
             music = new AnyMusic();
             break;
     }
     return music.SongSearch(key, Convert.ToInt32(page), Convert.ToInt32(size));
 }