diff --git a/ShowInfo.Tests/ShowInfoTests.cs b/ShowInfo.Tests/ShowInfoTests.cs index 196372f..65bde8f 100644 --- a/ShowInfo.Tests/ShowInfoTests.cs +++ b/ShowInfo.Tests/ShowInfoTests.cs @@ -20,7 +20,7 @@ public void ForFilename_WithValidSEFileName_ReturnsTVEpisodeInfo() // Assert Assert.AreEqual(3, episode.SeasonNumber); Assert.AreEqual(1, episode.EpisodeNumber); - Assert.AreEqual("Once Upon a Time", episode.ShowName); + Assert.AreEqual("Once Upon a Time (2011)", episode.ShowName); Assert.AreEqual("The Heart of the Truest Believer", episode.EpisodeTitle); } @@ -72,5 +72,21 @@ public void GetEpisode_WithValidAirdate_ReturnsTVEpisode() Assert.AreEqual("The Colbert Report", episode.ShowName); Assert.AreEqual("Vince Gilligan", episode.EpisodeTitle); } + + [TestMethod] + public void GetEpisode_WithAliasValidSeasonEpisode_ReturnsTVEpisode() + { + // Arrange + ShowInformationManager showMgr = new ShowInformationManager(); + + // Act + TVEpisodeInfo episode = showMgr.GetEpisodeInfo("Once Upon a Time", 3, 2); + + // Assert + Assert.AreEqual(3, episode.SeasonNumber); + Assert.AreEqual(2, episode.EpisodeNumber); + Assert.AreEqual("Once Upon a Time (2011)", episode.ShowName); /* Notice this changes */ + Assert.AreEqual("Lost Girl", episode.EpisodeTitle); + } } } diff --git a/ShowInfo/ShowAlias.cs b/ShowInfo/ShowAlias.cs index 661328d..d702ded 100644 --- a/ShowInfo/ShowAlias.cs +++ b/ShowInfo/ShowAlias.cs @@ -10,10 +10,10 @@ namespace ShowInfo [DataContract] public class ShowAlias { - [DataMember] + [DataMember(Name="Show")] public string Show { get; set; } - [DataMember] + [DataMember(Name="Alias")] public string Alias { get; set; } } } diff --git a/ShowInfo/ShowInfo.csproj b/ShowInfo/ShowInfo.csproj index bb435af..4d20629 100644 --- a/ShowInfo/ShowInfo.csproj +++ b/ShowInfo/ShowInfo.csproj @@ -59,6 +59,9 @@ + + PreserveNewest + diff --git a/ShowInfo/ShowInformation.cs b/ShowInfo/ShowInformation.cs index c860a5a..bd1eaa5 100644 --- a/ShowInfo/ShowInformation.cs +++ b/ShowInfo/ShowInformation.cs @@ -10,6 +10,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using ShowInfoProvider; +using ServiceStack.Text; namespace ShowInfo { @@ -43,6 +44,8 @@ private void Compose() private string currentPath = string.Empty; + #region Aliases + /// /// Our list of customizable show 'aliases' /// @@ -56,6 +59,7 @@ private void LoadAliases() { // If the show alias file exists, load it up: currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + string data = string.Empty; try { @@ -66,8 +70,9 @@ private void LoadAliases() // If the alias file exists, open it: if(File.Exists(Path.Combine(currentPath, aliasFile))) { - // TODO: Open the file and laod the aliases - + // Open the file and load the aliases + data = File.ReadAllText(Path.Combine(currentPath, aliasFile)); + showAliases = data.FromJson>(); } } catch(Exception ex) @@ -76,6 +81,27 @@ private void LoadAliases() } } + /// + /// If an alias exists, the show's alias is returned. If the show has no alias, + /// the original show name is returned + /// + /// The show name to check + /// + private string ResolveShowToAlias(string showName) + { + string retval = showName; + + // If the given show has an alias, return it + if(this.showAliases.Where(s => s.Show == showName).Any()) + { + retval = showAliases.Where(s => s.Show == showName).Select(s => s.Alias).FirstOrDefault(); + } + + return retval; + } + + #endregion + /// /// Default constructor /// @@ -147,6 +173,9 @@ public TVEpisodeInfo GetEpisodeInfoForFilename(string filename) parsedEpisodeNumber = Convert.ToInt32(seMatch2.Groups["ep_num"].Value); } + // Resolve the show alias (if it exists) + parsedShowName = ResolveShowToAlias(parsedShowName); + // Based on the type of information parsed, use either // season/episode data providers or airdate data providers switch(currentParseType) @@ -192,6 +221,9 @@ public TVEpisodeInfo GetEpisodeInfo(string showName, int season, int episode) // Create our new episode information: TVEpisodeInfo retval = null; + // Resolve the show alias (if it exists) + showName = ResolveShowToAlias(showName); + foreach(var provider in SEShowInfoProviders) { retval = provider.GetShowInfo(showName, season, episode); @@ -217,6 +249,9 @@ public TVEpisodeInfo GetEpisodeInfo(string showName, int year, int month, int da // Create our new episode information: TVEpisodeInfo retval = null; + // Resolve the show alias (if it exists) + showName = ResolveShowToAlias(showName); + foreach(var provider in ADShowInfoProviders) { retval = provider.GetShowInfo(showName, year, month, day); diff --git a/ShowInfo/showalias.json b/ShowInfo/showalias.json new file mode 100644 index 0000000..2a74af7 --- /dev/null +++ b/ShowInfo/showalias.json @@ -0,0 +1,10 @@ +[ + { + "Show" : "Once Upon a Time", + "Alias" : "Once Upon a Time (2011)" + }, + { + "Show" : "Castle 2009", + "Alias" : "Castle" + } +] \ No newline at end of file