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 void CreateFromJson(dynamic obj) { MusicHelper.LoadMusicInfoFromJson(this, obj); if (string.IsNullOrEmpty(Id)) { Id = MusicHelper.Get(obj, "list_id"); } }
void OnMp3PlayerSongChanged(object sender, SongChangedEventArgs e) { source.Clear(); SongViewModel svm = SongViewModel.GetId(e.Id); if (svm == null) { return; } var lrcPath = Path.Combine(Global.AppSettings["DownloadFolder"], svm.FileNameBase + ".lrc"); if (!File.Exists(lrcPath)) { lrcPath = Path.Combine(Global.BasePath, "cache", e.Id + ".lrc"); } if (!File.Exists(lrcPath)) { Task.Run(async() => { var url = svm.Song.UrlLrc; if (string.IsNullOrEmpty(url)) { var json = await NetAccess.Json(XiamiUrl.url_song, "id", svm.Id); if (json.song != null) { json = json.song; } url = MusicHelper.Get(json, "lyric", "song_lrc"); if (string.IsNullOrEmpty(url)) { return; } } string lrcText = await Http.Get(url, null); File.WriteAllText(lrcPath, lrcText); var f = LyricViewModel.LoadLrcFile(lrcPath); UIHelper.RunOnUI(() => { foreach (var item in f) { source.Add(item); } timelist = source.Select(x => x.Time.TotalMilliseconds).ToArray(); }); }); return; } var s = LyricViewModel.LoadLrcFile(lrcPath); foreach (var item in s) { source.Add(item); } timelist = source.Select(x => x.Time.TotalMilliseconds).ToArray(); }
public void CreateFromJson(dynamic obj) { MusicHelper.LoadMusicInfoFromJson(this, obj); ArtistId = MusicHelper.Get(obj, "artist_id"); ArtistName = MusicHelper.Get(obj, "artist_name"); if (string.IsNullOrEmpty(ArtistId) && obj["songs"] != null) { ArtistId = MusicHelper.Get(obj["songs"][0], "artist_id"); ArtistName = MusicHelper.Get(obj["songs"][0], "artist_name"); } }
public void CreateFromJson(dynamic obj) { MusicHelper.LoadMusicInfoFromJson(this, obj); ArtistId = MusicHelper.Get(obj, "artist_id"); ArtistName = MusicHelper.Get(obj, "artist_name", "name"); AlbumId = MusicHelper.Get(obj, "album_id"); AlbumName = MusicHelper.Get(obj, "album_name", "name"); UrlMp3 = StringHelper.EscapeUrl(MusicHelper.Get(obj, "location", "song_location", "listen_file")); UrlLrc = StringHelper.EscapeUrl(MusicHelper.Get(obj, "lyric", "song_lyric")); Description = MusicHelper.Get(obj, "reason", "description"); WriteId3 = true; }
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); }
public void CreateFromJson(dynamic obj) { MusicHelper.LoadMusicInfoFromJson(this, obj); Description = MusicHelper.Get(obj, "count_likes"); if (!string.IsNullOrEmpty(Description)) { Description += "位粉丝"; } AlbumCount = MusicHelper.Get(obj, "albums_count", "count"); if (!string.IsNullOrEmpty(AlbumCount)) { AlbumCount += "张专辑"; } }
void btn_import_click(object sender, RoutedEventArgs e) { var dir = Global.AppSettings["DownloadFolder"]; Task.Run(async() => { var buffer = new List <IMusic>(); int bufferLength = 10; var mp3s = Directory.EnumerateFiles(dir, "*.mp3").ToArray(); foreach (var item in mp3s) { try { var mp3 = TagLib.File.Create(item); var tags = mp3.Tag; if (tags.Comment == null) { continue; } var id = ""; var artistid = ""; var albumid = ""; var logo = ""; var m = reg_ids.Match(tags.Comment); if (!m.Success) { m = reg.Match(tags.Comment); if (!m.Success) { continue; } id = m.Groups[1].Value; var obj = await NetAccess.Json(XiamiUrl.url_song, "id", id); artistid = MusicHelper.Get(obj["song"], "artist_id"); albumid = MusicHelper.Get(obj["song"], "album_id"); logo = StringHelper.EscapeUrl(MusicHelper.Get(obj["song"], "logo")); tags.Comment = string.Join(" ", new[] { id, artistid, albumid }); mp3.Save(); } else { id = m.Groups[1].Value; artistid = m.Groups[2].Value; albumid = m.Groups[3].Value; } var art = System.IO.Path.Combine(Global.BasePath, "cache", albumid + ".art"); if (!File.Exists(art)) { if (string.IsNullOrEmpty(logo)) { var obj = await NetAccess.Json(XiamiUrl.url_song, "id", id); logo = StringHelper.EscapeUrl(MusicHelper.Get(obj["song"], "logo")); } await new System.Net.WebClient().DownloadFileTaskAsync(logo, art); } var song = new Song { Id = id, ArtistId = artistid, AlbumId = albumid, Name = tags.Title, ArtistName = tags.FirstPerformer, AlbumName = tags.Album, FilePath = item, Logo = logo, }; buffer.Add(song); } catch { } if (buffer.Count == bufferLength) { var songs = new List <IMusic>(); foreach (var s in buffer.OfType <Song>()) { SongViewModel.Get(s).HasMp3 = true; } songs.AddRange(buffer); Items.AddItems(songs); buffer.Clear(); } } if (buffer.Count > 0) { foreach (var s in buffer.OfType <Song>()) { SongViewModel.Get(s).HasMp3 = true; } Items.AddItems(buffer); } }); }