public async Task <SearchResult> Search(string key, EnumSearchType t) { key = key.Trim(); var res = new SearchResult { Items = new List <IMusic>(), Keyword = key, SearchType = t, Page = 1, }; var url = string.Format(search_url, Uri.EscapeDataString(key)); var response = await NetAccess.DownloadStringAsync(url); var json = response.ToDynamicObject(); if (json.song.Count > 0) { foreach (var obj in json.song) { var s = new Song { Id = "b" + MusicHelper.Get(obj, "songid"), ArtistName = MusicHelper.Get(obj, "artistname"), AlbumName = "", Name = MusicHelper.Get(obj, "songname"), WriteId3 = false, }; res.Items.Add(s); s.UrlMp3 = await getDownloadUrl(s.Id.Substring(1)); } } return(res); }
public async Task <SearchResult> Search(string key, EnumSearchType t) { var res = new SearchResult { Items = new List <IMusic>(), Keyword = key, SearchType = t, Page = 1, }; if (string.IsNullOrEmpty(key) || !re_url.IsMatch(key)) { return(res); } var html = await NetAccess.DownloadStringAsync(key); var ms = re_json.Matches(html); if (ms.Count == 0) { return(null); } var artistName = ""; var x = re_artist.Match(html); if (x.Success) { artistName = x.Groups[1].Value; } foreach (Match m in ms) { var listId = m.Groups[1].Value; var json = m.Groups[2].Value.ToDynamicObject(); foreach (var obj in json) { var s = new Song { Id = "d" + MusicHelper.Get(obj, "id"), AlbumName = artistName, ArtistName = artistName, Name = MusicHelper.Get(obj, "name"), UrlMp3 = (MusicHelper.Get(obj, "rawUrl") as string).Replace("\\/", "/"), Logo = MusicHelper.Get(obj, "cover"), WriteId3 = false, }; s.UrlLrc = DoubanUrl.LyricUrl(listId, s.Id.Substring(1)); res.Items.Add(s); } } return(res); }
async Task <string> getDownloadUrl(string id) { var url = string.Format("http://music.baidu.com/song/{0}/download", id); var html = await NetAccess.DownloadStringAsync(url); var m = re_download.Match(html); if (!m.Success) { return(null); } return(m.Groups[1].Value); }
//public override bool CanDownload //{ // get // { // var song = Info.Entity as SongViewModel; // return song != null && song.HasXml; // } //} public override async Task Download() { var item = Info.Entity as SongViewModel; if (item == null) { return; } if (string.IsNullOrEmpty(item.UrlLrc)) { var url = await NetAccess.DownloadStringAsync(XiamiUrl.UrlSongInfo(item.SongId)); } Info.Url = (Info.Entity as SongViewModel).UrlLrc; await base.Download(); }