Skip to content

Commit e5b8709

Browse files
committed
added a new SubEchoNest project to replace the usage of SubLastFm in obtaining artist info
1 parent bb0e674 commit e5b8709

38 files changed

+1152
-1
lines changed

Client/App.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Client.Common.Services;
66
using global::Common;
77
using MugenInjection;
8+
using SubEchoNest;
89
using SubLastFm;
910
using Subsonic8.Framework;
1011
using Subsonic8.Shell;
@@ -39,6 +40,7 @@ protected override void Configure()
3940
Kernel.Load<CommonModule>();
4041
Kernel.Load<SubsonicCommonModule>();
4142
Kernel.Load<SubLastFmModule>();
43+
Kernel.Load<SubEchoNestModule>();
4244
Kernel.Load<ClientModule>();
4345
}
4446

Client/Client.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
<Compile Include="Framework\Extensions\NotificationExtensions.cs" />
188188
<Compile Include="Framework\Interfaces\ISettingsHelper.cs" />
189189
<Compile Include="Framework\Extensions\SettingsPaneExtensionMethods.cs" />
190+
<Compile Include="Framework\Services\EchoNestConfigurationProvider.cs" />
190191
<Compile Include="Framework\Services\IDialogService.cs" />
191192
<Compile Include="Framework\Services\IIoCService.cs" />
192193
<Compile Include="Framework\Services\IoCService.cs" />
@@ -570,6 +571,10 @@
570571
<Project>{11d7fb8c-1a2c-4d5b-b129-937d76468a78}</Project>
571572
<Name>Common</Name>
572573
</ProjectReference>
574+
<ProjectReference Include="..\SubEchoNest\SubEchoNest.csproj">
575+
<Project>{431f874c-ede9-4255-906b-1b3d4d460ad3}</Project>
576+
<Name>SubEchoNest</Name>
577+
</ProjectReference>
573578
<ProjectReference Include="..\SubLastFm\SubLastFm.csproj">
574579
<Project>{4485a175-2491-40dd-a683-9ccf21267c45}</Project>
575580
<Name>SubLastFm</Name>

Client/ClientModule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ protected override void PrepareForLoad()
3535
Singletons.Add<ISettingsHelper, SettingsHelper>();
3636
Singletons.Add<INotificationsHelper, NotificationsHelper>();
3737
Singletons.Add<IConfigurationProvider, LastFmConfigurationProvider>();
38+
Singletons.Add<SubEchoNest.IConfigurationProvider, EchoNestConfigurationProvider>();
3839
}
3940

4041
#endregion

SubEchoNest/Configuration.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace SubEchoNest
2+
{
3+
public class Configuration : IConfiguration
4+
{
5+
public string BaseUrl { get; set; }
6+
7+
public string ApiKey { get; set; }
8+
9+
public string RequestFormatWithApiKey
10+
{
11+
get
12+
{
13+
return "{0}/{2}?api_key={1}&format=xml";
14+
}
15+
}
16+
}
17+
}

SubEchoNest/EchoNestService.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace SubEchoNest
2+
{
3+
using SubEchoNest.Results;
4+
5+
public class EchoNestService : IEchoNestService
6+
{
7+
private readonly IConfiguration _configuration;
8+
9+
public EchoNestService(IConfigurationProvider configurationProvider)
10+
{
11+
_configuration = configurationProvider.Configuration;
12+
}
13+
14+
public virtual IGetBiographiesResult GetArtistBiographies(string artistName)
15+
{
16+
return new GetBiographiesResult(_configuration, artistName);
17+
}
18+
}
19+
}

SubEchoNest/IConfiguration.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace SubEchoNest
2+
{
3+
public interface IConfiguration
4+
{
5+
string ApiKey { get; set; }
6+
7+
string BaseUrl { get; set; }
8+
9+
string RequestFormatWithApiKey { get; }
10+
}
11+
}

SubEchoNest/IConfigurationProvider.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace SubEchoNest
2+
{
3+
public interface IConfigurationProvider
4+
{
5+
IConfiguration Configuration { get; }
6+
}
7+
}

SubEchoNest/IEchoNestService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace SubEchoNest
2+
{
3+
using SubEchoNest.Results;
4+
5+
public interface IEchoNestService
6+
{
7+
IGetBiographiesResult GetArtistBiographies(string artistName);
8+
}
9+
}

SubEchoNest/Models/Biographies.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
namespace SubEchoNest.Models
2+
{
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Xml.Serialization;
6+
7+
[XmlRoot("biographies")]
8+
public class Biographies
9+
{
10+
private const string LastFmSiteName = "last.fm";
11+
private const string WikipediaSiteName = "wikipedia";
12+
13+
public Biographies()
14+
{
15+
Items = new List<Biography>();
16+
}
17+
18+
[XmlElement("biography")]
19+
public List<Biography> Items { get; set; }
20+
21+
[XmlIgnore]
22+
public Biography PreferredBiography
23+
{
24+
get
25+
{
26+
return Items.OrderByDescending(GetScore).FirstOrDefault();
27+
}
28+
}
29+
30+
private int GetScore(Biography biography)
31+
{
32+
var maximumBiographyLength = Items.Max(item => item.Text != null ? item.Text.Length : 0);
33+
var score = BiographyPrioritiesEnum.None;
34+
if (biography.Site == LastFmSiteName)
35+
{
36+
score |= BiographyPrioritiesEnum.LastFm;
37+
}
38+
39+
if (biography.Site == WikipediaSiteName)
40+
{
41+
score |= BiographyPrioritiesEnum.Wikipedia;
42+
}
43+
44+
if (biography.Text != null && biography.Text.Length == maximumBiographyLength)
45+
{
46+
score |= BiographyPrioritiesEnum.LongestText;
47+
}
48+
49+
return (int)score;
50+
}
51+
}
52+
}

SubEchoNest/Models/Biography.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace SubEchoNest.Models
2+
{
3+
using System.Xml.Serialization;
4+
5+
[XmlRoot("biography")]
6+
public class Biography
7+
{
8+
[XmlElement("text")]
9+
public string Text { get; set; }
10+
11+
[XmlElement("site")]
12+
public string Site { get; set; }
13+
14+
[XmlElement("url")]
15+
public string Url { get; set; }
16+
}
17+
}

0 commit comments

Comments
 (0)