Esempio n. 1
0
        private static async Task <List <WebSong> > SearchMeileAsync(string title, string artist, int limit, bool checkAllLinks)
        {
            using (var response = await new MeileSearchRequest(title.Append(artist))
                                  .Limit(limit).ToResponseAsync().DontMarshall())
            {
                if (!response.HasData)
                {
                    return(null);
                }
                var htmlDocument = response.Data;

                // Get the hyperlink node with the class='name'
                var songNameNodes =
                    htmlDocument.DocumentNode.Descendants("a")
                    .Where(p => p.Attributes.Contains("class") && p.Attributes["class"].Value == "name");

                // in it there is an attribute that contains the url to the song
                var songUrls = songNameNodes.Select(p => p.Attributes["href"].Value);
                var songIds  = songUrls.Where(p => p.Contains("/song/")).ToList();

                var songs = new List <WebSong>();

                foreach (var songId in songIds)
                {
                    var song = await GetMeileDetailsAsync(songId.Replace("/song/", string.Empty)).DontMarshall();

                    if (song != null)
                    {
                        songs.Add(new WebSong(song));
                    }
                }

                return(songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, false) : null);
            }
        }
Esempio n. 2
0
        private static async Task <List <WebSong> > SearchNeteaseAsync(string title, string artist, int limit, bool checkAllLinks)
        {
            using (
                var response =
                    await new NeteaseSearchRequest(title.Append(artist)).ToResponseAsync().ConfigureAwait(false))
            {
                var neteaseSongs = response.Data?.Result?.Songs?.Take(limit);
                if (neteaseSongs == null)
                {
                    return(null);
                }

                var songs = new List <WebSong>();

                foreach (var neteaseSong in neteaseSongs)
                {
                    using (
                        var detailsResponse =
                            await new NeteaseDetailsRequest(neteaseSong.Id).ToResponseAsync().ConfigureAwait(false))
                    {
                        var song = detailsResponse.Data?.Songs?.FirstOrDefault();
                        if (song != null)
                        {
                            song.ProviderNumber = 11;
                            songs.Add(new WebSong(song));
                        }
                    }
                }

                return(songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, false) : null);
            }
        }
Esempio n. 3
0
        private static async Task <List <WebSong> > SearchMp3ClanAsync(string title, string artist, int limit, bool checkAllLinks)
        {
            // mp3clan search doesn't work that well with the pound key (even encoded)
            var url = string.Format(
                Mp3ClanSearchUrl,
                IdentfyMatchTrack.CreateQuery(title.Contains("#") ? title.Replace("#", string.Empty) : title, artist),
                limit);

            using (var client = new HttpClient())
            {
                using (var resp = await client.GetAsync(url).ConfigureAwait(false))
                {
                    var json = await resp.Content.ReadAsStringAsync().ConfigureAwait(false);

                    var parseResp = await json.DeserializeAsync <Mp3ClanRoot>().ConfigureAwait(false);

                    if (parseResp == null || parseResp.response == null || !resp.IsSuccessStatusCode)
                    {
                        return(null);
                    }

                    return
                        (await
                         IdentfyMatchTrack.IdentifyMatches(parseResp.response.Select(p => new WebSong(p)).ToList(), title, artist,
                                                           checkAllLinks));
                }
            }
        }
Esempio n. 4
0
        private static async Task <List <WebSong> > SearchSoundCloudAsync(string title, string artist, int limit)
        {
            var url = string.Format(
                SoundCloudSearchUrl,
                ApiKeys.SoundCloudId,
                limit,
                IdentfyMatchTrack.CreateQuery(title, artist));

            using (var client = new HttpClient())
            {
                using (var resp = await client.GetAsync(url))
                {
                    var json = await resp.Content.ReadAsStringAsync().ConfigureAwait(false);

                    var parseResp = await json.DeserializeAsync <SoundCloudRoot>().ConfigureAwait(false);

                    if (parseResp == null || parseResp.Collection == null || !resp.IsSuccessStatusCode)
                    {
                        return(null);
                    }


                    parseResp.Collection.RemoveAll(p => p.StreamUrl == null);

                    foreach (var song in parseResp.Collection)
                    {
                        if (song.StreamUrl.Contains("soundcloud") && !song.StreamUrl.Contains("client_id"))
                        {
                            song.StreamUrl += "?client_id=" + ApiKeys.SoundCloudId;
                        }

                        if (string.IsNullOrEmpty(song.ArtworkUrl))
                        {
                            song.ArtworkUrl = song.User.AvatarUrl;
                        }

                        if (song.ArtworkUrl.IndexOf('?') > -1)
                        {
                            song.ArtworkUrl = song.ArtworkUrl.Remove(song.ArtworkUrl.LastIndexOf('?'));
                        }
                        song.ProviderNumber = 8;
                        song.ArtworkUrl     = song.ArtworkUrl.Replace("large", "t500x500");
                    }

                    return(await
                           IdentfyMatchTrack.IdentifyMatches(parseResp.Collection.Select(p => new WebSong(p)).ToList(), title, artist, false));
                }
            }
        }
Esempio n. 5
0
        private static async Task <List <WebSong> > SearchSongilyAsync(string title, string artist, int page, bool checkAllLinks)
        {
            var url = string.Format(SongilySearchUrl, WebUtility.UrlEncode(IdentfyMatchTrack.CreateQuery(title, artist, false).ToCleanQuery()), page);

            using (var client = new HttpClient())
            {
                using (var resp = await client.GetAsync(url).ConfigureAwait(false))
                {
                    if (!resp.IsSuccessStatusCode)
                    {
                        return(null);
                    }

                    var html = await resp.Content.ReadAsStringAsync().ConfigureAwait(false);

                    var doc = new HtmlDocument();
                    doc.LoadHtml(html);

                    // Get the div node with the class='actl'
                    var songNodes =
                        doc.DocumentNode.Descendants("li")
                        .Where(
                            p => p.Attributes.Contains("class") && p.Attributes["class"].Value.Contains("list-group-item"));

                    var songs = new List <WebSong>();

                    foreach (var songNode in songNodes)
                    {
                        var song = new WebSong {
                            Provider = Mp3Provider.Mp3Truck
                        };

                        try {
                            var detailNode = songNode.Descendants("small").FirstOrDefault();
                            if (detailNode != null)
                            {
                                var duration = detailNode.InnerText;

                                var durIndex = duration.IndexOf(":");
                                if (durIndex > 0)
                                {
                                    var seconds = int.Parse(duration.Substring(durIndex + 1, 2));
                                    var minutes = int.Parse(duration.Substring(0, durIndex));;
                                    song.Duration = new TimeSpan(0, 0, minutes, seconds);
                                }
                            }
                        }
                        catch (Exception)
                        {
                            song.Duration = new TimeSpan(0, 4, 0);
                        }
                        var songTitle =
                            songNode.Descendants("span")
                            .FirstOrDefault();

                        if (songTitle == null)
                        {
                            continue;
                        }

                        song.Name = WebUtility.HtmlDecode(songTitle.InnerText).Trim();

                        var linkNode =
                            songNode.Descendants("a")
                            .FirstOrDefault(
                                p =>
                                p.Attributes.Contains("title") &&
                                p.Attributes["title"].Value.Contains("Download"));
                        if (linkNode == null)
                        {
                            continue;
                        }

                        song.AudioUrl       = "http://songily.com/" + linkNode.Attributes["href"].Value;
                        song.ProviderNumber = 2;
                        songs.Add(song);
                    }

                    return(songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, checkAllLinks) : null);
                }
            }
        }
Esempio n. 6
0
        private static async Task <List <WebSong> > SearchMp3GluAsync(string title, string artist, int limit)
        {
            using (var response = await new Mp3GluSearchRequest(title.Append(artist)).ToResponseAsync())
            {
                if (!response.HasData)
                {
                    return(null);
                }

                var songNodes1 =
                    response.Data.DocumentNode.Descendants("div");

                var songNodes =
                    songNodes1.Where(p => p.Attributes["class"]?.Value.Contains("result_list") ?? false).Take(limit);

                var songs = new List <WebSong>();

                foreach (var songNode in songNodes)
                {
                    var song = new WebSong();

                    var detailsNode = songNode.Descendants("em").FirstOrDefault();

                    try
                    {
                        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);
                        }
                    }

                    catch (Exception)
                    {
                        song.Duration = new TimeSpan(0, 4, 0);
                    }

                    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;
                    }
                    song.ProviderNumber = 14;
                    songs.Add(song);
                }

                return(songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, false) : null);
            }
        }
Esempio n. 7
0
        private static async Task <List <WebSong> > SearchAnyMazaAync(string title, string artist, int limit)
        {
            using (var resp = await new AnyMazaSearchRequest(title.Append(artist)).ToResponseAsync())
            {
                if (!resp.HasData)
                {
                    return(null);
                }

                var songs = new List <WebSong>();

                foreach (var googleResult in resp.Data.ResponseData.Results)
                {
                    var song = new WebSong();

                    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))
                        {
                            try
                            {
                                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;
                                }
                            }
                            catch
                            {
                                song.Duration = new TimeSpan(0, 4, 0);
                            }
                        }

                        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;
                        }
                    }
                    song.ProviderNumber = 9;
                    songs.Add(song);
                }

                return(songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, false) : null);
            }
        }
Esempio n. 8
0
        private static async Task <List <WebSong> > SearchMiMp3Aync(string title, string artist, int limit)
        {
            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 <WebSong>();

                foreach (var songNode in songNodes)
                {
                    var song = new WebSong();

                    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.Name = 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))
                    {
                        try
                        {
                            var      duration = meta.Substring(10, meta.IndexOf(" ", StringComparison.Ordinal) - 10).Trim();
                            TimeSpan parsed;
                            if (TimeSpan.TryParse("00:" + duration, out parsed))
                            {
                                song.Duration = parsed;
                            }
                        }
                        catch
                        {
                            song.Duration = new TimeSpan(0, 4, 0);  //ignored
                        }
                    }

                    var linkNode =
                        songNode.Descendants("a").FirstOrDefault(p => p.Attributes["class"]?.Value == "play_button");
                    if (linkNode == null)
                    {
                        continue;
                    }

                    song.AudioUrl = linkNode.Attributes["href"]?.Value;

                    if (string.IsNullOrEmpty(song.AudioUrl))
                    {
                        continue;
                    }
                    song.AudioUrl = await GetMiMp3AudioUrlAsync(song.AudioUrl);

                    if (string.IsNullOrEmpty(song.AudioUrl))
                    {
                        continue;
                    }

                    song.ProviderNumber = 10;
                    songs.Add(song);
                }
                songs.Take(limit).ToList();
                return(songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, false) : null);
            }
        }
Esempio n. 9
0
        private static async Task <List <WebSong> > SearchMp3FreexAsync(string title, string artist, int limit)
        {
            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 <WebSong>();

                foreach (var songNode in songNodes)
                {
                    var song = new WebSong();

                    var songTitle =
                        songNode.Descendants("span")
                        .FirstOrDefault(p => p.Attributes["class"]?.Value == "res_title")?
                        .InnerText;
                    if (string.IsNullOrEmpty(songTitle))
                    {
                        continue;
                    }
                    song.SetNameAndArtistFromTitle(songTitle, true);

                    var meta =
                        songNode.Descendants("span")
                        .FirstOrDefault(p => p.Attributes["class"]?.Value == "label label-info")?
                        .InnerText;

                    if (!string.IsNullOrEmpty(meta))
                    {
                        try
                        {
                            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);
                        }
                        catch
                        {
                            song.Duration = new TimeSpan(0, 4, 0);
                        }
                    }

                    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;
                    }
                    song.ProviderNumber = 3;
                    songs.Add(song);
                }

                return(songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, false) : null);
            }
        }
Esempio n. 10
0
        private static async Task <List <WebSong> > SearchMp3TruckAsync(string title, string artist,
                                                                        bool checkAllLinks)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Referrer = new Uri("https://mp3truck.net/");
                var data = new Dictionary <string, string>
                {
                    { "sort", "relevance" },
                    { "p", "1" },
                    { "q", IdentfyMatchTrack.CreateQuery(title, artist) }
                };

                using (var content = new FormUrlEncodedContent(data))
                {
                    using (var resp = await client.PostAsync(Mp3TruckSearchUrl, content).ConfigureAwait(false))
                    {
                        if (!resp.IsSuccessStatusCode)
                        {
                            return(null);
                        }

                        var html = await resp.Content.ReadAsStringAsync().ConfigureAwait(false);

                        var doc = new HtmlDocument();
                        doc.LoadHtml(html);

                        // Get the div node with the class='actl'
                        var songNodes =
                            doc.DocumentNode.Descendants("div")
                            .Where(
                                p => p.Attributes.Contains("class") && p.Attributes["class"].Value.Contains("actl"));

                        var songs = new List <WebSong>();

                        foreach (var songNode in songNodes)
                        {
                            var song = new WebSong {
                                Provider = Mp3Provider.Mp3Truck
                            };

                            if (songNode.Attributes.Contains("data-id"))
                            {
                                song.Id = songNode.Attributes["data-id"].Value;
                            }

                            if (songNode.Attributes.Contains("data-bitrate"))
                            {
                                song.BitRate = int.Parse(songNode.Attributes["data-bitrate"].Value);
                            }

                            if (songNode.Attributes.Contains("data-filesize"))
                            {
                                song.ByteSize = (int)double.Parse(songNode.Attributes["data-filesize"].Value);
                            }

                            if (songNode.Attributes.Contains("data-duration"))
                            {
                                var duration = songNode.Attributes["data-duration"].Value;

                                if (duration.Contains(":"))
                                {
                                    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);
                                }
                                else
                                {
                                    song.Duration = new TimeSpan(0, 0, 0, int.Parse(duration));
                                }
                            }

                            var songTitle =
                                songNode.Descendants("div")
                                .FirstOrDefault(
                                    p => p.Attributes.Contains("id") && p.Attributes["id"].Value == "title")
                                .InnerText;
                            songTitle = WebUtility.HtmlDecode(songTitle.Substring(0, songTitle.Length - 4)).Trim();

                            // artist - title
                            var dashIndex = songTitle.IndexOf('-');
                            if (dashIndex != -1)
                            {
                                var titlePart = songTitle.Substring(dashIndex, songTitle.Length - dashIndex);
                                song.Artist = songTitle.Replace(titlePart, string.Empty).Trim();

                                songTitle = titlePart.Remove(0, 1).Trim();
                            }

                            song.Name = songTitle;

                            var linkNode =
                                songNode.Descendants("a")
                                .FirstOrDefault(
                                    p =>
                                    p.Attributes.Contains("class") &&
                                    p.Attributes["class"].Value.Contains("mp3download"));
                            if (linkNode == null)
                            {
                                continue;
                            }

                            song.AudioUrl       = linkNode.Attributes["href"].Value.Replace("/idl.php?u=", string.Empty);
                            song.ProviderNumber = 13;
                            songs.Add(song);
                        }

                        return(songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, checkAllLinks) : null);
                    }
                }
            }
        }
Esempio n. 11
0
        private static async Task <List <WebSong> > SearchMp3PmAsync(string title, string artist, int limit)
        {
            // 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 <WebSong>();

                foreach (var songNode in songNodes)
                {
                    var song = new WebSong
                    {
                        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.Name = 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);

                    try
                    {
                        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;
                        }
                    }
                    catch
                    {
                        song.Duration = new TimeSpan(0, 0, 4, 0);
                    }
                    song.ProviderNumber = 5;
                    songs.Add(song);
                }
                return(songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, false) : null);
            }
        }
Esempio n. 12
0
        //private static async Task<List<WebSong>> SearchPleerAsync(string title, string artist, int limit)
        //{
        //    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<WebSong>();

        //        foreach (var songNode in songNodes)
        //        {
        //            var song = new WebSong
        //            {
        //                Id = songNode.Attributes["file_id"].Value,
        //                Name = songNode.Attributes["song"].Value,
        //                Artist = songNode.Attributes["singer"].Value
        //            };


        //            try
        //            {
        //                int seconds;
        //                if (int.TryParse(songNode.Attributes["duration"].Value, out seconds))
        //                {
        //                    song.Duration = TimeSpan.FromSeconds(seconds);
        //                }
        //            }
        //            catch (Exception)
        //            {
        //                song.Duration = new TimeSpan(0, 4, 0);
        //            }

        //            var linkId = songNode.Attributes["link"].Value;
        //            song.AudioUrl = await GetPleerLinkAsync(linkId);

        //            if (string.IsNullOrEmpty(song.AudioUrl)) continue;
        //            song.ProviderNumber = 1;
        //            songs.Add(song);
        //        }

        //        return songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, false) : null;
        //    }
        //}

        //private static async Task<string> GetPleerLinkAsync(string id)
        //{
        //    using (var response = await new PleerDetailsRequest(id).ToResponseAsync().DontMarshall())
        //    {
        //        return response.Data?.Value<string>("track_link");
        //    }
        //}



        private static async Task <List <WebSong> > SearchPleerAsync(string title, string artist, int limit)
        {
            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 <WebSong>();

                foreach (var songNode in songNodes)
                {
                    var song = new WebSong
                    {
                        Id     = songNode.Attributes["file_id"].Value,
                        Name   = 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;
                    }
                    try
                    {
                        int seconds;
                        if (int.TryParse(songNode.Attributes["duration"].Value, out seconds))
                        {
                            song.Duration = TimeSpan.FromSeconds(seconds);
                        }
                    }
                    catch (Exception)
                    {
                        song.Duration = new TimeSpan(0, 4, 0);
                    }

                    var linkId = songNode.Attributes["link"].Value;
                    song.AudioUrl = await GetPleerLinkAsync(linkId);

                    if (string.IsNullOrEmpty(song.AudioUrl))
                    {
                        continue;
                    }
                    song.ProviderNumber = 1;
                    songs.Add(song);
                }

                return(songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, false) : null);
            }
        }
Esempio n. 13
0
        private static async Task <List <WebSong> > SearchYoutubeAsync(string title, string artist, int limit, bool includeAudioTag)
        {
            YouTubeService youtubeService;

            youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = ApiKeys.YouTubeIdMusicus,
                ApplicationName = "Musicus1" //"Musicus1"
            });


            var searchListRequest = youtubeService.Search.List("snippet");

            searchListRequest.Q          = IdentfyMatchTrack.CreateQuery(title, artist, false) + (includeAudioTag ? " (Audio)" : "");
            searchListRequest.MaxResults = limit;
            searchListRequest.SafeSearch = SearchResource.ListRequest.SafeSearchEnum.None;

            try
            {
                SearchListResponse searchListResponse;
                try
                {
                    // Call the search.list method to retrieve results matching the specified query term.
                    searchListResponse = await searchListRequest.ExecuteAsync();
                }

                catch
                {
                    youtubeService = new YouTubeService(new BaseClientService.Initializer()
                    {
                        ApiKey          = ApiKeys.YoutubeId,
                        ApplicationName = "Airstem" //"Musicus1"
                    });

                    var o = youtubeService.Search.List("snippet");
                    o.Q                = IdentfyMatchTrack.CreateQuery(title, artist, false) + (includeAudioTag ? " (Audio)" : "");
                    o.MaxResults       = limit;
                    searchListResponse = await o.ExecuteAsync();

                    if (o != null)
                    {
                        o = null;
                    }
                }

                if (searchListRequest != null)
                {
                    searchListRequest = null;
                }

                List <WebSong> songs = new List <WebSong>();

                foreach (var vid in from searchResult in searchListResponse.Items
                         where searchResult.Id.Kind == "youtube#video"
                         select new WebSong(searchResult))
                {
                    try
                    {
                        vid.AudioUrl = GetYoutubeUrlAsync(vid.Id);
                    }
                    catch
                    {
                        // ignored
                    }

                    if (string.IsNullOrEmpty(vid.AudioUrl))
                    {
                        continue;
                    }

                    vid.ProviderNumber = 6;
                    songs.Add(vid);
                }

                var results = await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, false);

                // try redoing the search without "(audio)"
                if (!results.Any(p => p.IsMatch) && includeAudioTag)
                {
                    return(await SearchYoutube(title, artist, limit, false));
                }

                return(results);
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 14
0
        //get mp3skull
        public async Task <List <WebSong> > SearchMp3Skull(string title, string artist,
                                                           bool checkAllLinks = false)
        {
            using (var client = new HttpClient())
            {
                var url = string.Format(Mp3SkullSearchUrl, IdentfyMatchTrack.CreateQuery(title, artist), Mp3SkullFckh);
                using (var resp = await client.GetAsync(url).ConfigureAwait(false))
                {
                    if (!resp.IsSuccessStatusCode)
                    {
                        return(null);
                    }

                    var html = await resp.Content.ReadAsStringAsync().ConfigureAwait(false);

                    var doc = new HtmlDocument();
                    doc.LoadHtml(html);

                    if (html.Contains("You have made too many request"))
                    {
                        return(null);
                    }

                    if (html.Contains("Your search session has expired"))
                    {
                        var fckhNode =
                            doc.DocumentNode.Descendants("input")
                            .FirstOrDefault(
                                p => p.Attributes.Contains("name") && p.Attributes["name"].Value == "fckh");
                        if (fckhNode == null)
                        {
                            return(null);
                        }

                        Mp3SkullFckh = fckhNode.Attributes["value"].Value;

                        return(await SearchMp3Skull(title, artist));
                    }

                    // Get the div node
                    var songNodes = doc.DocumentNode.Descendants("div").Where(p => p.Id == "song_html");

                    var songs = new List <WebSong>();

                    foreach (var songNode in songNodes)
                    {
                        var song = new WebSong(); //{ Provider = Mp3Provider.Mp3Skull };

                        var songUrlNode = songNode.Descendants("a").FirstOrDefault(p => p.InnerText == "Download");

                        if (songUrlNode == null)
                        {
                            continue;
                        }

                        song.AudioUrl = songUrlNode.Attributes["href"].Value;
                        var songInfo =
                            songNode.Descendants("div")
                            .FirstOrDefault(p => p.Attributes["class"].Value == "left")
                            .InnerText.Replace("<!-- info mp3 here -->", string.Empty)
                            .Trim();


                        var bitRateIndex = songInfo.IndexOf("kbps", StringComparison.Ordinal);
                        if (bitRateIndex > -1)
                        {
                            var bitrateTxt = songInfo.Substring(0, bitRateIndex);
                            int bitrate;
                            if (int.TryParse(bitrateTxt, out bitrate))
                            {
                                song.BitRate = bitrate;
                            }
                        }

                        #region Duration

                        if (bitRateIndex > -1)
                        {
                            songInfo = songInfo.Remove(0, bitRateIndex + 4);
                        }

                        var durationIndex = songInfo.IndexOf(":", StringComparison.Ordinal);
                        if (durationIndex > -1)
                        {
                            var durationText = songInfo.Substring(0, durationIndex + 3);
                            var seconds      = int.Parse(durationText.Substring(durationText.Length - 2, 2));
                            var minutes      = int.Parse(durationText.Remove(durationText.Length - 3));

                            song.Duration = new TimeSpan(0, 0, minutes, seconds);
                        }

                        #endregion

                        #region Size

                        if (durationIndex > -1)
                        {
                            songInfo = songInfo.Remove(0, durationIndex + 3);
                        }

                        var sizeIndex = songInfo.IndexOf("mb", StringComparison.Ordinal);
                        if (sizeIndex > -1)
                        {
                            var  sizeText = songInfo.Substring(0, sizeIndex);
                            long size;
                            if (long.TryParse(sizeText, out size))
                            {
                                song.ByteSize = (long)(size * (1024 * 1024.0));
                            }
                        }

                        #endregion

                        var songTitle = songNode.Descendants("b").FirstOrDefault().InnerText;
                        songTitle = songTitle.Substring(0, songTitle.Length - 4).Trim();

                        song.Name = songTitle;
                        //song.ProviderNumber = 9;
                        songs.Add(song);
                    }

                    return(songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, checkAllLinks) : null);
                }
            }
        }
Esempio n. 15
0
        private static async Task <List <WebSong> > SearchMp3lioAync(string title, string artist, int limit)
        {
            using (var response = await new Mp3lioSearchRequest(title.Append(artist)).ToResponseAsync().DontMarshall())
            {
                if (!response.HasData)
                {
                    return(null);
                }

                var songNodes =
                    response.Data.DocumentNode.Descendants("div")
                    .Where(p => p.Attributes["class"]?.Value.Contains("item") ?? false).Take(limit);

                var songs = new List <WebSong>();

                foreach (var songNode in songNodes)
                {
                    var song = new WebSong();

                    var duration = songNode.Descendants("em").FirstOrDefault();
                    if (duration != null)
                    {
                        try
                        {
                            var text    = duration.InnerText.Replace("Duration: ", "").Replace(" min", "");
                            var seconds = int.Parse(text.Substring(text.Length - 2, 2));
                            var minutes = int.Parse(text.Remove(text.Length - 3));
                            song.Duration = new TimeSpan(0, 0, minutes, seconds);
                        }

                        catch (Exception)
                        {
                            song.Duration = new TimeSpan(0, 4, 0);
                        }
                    }

                    //http://c.mp3fly.in/get.php?id=z-diRlyLGzo&name=Channa+Mereya+-++Ae+Dil+Hai+Mushkil++Karan+Johar++Ranbir++Anushka++Aishwarya++Pritam++Arijit&hash=73429b2cf5cf826f4fc8d4071112f60a1361cc6b&expire=1479907845

                    var songTitle = songNode.Descendants("strong").FirstOrDefault()?.InnerText;
                    if (string.IsNullOrEmpty(songTitle))
                    {
                        continue;
                    }
                    song.Name = songTitle;


                    var linkNode = songNode.Descendants("a").FirstOrDefault();

                    if (linkNode?.Attributes["href"]?.Value != null)
                    {
                        var          webConnect = new HtmlWeb();
                        HtmlDocument _htmlDoc   = await webConnect.LoadFromWebAsync(linkNode?.Attributes["href"]?.Value);

                        var htmlNode = _htmlDoc.DocumentNode.Descendants("a");
                        foreach (HtmlNode node in htmlNode)
                        {
                            if (node.Attributes["href"]?.Value.Contains("http://c.mp3fly.in/") == true)
                            {
                                song.AudioUrl = node.Attributes["href"]?.Value;
                                break;
                            }
                        }
                        // song.AudioUrl = linkNode?.Attributes["href"]?.Value;
                    }

                    if (string.IsNullOrEmpty(song.AudioUrl))
                    {
                        continue;
                    }

                    song.ProviderNumber = 4;
                    songs.Add(song);
                }

                return(songs.Any() ? await IdentfyMatchTrack.IdentifyMatches(songs, title, artist, false) : null);
            }
        }