Always update by name and by path
This commit is contained in:
parent
a798ff3dcc
commit
edd03afee7
|
@ -22,4 +22,11 @@ namespace NzbDrone.Core.Notifications.Emby
|
||||||
public int TvMaze { get; set; }
|
public int TvMaze { get; set; }
|
||||||
public int TvRage { get; set; }
|
public int TvRage { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum MediaBrowserMatchQuality
|
||||||
|
{
|
||||||
|
Id = 0,
|
||||||
|
Name = 1,
|
||||||
|
None = 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace NzbDrone.Core.Notifications.Emby
|
||||||
ProcessRequest(request, settings);
|
ProcessRequest(request, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<string> GetPaths(MediaBrowserSettings settings, Series series)
|
public HashSet<string> GetPaths(MediaBrowserSettings settings, Series series)
|
||||||
{
|
{
|
||||||
var path = "/Items";
|
var path = "/Items";
|
||||||
var url = GetUrl(settings);
|
var url = GetUrl(settings);
|
||||||
|
@ -53,46 +53,44 @@ namespace NzbDrone.Core.Notifications.Emby
|
||||||
{
|
{
|
||||||
var paths = ProcessGetRequest<MediaBrowserItems>(request, settings).Items.GroupBy(item =>
|
var paths = ProcessGetRequest<MediaBrowserItems>(request, settings).Items.GroupBy(item =>
|
||||||
{
|
{
|
||||||
var accumulator = 0;
|
|
||||||
|
|
||||||
if (item is { ProviderIds.Tvdb: int tvdbid } && tvdbid != 0 && tvdbid == series.TvdbId)
|
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)
|
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)
|
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)
|
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)
|
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;
|
if (paths.Key == MediaBrowserMatchQuality.None)
|
||||||
}, item => item.Path).OrderBy(group => group.Key).First();
|
|
||||||
|
|
||||||
if (paths.Key == 0)
|
|
||||||
{
|
{
|
||||||
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)
|
catch (InvalidOperationException ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,27 +35,22 @@ namespace NzbDrone.Core.Notifications.Emby
|
||||||
|
|
||||||
public void Update(MediaBrowserSettings settings, Series series, string updateType)
|
public void Update(MediaBrowserSettings settings, Series series, string updateType)
|
||||||
{
|
{
|
||||||
List<string> paths;
|
HashSet<string> paths;
|
||||||
|
|
||||||
if (settings.UpdateLibraryByName)
|
|
||||||
{
|
|
||||||
paths = _proxy.GetPaths(settings, series);
|
paths = _proxy.GetPaths(settings, series);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
paths = new List<string> { series.Path };
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var path in paths)
|
var mappedPath = new OsPath(series.Path);
|
||||||
{
|
|
||||||
var mappedPath = new OsPath(path);
|
|
||||||
|
|
||||||
if (settings.MapTo.IsNotNullOrWhiteSpace())
|
if (settings.MapTo.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
mappedPath = new OsPath(settings.MapTo) + (mappedPath - new OsPath(settings.MapFrom));
|
mappedPath = new OsPath(settings.MapTo) + (mappedPath - new OsPath(settings.MapFrom));
|
||||||
}
|
}
|
||||||
|
|
||||||
_proxy.Update(settings, mappedPath.ToString(), updateType);
|
paths.Add(mappedPath.ToString());
|
||||||
|
|
||||||
|
foreach (var path in paths)
|
||||||
|
{
|
||||||
|
_proxy.Update(settings, path, updateType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)]
|
[FieldDefinition(5, Label = "Update Library", HelpText = "Update Library on Import, Rename, or Delete?", Type = FieldType.Checkbox)]
|
||||||
public bool UpdateLibrary { get; set; }
|
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)]
|
[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 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)]
|
|
||||||
public string MapFrom { get; set; }
|
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; }
|
public string MapTo { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
|
|
Loading…
Reference in New Issue