From 9722506acac42211c72807ff40547aa0b0a4589e Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 4 Jun 2013 20:13:57 -0700 Subject: [PATCH] Fixed XBMC updating --- .../DownloadedEpisodesImportService.cs | 8 ++++- .../Notifications/NotificationService.cs | 9 +++--- .../Notifications/Xbmc/XbmcProvider.cs | 31 ++++++++++--------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs b/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs index 0f120c412..85cf06534 100644 --- a/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs +++ b/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs @@ -72,7 +72,13 @@ public void ProcessDownloadedEpiosdesFolder() { try { - var series = _parsingService.GetSeries(videoFile); + var series = _parsingService.GetSeries(Path.GetFileNameWithoutExtension(videoFile)); + + if (series == null) + { + _logger.Trace("Unknown Series for file: {0}", videoFile); + } + ProcessVideoFile(videoFile, series); } catch (Exception ex) diff --git a/NzbDrone.Core/Notifications/NotificationService.cs b/NzbDrone.Core/Notifications/NotificationService.cs index 9f08f90c8..ba31661ac 100644 --- a/NzbDrone.Core/Notifications/NotificationService.cs +++ b/NzbDrone.Core/Notifications/NotificationService.cs @@ -10,6 +10,7 @@ using NzbDrone.Core.Download; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.Tv; using Omu.ValueInjecter; namespace NzbDrone.Core.Notifications @@ -134,10 +135,10 @@ private INotification GetInstance(NotificationDefinition indexerDefinition) return instance; } - private string GetMessage(ParsedEpisodeInfo parsedEpisodeInfo) + private string GetMessage(ParsedEpisodeInfo parsedEpisodeInfo, Series series) { return String.Format("{0} - {1}{2}", - parsedEpisodeInfo.SeriesTitle, + series.Title, parsedEpisodeInfo.SeasonNumber, String.Concat(parsedEpisodeInfo.EpisodeNumbers.Select(i => String.Format("x{0:00}", i)))); } @@ -148,7 +149,7 @@ public void Handle(EpisodeGrabbedEvent message) .ToList() .ForEach(notification => notification.Instance - .OnGrab(GetMessage(message.Episode.ParsedEpisodeInfo)) + .OnGrab(GetMessage(message.Episode.ParsedEpisodeInfo, message.Episode.Series)) ); } @@ -158,7 +159,7 @@ public void Handle(EpisodeDownloadedEvent message) .ToList() .ForEach(notification => notification.Instance - .OnDownload(GetMessage(message.ParsedEpisodeInfo), message.Series) + .OnDownload(GetMessage(message.ParsedEpisodeInfo, message.Series), message.Series) ); } diff --git a/NzbDrone.Core/Notifications/Xbmc/XbmcProvider.cs b/NzbDrone.Core/Notifications/Xbmc/XbmcProvider.cs index 1ea546f71..8facdc754 100644 --- a/NzbDrone.Core/Notifications/Xbmc/XbmcProvider.cs +++ b/NzbDrone.Core/Notifications/Xbmc/XbmcProvider.cs @@ -39,19 +39,19 @@ public virtual void Update(XbmcSettings settings, Series series) var username = settings.Username; var password = settings.Password; - var host = settings.Host; + var address = String.Format("{0}:{1}", settings.Host, settings.Port); - Logger.Trace("Determining version of XBMC Host: {0}", host); - var version = GetJsonVersion(host, username, password); + Logger.Trace("Determining version of XBMC Host: {0}", address); + var version = GetJsonVersion(address, username, password); - //If Dharma + //Dharma if (version == new XbmcVersion(2)) { //Check for active player only when we should skip updates when playing if (!settings.AlwaysUpdate) { - Logger.Trace("Determining if there are any active players on XBMC host: {0}", host); - var activePlayers = GetActivePlayersDharma(host, username, password); + Logger.Trace("Determining if there are any active players on XBMC host: {0}", address); + var activePlayers = GetActivePlayersDharma(address, username, password); //If video is currently playing, then skip update if (activePlayers["video"]) @@ -60,17 +60,17 @@ public virtual void Update(XbmcSettings settings, Series series) return; } } - UpdateWithHttp(series, host, username, password); + UpdateWithHttp(series, address, username, password); } - //If Eden or newer (attempting to make it future compatible) + //Eden else if (version == new XbmcVersion(3) || version == new XbmcVersion(4)) { //Check for active player only when we should skip updates when playing if (!settings.AlwaysUpdate) { - Logger.Trace("Determining if there are any active players on XBMC host: {0}", host); - var activePlayers = GetActivePlayersEden(host, username, password); + Logger.Trace("Determining if there are any active players on XBMC host: {0}", address); + var activePlayers = GetActivePlayersEden(address, username, password); //If video is currently playing, then skip update if (activePlayers.Any(a => a.Type.Equals("video"))) @@ -80,16 +80,17 @@ public virtual void Update(XbmcSettings settings, Series series) } } - UpdateWithJsonExecBuiltIn(series, host, username, password); + UpdateWithJsonExecBuiltIn(series, address, username, password); } + //Frodo or newer (attempting to make it future compatible) else if (version >= new XbmcVersion(5)) { //Check for active player only when we should skip updates when playing if (!settings.AlwaysUpdate) { - Logger.Trace("Determining if there are any active players on XBMC host: {0}", host); - var activePlayers = GetActivePlayersEden(host, username, password); + Logger.Trace("Determining if there are any active players on XBMC host: {0}", address); + var activePlayers = GetActivePlayersEden(address, username, password); //If video is currently playing, then skip update if (activePlayers.Any(a => a.Type.Equals("video"))) @@ -99,7 +100,7 @@ public virtual void Update(XbmcSettings settings, Series series) } } - UpdateWithJsonVideoLibraryScan(series, host, username, password); + UpdateWithJsonVideoLibraryScan(series, address, username, password); } //Log Version zero if check failed @@ -163,7 +164,7 @@ public virtual bool UpdateWithJsonVideoLibraryScan(Series series, string host, s Logger.Trace("Failed to get TV Shows from XBMC"); else - path = xbmcShows.FirstOrDefault(s => s.ImdbNumber == series.Id || s.Label == series.Title); + path = xbmcShows.FirstOrDefault(s => s.ImdbNumber == series.TvdbId || s.Label == series.Title); var postJson = new JObject(); postJson.Add(new JProperty("jsonrpc", "2.0"));