1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Fixed: Preserve existing watched status in Kodi nfo files on metadata refreshes (not file upgrades).

This commit is contained in:
Taloth Saldono 2018-03-01 19:21:37 +01:00 committed by Taloth
parent b19b6c93d3
commit 58e939beda

View File

@ -7,6 +7,7 @@
using System.Xml; using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using NLog; using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Extras.Metadata.Files; using NzbDrone.Core.Extras.Metadata.Files;
using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaCover;
@ -21,13 +22,16 @@ public class XbmcMetadata : MetadataBase<XbmcMetadataSettings>
private readonly Logger _logger; private readonly Logger _logger;
private readonly IMapCoversToLocal _mediaCoverService; private readonly IMapCoversToLocal _mediaCoverService;
private readonly IDetectXbmcNfo _detectNfo; private readonly IDetectXbmcNfo _detectNfo;
private readonly IDiskProvider _diskProvider;
public XbmcMetadata(IDetectXbmcNfo detectNfo, public XbmcMetadata(IDetectXbmcNfo detectNfo,
IDiskProvider diskProvider,
IMapCoversToLocal mediaCoverService, IMapCoversToLocal mediaCoverService,
Logger logger) Logger logger)
{ {
_logger = logger; _logger = logger;
_mediaCoverService = mediaCoverService; _mediaCoverService = mediaCoverService;
_diskProvider = diskProvider;
_detectNfo = detectNfo; _detectNfo = detectNfo;
} }
@ -203,6 +207,8 @@ public override MetadataFileResult EpisodeMetadata(Series series, EpisodeFile ep
_logger.Debug("Generating Episode Metadata for: {0}", Path.Combine(series.Path, episodeFile.RelativePath)); _logger.Debug("Generating Episode Metadata for: {0}", Path.Combine(series.Path, episodeFile.RelativePath));
var watched = GetExistingWatchedStatus(series, episodeFile.RelativePath);
var xmlResult = string.Empty; var xmlResult = string.Empty;
foreach (var episode in episodeFile.Episodes.Value) foreach (var episode in episodeFile.Episodes.Value)
{ {
@ -237,7 +243,7 @@ public override MetadataFileResult EpisodeMetadata(Series series, EpisodeFile ep
details.Add(new XElement("thumb", image.Url)); details.Add(new XElement("thumb", image.Url));
} }
details.Add(new XElement("watched", "false")); details.Add(new XElement("watched", watched));
if (episode.Ratings != null && episode.Ratings.Votes > 0) if (episode.Ratings != null && episode.Ratings.Votes > 0)
{ {
@ -298,9 +304,6 @@ public override MetadataFileResult EpisodeMetadata(Series series, EpisodeFile ep
} }
} }
RenameExistingNfo(GetEpisodeMetadataFilename(episodeFile.RelativePath));
return new MetadataFileResult(GetEpisodeMetadataFilename(episodeFile.RelativePath), xmlResult.Trim(Environment.NewLine.ToCharArray())); return new MetadataFileResult(GetEpisodeMetadataFilename(episodeFile.RelativePath), xmlResult.Trim(Environment.NewLine.ToCharArray()));
} }
@ -380,11 +383,6 @@ private IEnumerable<ImageFileResult> ProcessSeasonImages(Series series, Season s
} }
} }
private void RenameExistingNfo(string nfoFilePath)
{
}
private string GetEpisodeMetadataFilename(string episodeFilePath) private string GetEpisodeMetadataFilename(string episodeFilePath)
{ {
return Path.ChangeExtension(episodeFilePath, "nfo"); return Path.ChangeExtension(episodeFilePath, "nfo");
@ -394,5 +392,19 @@ private string GetEpisodeImageFilename(string episodeFilePath)
{ {
return Path.ChangeExtension(episodeFilePath, "").Trim('.') + "-thumb.jpg"; return Path.ChangeExtension(episodeFilePath, "").Trim('.') + "-thumb.jpg";
} }
private bool GetExistingWatchedStatus(Series series, string episodeFilePath)
{
var fullPath = Path.Combine(series.Path, GetEpisodeMetadataFilename(episodeFilePath));
if (!_diskProvider.FileExists(fullPath))
{
return false;
}
var fileContent = _diskProvider.ReadAllText(fullPath);
return Regex.IsMatch(fileContent, "<watched>true</watched>");
}
} }
} }