Merge pull request #6422 from daullmer/nfo-fanart
This commit is contained in:
commit
bb685e4920
|
@ -779,59 +779,15 @@ 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;
|
||||
}
|
||||
|
||||
case "fanart":
|
||||
{
|
||||
var subtree = reader.ReadSubtree();
|
||||
subtree.ReadToDescendant("thumb");
|
||||
FetchThumbNode(subtree, itemResult);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -854,6 +810,68 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||
}
|
||||
}
|
||||
|
||||
private void FetchThumbNode(XmlReader reader, MetadataResult<T> itemResult)
|
||||
{
|
||||
var artType = reader.GetAttribute("aspect");
|
||||
var val = reader.ReadElementContentAsString();
|
||||
|
||||
// artType is null if the thumb node is a child of the fanart tag
|
||||
// -> set image type to fanart
|
||||
if (string.IsNullOrWhiteSpace(artType))
|
||||
{
|
||||
artType = "fanart";
|
||||
}
|
||||
|
||||
// skip:
|
||||
// - empty uri
|
||||
// - tag containing '.' because we can't set images for seasons, episodes or movie sets within series or movies
|
||||
if (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();
|
||||
|
|
|
@ -207,6 +207,20 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
|
|||
Assert.Equal(id, item.ProviderIds[provider]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_GivenFileWithFanartTag_Success()
|
||||
{
|
||||
var result = new MetadataResult<Video>()
|
||||
{
|
||||
Item = new Movie()
|
||||
};
|
||||
|
||||
_parser.Fetch(result, "Test Data/Fanart.nfo", CancellationToken.None);
|
||||
|
||||
Assert.Single(result.RemoteImages.Where(x => x.type == ImageType.Backdrop));
|
||||
Assert.Equal("https://assets.fanart.tv/fanart/movies/141052/moviebackground/justice-league-5a5332c7b5e77.jpg", result.RemoteImages.First(x => x.type == ImageType.Backdrop).url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_RadarrUrlFile_Success()
|
||||
{
|
||||
|
|
33
tests/Jellyfin.XbmcMetadata.Tests/Test Data/Fanart.nfo
Normal file
33
tests/Jellyfin.XbmcMetadata.Tests/Test Data/Fanart.nfo
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<movie>
|
||||
<thumb aspect="clearlogo" preview="https://assets.fanart.tv/preview/movies/141052/hdmovielogo/justice-league-5865bf95cbadb.png">https://assets.fanart.tv/fanart/movies/141052/hdmovielogo/justice-league-5865bf95cbadb.png</thumb>
|
||||
<thumb aspect="clearlogo" preview="https://assets.fanart.tv/preview/movies/141052/hdmovielogo/justice-league-585e9ca3bcf6a.png">https://assets.fanart.tv/fanart/movies/141052/hdmovielogo/justice-league-585e9ca3bcf6a.png</thumb>
|
||||
<thumb aspect="clearlogo" preview="https://assets.fanart.tv/preview/movies/141052/hdmovielogo/justice-league-57b476a831d74.png">https://assets.fanart.tv/fanart/movies/141052/hdmovielogo/justice-league-57b476a831d74.png</thumb>
|
||||
<thumb aspect="clearlogo" preview="https://assets.fanart.tv/preview/movies/141052/hdmovielogo/justice-league-57947e28cf10b.png">https://assets.fanart.tv/fanart/movies/141052/hdmovielogo/justice-league-57947e28cf10b.png</thumb>
|
||||
<thumb aspect="clearlogo" preview="https://assets.fanart.tv/preview/movies/141052/hdmovielogo/justice-league-5863d5c0cf0c9.png">https://assets.fanart.tv/fanart/movies/141052/hdmovielogo/justice-league-5863d5c0cf0c9.png</thumb>
|
||||
<thumb aspect="clearlogo" preview="https://assets.fanart.tv/preview/movies/141052/hdmovielogo/justice-league-5a801747e5545.png">https://assets.fanart.tv/fanart/movies/141052/hdmovielogo/justice-league-5a801747e5545.png</thumb>
|
||||
<thumb aspect="clearlogo" preview="https://assets.fanart.tv/preview/movies/141052/hdmovielogo/justice-league-5cd75683df92b.png">https://assets.fanart.tv/fanart/movies/141052/hdmovielogo/justice-league-5cd75683df92b.png</thumb>
|
||||
<thumb aspect="banner" preview="https://assets.fanart.tv/preview/movies/141052/moviebanner/justice-league-586017e95adbd.jpg">https://assets.fanart.tv/fanart/movies/141052/moviebanner/justice-league-586017e95adbd.jpg</thumb>
|
||||
<thumb aspect="banner" preview="https://assets.fanart.tv/preview/movies/141052/moviebanner/justice-league-5934d45bc6592.jpg">https://assets.fanart.tv/fanart/movies/141052/moviebanner/justice-league-5934d45bc6592.jpg</thumb>
|
||||
<thumb aspect="banner" preview="https://assets.fanart.tv/preview/movies/141052/moviebanner/justice-league-5aa9289a379fa.jpg">https://assets.fanart.tv/fanart/movies/141052/moviebanner/justice-league-5aa9289a379fa.jpg</thumb>
|
||||
<thumb aspect="landscape" preview="https://assets.fanart.tv/preview/movies/141052/moviethumb/justice-league-585fb155c3743.jpg">https://assets.fanart.tv/fanart/movies/141052/moviethumb/justice-league-585fb155c3743.jpg</thumb>
|
||||
<thumb aspect="landscape" preview="https://assets.fanart.tv/preview/movies/141052/moviethumb/justice-league-585edbda91d82.jpg">https://assets.fanart.tv/fanart/movies/141052/moviethumb/justice-league-585edbda91d82.jpg</thumb>
|
||||
<thumb aspect="landscape" preview="https://assets.fanart.tv/preview/movies/141052/moviethumb/justice-league-5b86588882c12.jpg">https://assets.fanart.tv/fanart/movies/141052/moviethumb/justice-league-5b86588882c12.jpg</thumb>
|
||||
<thumb aspect="landscape" preview="https://assets.fanart.tv/preview/movies/141052/moviethumb/justice-league-5bbb9babe600c.jpg">https://assets.fanart.tv/fanart/movies/141052/moviethumb/justice-league-5bbb9babe600c.jpg</thumb>
|
||||
<thumb aspect="clearart" preview="https://assets.fanart.tv/preview/movies/141052/hdmovieclearart/justice-league-5865c23193041.png">https://assets.fanart.tv/fanart/movies/141052/hdmovieclearart/justice-league-5865c23193041.png</thumb>
|
||||
<thumb aspect="discart" preview="https://assets.fanart.tv/preview/movies/141052/moviedisc/justice-league-5a3af26360617.png">https://assets.fanart.tv/fanart/movies/141052/moviedisc/justice-league-5a3af26360617.png</thumb>
|
||||
<thumb aspect="discart" preview="https://assets.fanart.tv/preview/movies/141052/moviedisc/justice-league-58690967b9765.png">https://assets.fanart.tv/fanart/movies/141052/moviedisc/justice-league-58690967b9765.png</thumb>
|
||||
<thumb aspect="discart" preview="https://assets.fanart.tv/preview/movies/141052/moviedisc/justice-league-5a953ca4db6a6.png">https://assets.fanart.tv/fanart/movies/141052/moviedisc/justice-league-5a953ca4db6a6.png</thumb>
|
||||
<thumb aspect="discart" preview="https://assets.fanart.tv/preview/movies/141052/moviedisc/justice-league-5a0b913c233be.png">https://assets.fanart.tv/fanart/movies/141052/moviedisc/justice-league-5a0b913c233be.png</thumb>
|
||||
<thumb aspect="discart" preview="https://assets.fanart.tv/preview/movies/141052/moviedisc/justice-league-5a87e0cdb1209.png">https://assets.fanart.tv/fanart/movies/141052/moviedisc/justice-league-5a87e0cdb1209.png</thumb>
|
||||
<thumb aspect="discart" preview="https://assets.fanart.tv/preview/movies/141052/moviedisc/justice-league-59dc595362ef1.png">https://assets.fanart.tv/fanart/movies/141052/moviedisc/justice-league-59dc595362ef1.png</thumb>
|
||||
<fanart>
|
||||
<thumb preview="https://assets.fanart.tv/preview/movies/141052/moviebackground/justice-league-5a5332c7b5e77.jpg">https://assets.fanart.tv/fanart/movies/141052/moviebackground/justice-league-5a5332c7b5e77.jpg</thumb>
|
||||
<thumb preview="https://assets.fanart.tv/preview/movies/141052/moviebackground/justice-league-5a53cf2dac1c8.jpg">https://assets.fanart.tv/fanart/movies/141052/moviebackground/justice-league-5a53cf2dac1c8.jpg</thumb>
|
||||
<thumb preview="https://assets.fanart.tv/preview/movies/141052/moviebackground/justice-league-5976ba93eb5d3.jpg">https://assets.fanart.tv/fanart/movies/141052/moviebackground/justice-league-5976ba93eb5d3.jpg</thumb>
|
||||
<thumb preview="https://assets.fanart.tv/preview/movies/141052/moviebackground/justice-league-58fa1f1932897.jpg">https://assets.fanart.tv/fanart/movies/141052/moviebackground/justice-league-58fa1f1932897.jpg</thumb>
|
||||
<thumb preview="https://assets.fanart.tv/preview/movies/141052/moviebackground/justice-league-5a14f5fd8dd16.jpg">https://assets.fanart.tv/fanart/movies/141052/moviebackground/justice-league-5a14f5fd8dd16.jpg</thumb>
|
||||
<thumb preview="https://assets.fanart.tv/preview/movies/141052/moviebackground/justice-league-5a119394ea362.jpg">https://assets.fanart.tv/fanart/movies/141052/moviebackground/justice-league-5a119394ea362.jpg</thumb>
|
||||
</fanart>
|
||||
<thumb aspect="fanart">This-should-not-be-saved-as-a-fanart-image.jpg</thumb>
|
||||
</movie>
|
Loading…
Reference in New Issue
Block a user