From c693f902717bb6fc72d568ce608db3aeb23474b9 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 17 Oct 2012 23:49:53 -0700 Subject: [PATCH] Fixed up issues with initial XEM implementation --- NzbDrone.Core.Test/Files/Xem/Ids.txt | 22 ++++------------- NzbDrone.Core.Test/Files/Xem/Names.txt | 24 +++++++++++++++++++ .../JobTests/ImportNewSeriesJobTest.cs | 1 - NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 5 +++- NzbDrone.Core/Jobs/XemUpdateJob.cs | 9 +++++-- .../Providers/XemCommunicationProvider.cs | 7 +++--- NzbDrone.Core/Providers/XemProvider.cs | 17 +++++++++++-- 7 files changed, 58 insertions(+), 27 deletions(-) create mode 100644 NzbDrone.Core.Test/Files/Xem/Names.txt diff --git a/NzbDrone.Core.Test/Files/Xem/Ids.txt b/NzbDrone.Core.Test/Files/Xem/Ids.txt index fb005862c..fad09850f 100644 --- a/NzbDrone.Core.Test/Files/Xem/Ids.txt +++ b/NzbDrone.Core.Test/Files/Xem/Ids.txt @@ -1,24 +1,10 @@ { "result": "success", - "data": { - "220571": [ - "Is This a Zombie? Of the Dead", - "Kore wa Zombie Desuka?", - "Kore wa Zombie Desuka? Of the Dead", - "Kore wa Zombie Desuka Of the Dead", - "Kore wa Zombie Desu ka - Of the Dead", - "Kore wa Zombie Desu ka of the Dead" - ], - "79151": [ - "Fate Stay Night", - "Fate/Zero", - "Fate Zero", - "Fate/Zero (2012)", - "Fate Zero S2", - "Fate Zero" - ] - }, + "data": [ + "73141", + "79886", + ], "message": "" } \ No newline at end of file diff --git a/NzbDrone.Core.Test/Files/Xem/Names.txt b/NzbDrone.Core.Test/Files/Xem/Names.txt new file mode 100644 index 000000000..fb005862c --- /dev/null +++ b/NzbDrone.Core.Test/Files/Xem/Names.txt @@ -0,0 +1,24 @@ +{ + + "result": "success", + "data": { + "220571": [ + "Is This a Zombie? Of the Dead", + "Kore wa Zombie Desuka?", + "Kore wa Zombie Desuka? Of the Dead", + "Kore wa Zombie Desuka Of the Dead", + "Kore wa Zombie Desu ka - Of the Dead", + "Kore wa Zombie Desu ka of the Dead" + ], + "79151": [ + "Fate Stay Night", + "Fate/Zero", + "Fate Zero", + "Fate/Zero (2012)", + "Fate Zero S2", + "Fate Zero" + ] + }, + "message": "" + +} \ No newline at end of file diff --git a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs index 9a83c768b..4d5a03b09 100644 --- a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs @@ -42,7 +42,6 @@ public void import_new_series_succesfull() .Setup(j => j.Start(notification, series[0].SeriesId, 0)) .Callback(() => series[0].LastDiskSync = DateTime.Now); - Mocker.GetMock() .Setup(j => j.Start(notification, series[1].SeriesId, 0)) .Callback(() => series[1].LastDiskSync = DateTime.Now); diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index c406f37b4..2f7a97268 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -335,10 +335,13 @@ Designer Always + + Always + Always - + Always diff --git a/NzbDrone.Core/Jobs/XemUpdateJob.cs b/NzbDrone.Core/Jobs/XemUpdateJob.cs index 53904a624..a64b5f54d 100644 --- a/NzbDrone.Core/Jobs/XemUpdateJob.cs +++ b/NzbDrone.Core/Jobs/XemUpdateJob.cs @@ -44,8 +44,13 @@ public virtual void Start(ProgressNotification notification, int targetId, int s _logger.Trace("Starting XEM Update for all series"); _xemProvider.UpdateMappings(); } - _logger.Trace("Starting XEM Update for series: {0}", targetId); - _xemProvider.UpdateMappings(targetId); + + else + { + _logger.Trace("Starting XEM Update for series: {0}", targetId); + _xemProvider.UpdateMappings(targetId); + } + _logger.Trace("XEM Update complete"); } } diff --git a/NzbDrone.Core/Providers/XemCommunicationProvider.cs b/NzbDrone.Core/Providers/XemCommunicationProvider.cs index 7c0d97e3a..3cbab3a12 100644 --- a/NzbDrone.Core/Providers/XemCommunicationProvider.cs +++ b/NzbDrone.Core/Providers/XemCommunicationProvider.cs @@ -32,14 +32,15 @@ public XemCommunicationProvider() public virtual List GetXemSeriesIds(string origin = "tvdb") { _logger.Trace("Fetching Series IDs from: {0}", origin); - var url = String.Format("{0}allNames?origin={1}", XEM_BASE_URL, origin); + + var url = String.Format("{0}havemap?origin={1}", XEM_BASE_URL, origin); var response =_httpProvider.DownloadString(url); CheckForFailureResult(response); - var result = JsonConvert.DeserializeObject>>(JObject.Parse(response).SelectToken("data").ToString()); + var result = JsonConvert.DeserializeObject>>(response); - return result.Keys.ToList(); + return result.Data.ToList(); } public virtual List GetSceneTvdbMappings(int id) diff --git a/NzbDrone.Core/Providers/XemProvider.cs b/NzbDrone.Core/Providers/XemProvider.cs index b3e0e01b7..3c1fed45c 100644 --- a/NzbDrone.Core/Providers/XemProvider.cs +++ b/NzbDrone.Core/Providers/XemProvider.cs @@ -36,7 +36,7 @@ public virtual void UpdateMappings() { var ids = _xemCommunicationProvider.GetXemSeriesIds(); var series = _seriesProvider.GetAllSeries(); - var wantedSeries = series.Where(s => ids.Contains(s.SeriesId)); + var wantedSeries = series.Where(s => ids.Contains(s.SeriesId)).ToList(); foreach(var ser in wantedSeries) { @@ -80,11 +80,20 @@ public virtual void PerformUpdate(Series series) return; } + var episodes = _episodeProvider.GetEpisodeBySeries(series.SeriesId); + foreach (var mapping in mappings) { _logger.Trace("Setting scene numbering mappings for {0} S{1:00}E{2:00}", series.Title, mapping.Tvdb.Season, mapping.Tvdb.Episode); - var episode = _episodeProvider.GetEpisode(series.SeriesId, mapping.Tvdb.Season, mapping.Tvdb.Episode); + var episode = episodes.SingleOrDefault(e => e.SeasonNumber == mapping.Tvdb.Season && e.EpisodeNumber == mapping.Tvdb.Episode); + + if (episode == null) + { + _logger.Trace("Information hasn't been added to TheTVDB yet, skipping."); + continue; + } + episode.AbsoluteEpisodeNumber = mapping.Scene.Absolute; episode.SceneSeasonNumber = mapping.Scene.Season; episode.SceneEpisodeNumber = mapping.Scene.Episode; @@ -93,6 +102,10 @@ public virtual void PerformUpdate(Series series) _logger.Trace("Committing scene numbering mappings to database for: {0}", series.Title); _episodeProvider.UpdateEpisodes(episodesToUpdate); + + _logger.Trace("Setting UseSceneMapping for {0}", series.Title); + series.UseSceneNumbering = true; + _seriesProvider.UpdateSeries(series); } catch (Exception ex)