Move thumb tag parsing to separate method

This commit is contained in:
David Ullmer 2021-08-13 20:16:05 +02:00
parent 04571e93f8
commit 577d665192
No known key found for this signature in database
GPG Key ID: 4AEABE3359D5883C

View File

@ -783,59 +783,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
case "thumb":
{
var artType = reader.GetAttribute("aspect");
var val = reader.ReadElementContentAsString();
// skip:
// - empty aspect tag
// - empty uri
// - tag containing '.' because we can't set images for seasons, episodes or movie sets within series or movies
if (string.IsNullOrEmpty(artType) || string.IsNullOrEmpty(val) || artType.Contains('.', StringComparison.Ordinal))
{
break;
}
ImageType imageType = GetImageType(artType);
if (!Uri.TryCreate(val, UriKind.Absolute, out var uri))
{
Logger.LogError("Image location {Path} specified in nfo file for {ItemName} is not a valid URL or file path.", val, item.Name);
break;
}
if (uri.IsFile)
{
// only allow one item of each type
if (itemResult.Images.Any(x => x.Type == imageType))
{
break;
}
var fileSystemMetadata = _directoryService.GetFile(val);
// non existing file returns null
if (fileSystemMetadata == null || !fileSystemMetadata.Exists)
{
Logger.LogWarning("Artwork file {Path} specified in nfo file for {ItemName} does not exist.", uri, item.Name);
break;
}
itemResult.Images.Add(new LocalImageInfo()
{
FileInfo = fileSystemMetadata,
Type = imageType
});
}
else
{
// only allow one item of each type
if (itemResult.RemoteImages.Any(x => x.type == imageType))
{
break;
}
itemResult.RemoteImages.Add((uri.ToString(), imageType));
}
FetchThumbNode(reader, itemResult);
break;
}
@ -858,6 +806,62 @@ namespace MediaBrowser.XbmcMetadata.Parsers
}
}
private void FetchThumbNode(XmlReader reader, MetadataResult<T> itemResult)
{
var artType = reader.GetAttribute("aspect");
var val = reader.ReadElementContentAsString();
// skip:
// - empty aspect tag
// - empty uri
// - tag containing '.' because we can't set images for seasons, episodes or movie sets within series or movies
if (string.IsNullOrEmpty(artType) || string.IsNullOrEmpty(val) || artType.Contains('.', StringComparison.Ordinal))
{
return;
}
ImageType imageType = GetImageType(artType);
if (!Uri.TryCreate(val, UriKind.Absolute, out var uri))
{
Logger.LogError("Image location {Path} specified in nfo file for {ItemName} is not a valid URL or file path.", val, itemResult.Item.Name);
return;
}
if (uri.IsFile)
{
// only allow one item of each type
if (itemResult.Images.Any(x => x.Type == imageType))
{
return;
}
var fileSystemMetadata = _directoryService.GetFile(val);
// non existing file returns null
if (fileSystemMetadata == null || !fileSystemMetadata.Exists)
{
Logger.LogWarning("Artwork file {Path} specified in nfo file for {ItemName} does not exist.", uri, itemResult.Item.Name);
return;
}
itemResult.Images.Add(new LocalImageInfo()
{
FileInfo = fileSystemMetadata,
Type = imageType
});
}
else
{
// only allow one item of each type
if (itemResult.RemoteImages.Any(x => x.type == imageType))
{
return;
}
itemResult.RemoteImages.Add((uri.ToString(), imageType));
}
}
private void FetchFromFileInfoNode(XmlReader reader, T item)
{
reader.MoveToContent();