public void SetNameAndArtistFromTitle() { var match = new MatchSong(); match.SetNameAndArtistFromTitle("Childish Gambino - 3005", true); Assert.AreEqual(match.Title, "3005"); Assert.AreEqual(match.Artist, "Childish Gambino"); }
protected override async Task<List<MatchSong>> InternalGetSongsAsync(string title, string artist, int limit = 10) { using (var response = await new Mp3FreexSearchRequest(title.Append(artist)).ToResponseAsync().DontMarshall() ) { if (!response.HasData) return null; var songNodes = response.Data.DocumentNode.Descendants("div") .Where(p => p.Attributes["class"]?.Value.Contains("actl") ?? false).Take(limit); var songs = new List<MatchSong>(); foreach (var songNode in songNodes) { var song = new MatchSong(); var songTitle = songNode.Descendants("span") .FirstOrDefault(p => p.Attributes["class"]?.Value == "res_title")? .InnerText; if (string.IsNullOrEmpty(songTitle)) continue; song.SetNameAndArtistFromTitle(WebUtility.HtmlDecode(songTitle), true); var meta = songNode.Descendants("span") .FirstOrDefault(p => p.Attributes["class"]?.Value == "label label-info")? .InnerText; if (!string.IsNullOrEmpty(meta)) { var duration = meta.Substring(0, meta.IndexOf("|", StringComparison.Ordinal)).Trim(); var seconds = int.Parse(duration.Substring(duration.Length - 2, 2)); var minutes = int.Parse(duration.Remove(duration.Length - 3)); song.Duration = new TimeSpan(0, 0, minutes, seconds); int bitrate; if (int.TryParse(meta.Substring(meta.IndexOf("|", StringComparison.Ordinal) + 1).Replace("kbps", ""), out bitrate)) { song.BitRate = bitrate; } } var linkNode = songNode.Descendants("a") .FirstOrDefault(p => p.Attributes["class"]?.Value.Contains("mp3download") ?? false); var url = linkNode?.Attributes["data-online"]?.Value; if (string.IsNullOrEmpty(url)) continue; song.AudioUrl = await GetAudioUrlAsync(url).DontMarshall(); if (string.IsNullOrEmpty(song.AudioUrl)) continue; songs.Add(song); } return songs; } }
private void MatchViewer_OnPlayClick(object sender, MatchSong e) { var player = App.Current.Kernel.Resolve<IPlayerService>(); if (player.CurrentState == MediaPlayerState.Playing) player.PlayOrPause(); PlaybackPlayer.Source = new Uri(e.AudioUrl); PlaybackPlayer.Play(); }
protected override async Task<List<MatchSong>> InternalGetSongsAsync(string title, string artist, int limit = 10) { using (var resp = await new MiMp3SSearchRequest(title.Append(artist).ToLower()).ToResponseAsync()) { if (!resp.HasData) return null; var songNodes = resp.Data.DocumentNode.Descendants("ul") .FirstOrDefault(p => p.Attributes["class"]?.Value == "mp3-list").Descendants("li"); var songs = new List<MatchSong>(); foreach (var songNode in songNodes) { var song = new MatchSong(); var titleNode = songNode.Descendants("span").FirstOrDefault(p => p.Attributes["class"]?.Value == "mp3-title"); if (titleNode == null) continue; titleNode.Descendants("font").FirstOrDefault().Remove(); var songTitle = titleNode.InnerText; if (string.IsNullOrEmpty(songTitle)) continue; song.Title = WebUtility.HtmlDecode(songTitle.Remove(songTitle.LastIndexOf(" - MP3", StringComparison.Ordinal)).Trim()); var meta = WebUtility.HtmlDecode( songNode.Descendants("span") .FirstOrDefault(p => p.Attributes["class"]?.Value == "mp3-url") .InnerText); if (!string.IsNullOrEmpty(meta)) { var duration = meta.Substring(10, meta.IndexOf("•", StringComparison.Ordinal) - 10).Trim(); TimeSpan parsed; if (TimeSpan.TryParse("00:" + duration, out parsed)) { song.Duration = parsed; } } var linkNode = songNode.Descendants("a").FirstOrDefault(p => p.Attributes["class"]?.Value == "play_button"); song.AudioUrl = linkNode.Attributes["href"]?.Value; if (string.IsNullOrEmpty(song.AudioUrl)) continue; song.AudioUrl = await GetAudioUrlAsync(song.AudioUrl); if (string.IsNullOrEmpty(song.AudioUrl)) continue; songs.Add(song); } return songs.Take(limit).ToList(); } }
protected override async Task<List<MatchSong>> InternalGetSongsAsync(string title, string artist, int limit = 10) { using (var resp = await new AnyMazaSearchRequest(title.Append(artist)).ToResponseAsync()) { if (!resp.HasData) return null; var songs = new List<MatchSong>(); foreach (var googleResult in resp.Data.ResponseData.Results) { var song = new MatchSong(); if (!googleResult.Url.StartsWith("http://anymaza.com/music/")) continue; song.SetNameAndArtistFromTitle(googleResult.TitleNoFormatting.Remove(googleResult.TitleNoFormatting.LastIndexOf(artist, StringComparison.Ordinal) + artist.Length).Replace(" By ", " - "), false); using (var anymazaResp = await googleResult.Url.ToUri().GetAsync()) { if (!anymazaResp.IsSuccessStatusCode) continue; var document = await anymazaResp.ParseHtmlAsync(); var duration = document.DocumentNode.Descendants("center").FirstOrDefault()?.InnerText; //Category: Justin Bieber - Purpose ( Deluxe Edition ) Duration: 3:28 sec Singer : Justin Bieber if (!string.IsNullOrEmpty(duration)) { duration = duration.Substring(duration.IndexOf("Duration:", StringComparison.Ordinal) + 9); duration = duration.Remove(duration.LastIndexOf("sec", StringComparison.Ordinal)).Trim(); TimeSpan dur; if (TimeSpan.TryParse("00:" + duration, out dur)) { song.Duration = dur; } } var link = document.DocumentNode.Descendants("a") .FirstOrDefault(p => p.Attributes["class"]?.Value == "dowbutzip")?.Attributes["href"]?.Value; if (string.IsNullOrEmpty(link)) continue; if (link.StartsWith("/")) song.AudioUrl = "http://anymaza.com" + link; else song.AudioUrl = link; } songs.Add(song); } return songs; } }
protected override async Task<List<MatchSong>> InternalGetSongsAsync(string title, string artist, int limit = 10) { // in the query, the artist goes first. Results don't work otherwise. using (var response = await new Mp3PmSearchRequest(artist.Append(title)).ToResponseAsync()) { if (!response.HasData) return null; var songNodes = response.Data.DocumentNode.Descendants("li") .Where(p => p.Attributes.Contains("data-sound-url")) .Take(limit); var songs = new List<MatchSong>(); foreach (var songNode in songNodes) { var song = new MatchSong { Id = songNode.Attributes["data-sound-id"]?.Value, AudioUrl = songNode.Attributes["data-sound-url"]?.Value }; if (string.IsNullOrEmpty(song.AudioUrl)) continue; var titleText = songNode.Descendants("b") .FirstOrDefault(p => p.Attributes["class"]?.Value == "cplayer-data-sound-title")?.InnerText; if (string.IsNullOrEmpty(titleText)) continue; song.Title = WebUtility.HtmlDecode(titleText); var artistText = songNode.Descendants("i") .FirstOrDefault(p => p.Attributes["class"]?.Value == "cplayer-data-sound-author")?.InnerText; if (string.IsNullOrEmpty(artistText)) continue; song.Artist = WebUtility.HtmlDecode(artistText); var durationText = songNode.Descendants("em") .FirstOrDefault(p => p.Attributes["class"]?.Value == "cplayer-data-sound-time")?.InnerText; TimeSpan duration; if (TimeSpan.TryParse("00:" + durationText, out duration)) { song.Duration = duration; } songs.Add(song); } return songs; } }
protected override async Task<List<MatchSong>> InternalGetSongsAsync(string title, string artist, int limit = 10) { using (var response = await new PleerSearchRequest(title.Append(artist)).ToResponseAsync().DontMarshall()) { var o = response.Data; if (!response.HasData || !o.Value<bool>("success")) return null; var html = o.Value<string>("html"); var doc = new HtmlDocument(); doc.LoadHtml(html); var songNodes = doc.DocumentNode.Descendants("li").Where(p => p.Attributes.Contains("file_id")).Take(limit); var songs = new List<MatchSong>(); foreach (var songNode in songNodes) { var song = new MatchSong { Id = songNode.Attributes["file_id"].Value, Title = WebUtility.HtmlDecode(songNode.Attributes["song"].Value), Artist = WebUtility.HtmlDecode(songNode.Attributes["singer"].Value) }; int bitRate; if (int.TryParse(songNode.Attributes["rate"].Value.Replace(" Kb/s", ""), out bitRate)) { song.BitRate = bitRate; } int seconds; if (int.TryParse(songNode.Attributes["duration"].Value, out seconds)) { song.Duration = TimeSpan.FromSeconds(seconds); } var linkId = songNode.Attributes["link"].Value; song.AudioUrl = await GetPleerLinkAsync(linkId); if (string.IsNullOrEmpty(song.AudioUrl)) continue; songs.Add(song); } return songs; } }
protected override async Task<List<MatchSong>> InternalGetSongsAsync(string title, string artist, int limit = 10) { using (var response = await new Mp3GluSearchRequest(title.Append(artist)).ToResponseAsync().DontMarshall() ) { if (!response.HasData) return null; var songNodes = response.Data.DocumentNode.Descendants("div") .Where(p => p.Attributes["class"]?.Value.Contains("result_list") ?? false).Take(limit); var songs = new List<MatchSong>(); foreach (var songNode in songNodes) { var song = new MatchSong(); var detailsNode = songNode.Descendants("em").FirstOrDefault(); var duration = detailsNode.InnerText.Substring(0, detailsNode.InnerText.IndexOf("min ", StringComparison.Ordinal)); if (!string.IsNullOrEmpty(duration)) { duration = duration.Replace("Duration : ", "").Trim(); var seconds = int.Parse(duration.Substring(duration.Length - 2, 2)); var minutes = int.Parse(duration.Remove(duration.Length - 3)); song.Duration = new TimeSpan(0, 0, minutes, seconds); } var songTitle = songNode.Descendants("strong").FirstOrDefault()?.InnerText; if (string.IsNullOrEmpty(songTitle)) continue; song.SetNameAndArtistFromTitle(WebUtility.HtmlDecode(songTitle.Substring(0, songTitle.Length - 4)).Trim(), true); var linkNode = songNode.Descendants("a") .FirstOrDefault(); song.AudioUrl = linkNode?.Attributes["href"]?.Value; if (string.IsNullOrEmpty(song.AudioUrl)) continue; songs.Add(song); } return songs; } }
protected override async Task<List<MatchSong>> InternalGetSongsAsync(string title, string artist, int limit = 10) { using (var response = await new Mp3MinerSearchRequest("mp3songs", title.Append(artist)).ToResponseAsync()) { if (!response.HasData) return null; var songNodes = response.Data.DocumentNode.Descendants("a") .Where(p => p.Attributes.Contains("href") && p.Attributes["href"].Value.Contains("ref=search")) .Take(limit); var songs = new List<MatchSong>(); foreach (var songNode in songNodes) { using (var InnerResponse = await new Mp3MinerSearchRequest("mp3", songNode.Attributes["href"].Value.Substring(5)).ToResponseAsync()) { if (!InnerResponse.HasData) { return null; } var songUrl = InnerResponse.Data.DocumentNode.Descendants("audio") .Where(p => p.Attributes.Contains("src")) .FirstOrDefault(); if(songUrl == null) { break; } var innerSongNode = InnerResponse.Data.DocumentNode.Descendants("div") .Where(p => p.Attributes.Contains("class") && p.Attributes["class"].Value.Contains("mdl-card__title")) .FirstOrDefault(); if(innerSongNode == null) { break; } var song = new MatchSong { Id = Regex.Match(songNode.Attributes["href"].Value, "/mp3/(.*?)-").Groups[1].ToString(), AudioUrl = songUrl.Attributes["src"]?.Value }; if (string.IsNullOrEmpty(song.AudioUrl)) continue; var titleText = innerSongNode.Descendants("h2") .FirstOrDefault(p => p.Attributes["class"]?.Value == "mdl-card__title-text")?.InnerText; if (string.IsNullOrEmpty(titleText)) continue; song.Title = WebUtility.HtmlDecode(titleText); var artistText = innerSongNode.Descendants("h3") .FirstOrDefault().ChildNodes.FirstOrDefault(c => c.Attributes.Contains("href"))?.InnerText; if (string.IsNullOrEmpty(artistText)) continue; song.Artist = WebUtility.HtmlDecode(artistText); var durationText = InnerResponse.Data.DocumentNode.Descendants("div") .FirstOrDefault(p => p.Attributes["class"]?.Value == "info-section stretchable")?.InnerText; durationText = durationText.Substring(durationText.IndexOf("/") + 1).Trim(); TimeSpan duration; if (TimeSpan.TryParse("00:" + durationText, out duration)) { song.Duration = duration; } songs.Add(song); } } return songs; } }
private async Task<bool> CheckAudioSizeAsync(MatchSong matchSong) { using (var response = await matchSong.AudioUrl.ToUri().HeadAsync()) { if (response == null || !response.IsSuccessStatusCode) return false; var type = response.Content.Headers.ContentType?.MediaType ?? response.Content.Headers.GetValues("Content-Type")?.FirstOrDefault() ?? ""; if (!type.Contains("audio") && !type.Contains("octet-stream")) return false; var size = response.Content.Headers.ContentLength; if (size != null) { matchSong.ByteSize = (long) size; } return matchSong.ByteSize > 0; } }