Skip to content

Commit

Permalink
Merge pull request #293 from zumicts/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
haroldma-zz committed Nov 24, 2015
2 parents c5d3839 + 88d11bd commit 944aa4b
Show file tree
Hide file tree
Showing 55 changed files with 5,047 additions and 3,930 deletions.
9 changes: 7 additions & 2 deletions Audiotica.Web/Audiotica.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@
<Compile Include="Extensions\RestRequestExtensions.cs" />
<Compile Include="Extensions\UriExtensions.cs" />
<Compile Include="Extensions\MatchSongExtensions.cs" />
<Compile Include="Http\Requets\MatchEngine\AnyMaza\AnyMazaSearchRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\AnyMaza\Model\GoogleSearchRoot.cs" />
<Compile Include="Http\Requets\MatchEngine\Meile\MeileDetailsRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\Meile\MeileSearchRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\MiMp3S\MiMp3SSearchRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\Mp3Freex\Mp3FreexSearchRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\Mp3Pm\Mp3PmSearchRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\Mp3Skull\Mp3SkullRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\Mp3lio\Mp3lioSearchRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\Mp3Truck\Mp3TruckSearchRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\Mp3Truck\Mp3GluSearchRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\Netease\NeteaseDetailsRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\Netease\NeteaseSearchRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\Pleer\PleerDetailsRequest.cs" />
Expand Down Expand Up @@ -103,6 +106,8 @@
<Compile Include="Http\Requets\RestObjectRequest.cs" />
<Compile Include="Http\Requets\MatchEngine\SoundCloud\SoundCloudSearchRequest.cs" />
<Compile Include="IConfigurableProvider.cs" />
<Compile Include="MatchEngine\Providers\AnyMazaMatchProvider.cs" />
<Compile Include="MatchEngine\Providers\MiMp3SMatchProvider.cs" />
<Compile Include="MatchEngine\Providers\Mp3FreexMatchProvider.cs" />
<Compile Include="MatchEngine\Providers\Mp3lioMatchProvider.cs" />
<Compile Include="MatchEngine\Providers\Mp3PmProvider.cs" />
Expand All @@ -113,7 +118,7 @@
<Compile Include="MatchEngine\Interfaces\Validators\ISongTypeValidator.cs" />
<Compile Include="MatchEngine\Providers\MeileMatchProvider.cs" />
<Compile Include="MatchEngine\Providers\Mp3SkullMatchProvider.cs" />
<Compile Include="MatchEngine\Providers\Mp3TruckMatchProvider.cs" />
<Compile Include="MatchEngine\Providers\Mp3GluMatchProvider.cs" />
<Compile Include="MatchEngine\Providers\NeteaseMatchProvider.cs" />
<Compile Include="MatchEngine\Providers\PleerMatchProvider.cs" />
<Compile Include="MatchEngine\Providers\MatchProviderBase.cs" />
Expand Down
8 changes: 7 additions & 1 deletion Audiotica.Web/Extensions/MatchSongExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using Audiotica.Web.Models;

Expand Down Expand Up @@ -27,7 +28,12 @@ public static void SetNameAndArtistFromTitle(this MatchSong song, string title,
var left = titleSplit[0];
var right = string.Join($" {seperator} ", titleSplit.Skip(1));

if (artistOnLeft)

if (string.IsNullOrEmpty(right))
{
song.Title = left;
}
else if (artistOnLeft)
{
song.Artist = left;
song.Title = right;
Expand Down
1 change: 1 addition & 0 deletions Audiotica.Web/Extensions/UriExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static async Task<HtmlDocument> ParseHtmlAsync(this HttpResponseMessage r
var doc = new HtmlDocument();

var html = await response.Content.ReadAsStringAsync().DontMarshall();

doc.LoadHtml(html);

return doc;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Audiotica.Web.Extensions;
using Audiotica.Web.Http.Requets.MatchEngine.AnyMaza.Model;

namespace Audiotica.Web.Http.Requets.MatchEngine.AnyMaza
{
internal class AnyMazaSearchRequest : RestObjectRequest<GoogleSearchRoot>
{
public AnyMazaSearchRequest(string query)
{
this.Url("https://ajax.googleapis.com/ajax/services/search/web")
.QParam("q", query + " site:AnyMaza.com").QParam("v", "1.0");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;

namespace Audiotica.Web.Http.Requets.MatchEngine.AnyMaza.Model
{
public class GoogleResult
{
public string GsearchResultClass { get; set; }
public string UnescapedUrl { get; set; }
public string Url { get; set; }
public string VisibleUrl { get; set; }
public string CacheUrl { get; set; }
public string Title { get; set; }
public string TitleNoFormatting { get; set; }
public string Content { get; set; }
}

public class GooglePage
{
public string Start { get; set; }
public int Label { get; set; }
}

public class GoogleCursor
{
public string ResultCount { get; set; }
public List<GooglePage> Pages { get; set; }
public string EstimatedResultCount { get; set; }
public int CurrentPageIndex { get; set; }
public string MoreResultsUrl { get; set; }
public string SearchResultTime { get; set; }
}

public class GoogleSearchResponseData
{
public List<GoogleResult> Results { get; set; }
public GoogleCursor Cursor { get; set; }
}

public class GoogleSearchRoot
{
public GoogleSearchResponseData ResponseData { get; set; }
public object ResponseDetails { get; set; }
public int ResponseStatus { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Audiotica.Web.Extensions;
using HtmlAgilityPack;

namespace Audiotica.Web.Http.Requets.MatchEngine.MiMp3S
{
public class MiMp3SSearchRequest : RestObjectRequest<HtmlDocument>
{
public MiMp3SSearchRequest(string query)
{
this.Url("http://www.mimp3s.com/{query}-mp3.html").UrlParam("query", query.Replace(" ", "-"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Mp3FreexSearchRequest : RestObjectRequest<HtmlDocument>
{
public Mp3FreexSearchRequest(string query)
{
this.Url("http://mp3freex.com/{query}-download").UrlParam("query", query.Replace(" ", "-")).Get();
this.Url("http://mp3freex.net/").QParam("inmp3", query).Get();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Mp3PmSearchRequest : RestObjectRequest<HtmlDocument>
{
public Mp3PmSearchRequest(string query)
{
this.Url("http://mp3pm.com/s/f/{query}/").UrlParam("query", query).Get();
this.Url("http://mp3pm.info/s/f/{query}/").UrlParam("query", query).Get();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Audiotica.Web.Extensions;
using HtmlAgilityPack;

namespace Audiotica.Web.Http.Requets.MatchEngine.Mp3Truck
{
public class Mp3GluSearchRequest : RestObjectRequest<HtmlDocument>
{
public Mp3GluSearchRequest(string query)
{
this.Url("http://mp3glu.com/search.php")
.QParam("q", query)
.Post();
}
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion Audiotica.Web/MatchEngine/Interfaces/IMatchProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace Audiotica.Web.MatchEngine.Interfaces
public interface IMatchProvider : IConfigurableProvider
{
Task<Uri> GetLinkAsync(string title, string artist);
Task<List<MatchSong>> GetSongsAsync(string title, string artist, int limit = 10);
Task<List<MatchSong>> GetSongsAsync(string title, string artist, int limit = 10, bool verifyMatchesOnly = true);
}
}
82 changes: 82 additions & 0 deletions Audiotica.Web/MatchEngine/Providers/AnyMazaMatchProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Audiotica.Core.Extensions;
using Audiotica.Core.Utilities.Interfaces;
using Audiotica.Web.Enums;
using Audiotica.Web.Extensions;
using Audiotica.Web.Http.Requets.MatchEngine.AnyMaza;
using Audiotica.Web.MatchEngine.Interfaces.Validators;
using Audiotica.Web.Models;
using HtmlAgilityPack;

namespace Audiotica.Web.MatchEngine.Providers
{
public class AnyMazaMatchProvider : MatchProviderBase
{
public AnyMazaMatchProvider(IEnumerable<ISongTypeValidator> validators, ISettingsUtility settingsUtility)
: base(validators, settingsUtility)
{
}

public override string DisplayName => "AnyMaza.Com";

public override ProviderSpeed Speed => ProviderSpeed.Fast;
public override ProviderResultsQuality ResultsQuality => ProviderResultsQuality.Excellent;

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;
}
}
}
}
6 changes: 3 additions & 3 deletions Audiotica.Web/MatchEngine/Providers/MatchProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public async Task<Uri> GetLinkAsync(string title, string artist)

return Uri.IsWellFormedUriString(uriString, UriKind.Absolute) ? new Uri(uriString, UriKind.Absolute) : null;
}

public async Task<List<MatchSong>> GetSongsAsync(string title, string artist,
int limit = 10)
int limit = 10, bool verifyMatchesOnly = true)
{
return
await
VerifyMatchesAsync(title, artist, await InternalGetSongsAsync(title, artist, limit).DontMarshall())
VerifyMatchesAsync(title, artist, await InternalGetSongsAsync(title, artist, limit).DontMarshall(), verifyMatchesOnly)
.DontMarshall();
}

Expand Down
2 changes: 1 addition & 1 deletion Audiotica.Web/MatchEngine/Providers/MeileMatchProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public MeileMatchProvider(IEnumerable<ISongTypeValidator> validators, ISettingsU
}

public override string DisplayName => "Meile";
public override ProviderSpeed Speed => ProviderSpeed.Slow;
public override ProviderSpeed Speed => ProviderSpeed.SuperSlow;
public override ProviderResultsQuality ResultsQuality => ProviderResultsQuality.Great;

protected override async Task<List<MatchSong>> InternalGetSongsAsync(string title, string artist, int limit = 10)
Expand Down
Loading

0 comments on commit 944aa4b

Please sign in to comment.