Always update by name and by path

This commit is contained in:
Jendrik Weise 2023-07-27 18:37:58 +02:00
parent a798ff3dcc
commit edd03afee7
4 changed files with 33 additions and 36 deletions

View File

@ -22,4 +22,11 @@ namespace NzbDrone.Core.Notifications.Emby
public int TvMaze { get; set; }
public int TvRage { get; set; }
}
public enum MediaBrowserMatchQuality
{
Id = 0,
Name = 1,
None = 2
}
}

View File

@ -35,7 +35,7 @@ namespace NzbDrone.Core.Notifications.Emby
ProcessRequest(request, settings);
}
public List<string> GetPaths(MediaBrowserSettings settings, Series series)
public HashSet<string> GetPaths(MediaBrowserSettings settings, Series series)
{
var path = "/Items";
var url = GetUrl(settings);
@ -53,46 +53,44 @@ namespace NzbDrone.Core.Notifications.Emby
{
var paths = ProcessGetRequest<MediaBrowserItems>(request, settings).Items.GroupBy(item =>
{
var accumulator = 0;
if (item is { ProviderIds.Tvdb: int tvdbid } && tvdbid != 0 && tvdbid == series.TvdbId)
{
accumulator |= 1 << 4;
return MediaBrowserMatchQuality.Id;
}
if (item is { ProviderIds.Imdb: string imdbid } && imdbid == series.ImdbId)
{
accumulator |= 1 << 3;
return MediaBrowserMatchQuality.Id;
}
if (item is { ProviderIds.TvMaze: int tvmazeid } && tvmazeid != 0 && tvmazeid == series.TvMazeId)
{
accumulator |= 1 << 2;
return MediaBrowserMatchQuality.Id;
}
if (item is { ProviderIds.TvRage: int tvrageid } && tvrageid != 0 && tvrageid == series.TvRageId)
{
accumulator |= 1 << 1;
return MediaBrowserMatchQuality.Id;
}
if (item is { Name: var name } && name == series.Title)
{
accumulator |= 1 << 0;
return MediaBrowserMatchQuality.Name;
}
_logger.Trace($"{item.Path} {accumulator} {item.ProviderIds.TvRage} {series.TvRageId}");
return MediaBrowserMatchQuality.None;
}, item => item.Path).OrderBy(group => (int)group.Key).First();
return -accumulator;
}, item => item.Path).OrderBy(group => group.Key).First();
if (paths.Key == 0)
if (paths.Key == MediaBrowserMatchQuality.None)
{
throw new MediaBrowserException("Could not find series by name");
_logger.Trace("Could not find series by name");
return new HashSet<string>();
}
_logger.Trace("Found series by name: {0}", string.Join(" ", paths));
_logger.Trace("Found series by name/id: {0}", string.Join(" ", paths));
return paths.ToList();
return paths.ToHashSet();
}
catch (InvalidOperationException ex)
{

View File

@ -35,27 +35,22 @@ namespace NzbDrone.Core.Notifications.Emby
public void Update(MediaBrowserSettings settings, Series series, string updateType)
{
List<string> paths;
HashSet<string> paths;
if (settings.UpdateLibraryByName)
paths = _proxy.GetPaths(settings, series);
var mappedPath = new OsPath(series.Path);
if (settings.MapTo.IsNotNullOrWhiteSpace())
{
paths = _proxy.GetPaths(settings, series);
}
else
{
paths = new List<string> { series.Path };
mappedPath = new OsPath(settings.MapTo) + (mappedPath - new OsPath(settings.MapFrom));
}
paths.Add(mappedPath.ToString());
foreach (var path in paths)
{
var mappedPath = new OsPath(path);
if (settings.MapTo.IsNotNullOrWhiteSpace())
{
mappedPath = new OsPath(settings.MapTo) + (mappedPath - new OsPath(settings.MapFrom));
}
_proxy.Update(settings, mappedPath.ToString(), updateType);
_proxy.Update(settings, path, updateType);
}
}

View File

@ -45,13 +45,10 @@ namespace NzbDrone.Core.Notifications.Emby
[FieldDefinition(5, Label = "Update Library", HelpText = "Update Library on Import, Rename, or Delete?", Type = FieldType.Checkbox)]
public bool UpdateLibrary { get; set; }
[FieldDefinition(5, Label = "Update Library By Name", HelpText = "Update Library by name rather than path(Requires 'UpdateLibrary')", Type = FieldType.Checkbox, Advanced = true)]
public bool UpdateLibraryByName { get; set; }
[FieldDefinition(5, Label = "Map Paths From", HelpText = "Sonarr path, used to modify series paths when Emby/Jellyfin sees library path location differently from Sonarr(Requires 'UpdateLibrary')", Type = FieldType.Textbox, Advanced = true)]
[FieldDefinition(6, Label = "Map Paths From", HelpText = "Sonarr path, used to modify series paths when Emby/Jellyfin sees library path location differently from Sonarr(Requires 'UpdateLibrary')", Type = FieldType.Textbox, Advanced = true)]
public string MapFrom { get; set; }
[FieldDefinition(5, Label = "Map Paths To", HelpText = "Emby/Jellyfin path, used to modify series paths when Emby/Jellyfin sees library path location differently from Sonarr(Requires 'UpdateLibrary')", Type = FieldType.Textbox, Advanced = true)]
[FieldDefinition(7, Label = "Map Paths To", HelpText = "Emby/Jellyfin path, used to modify series paths when Emby/Jellyfin sees library path location differently from Sonarr(Requires 'UpdateLibrary')", Type = FieldType.Textbox, Advanced = true)]
public string MapTo { get; set; }
[JsonIgnore]