Merge pull request #5068 from Ullmie02/nfo-tests

This commit is contained in:
Bond-009 2021-01-23 13:52:33 +01:00 committed by GitHub
commit 827f39f54b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 503 additions and 4 deletions

View File

@ -208,6 +208,18 @@ namespace MediaBrowser.XbmcMetadata.Parsers
break;
}
case "showtitle":
{
var showtitle = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(showtitle))
{
item.SeriesName = showtitle;
}
break;
}
default:
base.FetchDataFromXmlNode(reader, itemResult);
break;

View File

@ -56,6 +56,8 @@ namespace MediaBrowser.XbmcMetadata.Savers
{
var episode = (Episode)item;
writer.WriteElementString("showtitle", episode.SeriesName);
if (episode.IndexNumber.HasValue)
{
writer.WriteElementString("episode", episode.IndexNumber.Value.ToString(_usCulture));
@ -122,7 +124,8 @@ namespace MediaBrowser.XbmcMetadata.Savers
"airsbefore_episode",
"airsbefore_season",
"displayseason",
"displayepisode"
"displayepisode",
"showtitle"
});
return list;

View File

@ -0,0 +1,103 @@
using System;
using System.Linq;
using System.Threading;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.XbmcMetadata.Parsers;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
#pragma warning disable CA5369
namespace Jellyfin.XbmcMetadata.Tests.Parsers
{
public class EpisodeNfoProviderTests
{
private readonly EpisodeNfoParser _parser;
public EpisodeNfoProviderTests()
{
var providerManager = new Mock<IProviderManager>();
providerManager.Setup(x => x.GetExternalIdInfos(It.IsAny<IHasProviderIds>()))
.Returns(Enumerable.Empty<ExternalIdInfo>());
var config = new Mock<IConfigurationManager>();
config.Setup(x => x.GetConfiguration(It.IsAny<string>()))
.Returns(new XbmcMetadataOptions());
_parser = new EpisodeNfoParser(new NullLogger<EpisodeNfoParser>(), config.Object, providerManager.Object);
}
[Fact]
public void Fetch_Valid_Succes()
{
var result = new MetadataResult<Episode>()
{
Item = new Episode()
};
_parser.Fetch(result, "Test Data/The Bone Orchard.nfo", CancellationToken.None);
var item = result.Item;
Assert.Equal("The Bone Orchard", item.Name);
Assert.Equal("American Gods", item.SeriesName);
Assert.Equal(1, item.IndexNumber);
Assert.Equal(1, item.ParentIndexNumber);
Assert.Equal("When Shadow Moon is released from prison early after the death of his wife, he meets Mr. Wednesday and is recruited as his bodyguard. Shadow discovers that this may be more than he bargained for.", item.Overview);
Assert.Equal(0, item.RunTimeTicks);
Assert.Equal("16", item.OfficialRating);
Assert.Contains("Drama", item.Genres);
Assert.Contains("Mystery", item.Genres);
Assert.Contains("Sci-Fi & Fantasy", item.Genres);
Assert.Equal(new DateTime(2017, 4, 30), item.PremiereDate);
Assert.Equal(2017, item.ProductionYear);
Assert.Single(item.Studios);
Assert.Contains("Starz", item.Studios);
// Credits
var writers = result.People.Where(x => x.Type == PersonType.Writer).ToArray();
Assert.Equal(2, writers.Length);
Assert.Contains("Bryan Fuller", writers.Select(x => x.Name));
Assert.Contains("Michael Green", writers.Select(x => x.Name));
// Direcotrs
var directors = result.People.Where(x => x.Type == PersonType.Director).ToArray();
Assert.Single(directors);
Assert.Contains("David Slade", directors.Select(x => x.Name));
// Actors
var actors = result.People.Where(x => x.Type == PersonType.Actor).ToArray();
Assert.Equal(11, actors.Length);
// Only test one actor
var shadow = actors.FirstOrDefault(x => x.Role.Equals("Shadow Moon", StringComparison.Ordinal));
Assert.NotNull(shadow);
Assert.Equal("Ricky Whittle", shadow!.Name);
Assert.Equal(0, shadow!.SortOrder);
Assert.Equal("http://image.tmdb.org/t/p/original/cjeDbVfBp6Qvb3C74Dfy7BKDTQN.jpg", shadow!.ImageUrl);
Assert.Equal(new DateTime(2017, 10, 7, 14, 25, 47), item.DateCreated);
}
[Fact]
public void Fetch_WithNullItem_ThrowsArgumentException()
{
var result = new MetadataResult<Episode>();
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, "Test Data/The Bone Orchard.nfo", CancellationToken.None));
}
[Fact]
public void Fetch_NullResult_ThrowsArgumentException()
{
var result = new MetadataResult<Episode>()
{
Item = new Episode()
};
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, string.Empty, CancellationToken.None));
}
}
}

View File

@ -12,7 +12,7 @@ using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
namespace Jellyfin.XbmcMetadata.Parsers.Tests
namespace Jellyfin.XbmcMetadata.Tests.Parsers
{
public class MovieNfoParserTests
{

View File

@ -0,0 +1,72 @@
#pragma warning disable CA5369
using System;
using System.Linq;
using System.Threading;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.XbmcMetadata.Parsers;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
namespace Jellyfin.XbmcMetadata.Tests.Parsers
{
public class MusicAlbumNfoProviderTests
{
private readonly BaseNfoParser<MusicAlbum> _parser;
public MusicAlbumNfoProviderTests()
{
var providerManager = new Mock<IProviderManager>();
providerManager.Setup(x => x.GetExternalIdInfos(It.IsAny<IHasProviderIds>()))
.Returns(Enumerable.Empty<ExternalIdInfo>());
var config = new Mock<IConfigurationManager>();
config.Setup(x => x.GetConfiguration(It.IsAny<string>()))
.Returns(new XbmcMetadataOptions());
_parser = new BaseNfoParser<MusicAlbum>(new NullLogger<BaseNfoParser<MusicAlbum>>(), config.Object, providerManager.Object);
}
[Fact]
public void Fetch_Valid_Succes()
{
var result = new MetadataResult<MusicAlbum>()
{
Item = new MusicAlbum()
};
_parser.Fetch(result, "Test Data/The Best of 1980-1990.nfo", CancellationToken.None);
var item = result.Item;
Assert.Equal("The Best of 1980-1990", item.Name);
Assert.Equal(1989, item.ProductionYear);
Assert.Contains("Pop", item.Genres);
Assert.Single(item.Genres);
Assert.Contains("Rock/Pop", item.Tags);
Assert.Equal("The Best of 1980-1990 is the first greatest hits compilation by Irish rock band U2, released in November 1998. It mostly contains the group's hit singles from the eighties but also mixes in some live staples as well as one new recording, Sweetest Thing. In April 1999, a companion video (featuring music videos and live footage) was released. The album was followed by another compilation, The Best of 1990-2000, in 2002.\nA limited edition version containing a special B-sides disc was released on the same date as the single-disc version. At the time of release, the official word was that the 2-disc album would be available the first week the album went on sale, then pulled from the stores. While this threat never materialized, it did result in the 2-disc version being in very high demand. Both versions charted in the Billboard 200.\nThe boy on the cover is Peter Rowan, brother of Bono's friend Guggi (real name Derek Rowan) of the Virgin Prunes. He also appears on the covers of the early EP Three, two of the band's first three albums (Boy and War), and Early Demos.", item.Overview);
}
[Fact]
public void Fetch_WithNullItem_ThrowsArgumentException()
{
var result = new MetadataResult<MusicAlbum>();
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, "Test Data/The Best of 1980-1990.nfo", CancellationToken.None));
}
[Fact]
public void Fetch_NullResult_ThrowsArgumentException()
{
var result = new MetadataResult<MusicAlbum>()
{
Item = new MusicAlbum()
};
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, string.Empty, CancellationToken.None));
}
}
}

View File

@ -12,7 +12,7 @@ using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
namespace Jellyfin.XbmcMetadata.Parsers.Tests
namespace Jellyfin.XbmcMetadata.Tests.Parsers
{
public class MusicArtistNfoParserTests
{

View File

@ -0,0 +1,83 @@
#pragma warning disable CA5369
using System;
using System.Linq;
using System.Threading;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.XbmcMetadata.Parsers;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
namespace Jellyfin.XbmcMetadata.Tests.Parsers
{
public class SeasonNfoProviderTests
{
private readonly SeasonNfoParser _parser;
public SeasonNfoProviderTests()
{
var providerManager = new Mock<IProviderManager>();
providerManager.Setup(x => x.GetExternalIdInfos(It.IsAny<IHasProviderIds>()))
.Returns(Enumerable.Empty<ExternalIdInfo>());
var config = new Mock<IConfigurationManager>();
config.Setup(x => x.GetConfiguration(It.IsAny<string>()))
.Returns(new XbmcMetadataOptions());
_parser = new SeasonNfoParser(new NullLogger<SeasonNfoParser>(), config.Object, providerManager.Object);
}
[Fact]
public void Fetch_Valid_Succes()
{
var result = new MetadataResult<Season>()
{
Item = new Season()
};
_parser.Fetch(result, "Test Data/Season 01.nfo", CancellationToken.None);
var item = result.Item;
Assert.Equal("Season 1", item.Name);
Assert.Equal(1, item.IndexNumber);
Assert.False(item.IsLocked);
Assert.Equal(2019, item.ProductionYear);
Assert.Equal(new DateTime(2019, 11, 08), item.PremiereDate);
Assert.Equal(new DateTime(2020, 06, 14, 17, 26, 51), item.DateCreated);
Assert.Equal(10, result.People.Count);
Assert.True(result.People.All(x => x.Type == PersonType.Actor));
// Only test one actor
var nini = result.People.FirstOrDefault(x => x.Role.Equals("Nini", StringComparison.Ordinal));
Assert.NotNull(nini);
Assert.Equal("Olivia Rodrigo", nini!.Name);
Assert.Equal(0, nini!.SortOrder);
Assert.Equal("/config/metadata/People/O/Olivia Rodrigo/poster.jpg", nini!.ImageUrl);
}
[Fact]
public void Fetch_WithNullItem_ThrowsArgumentException()
{
var result = new MetadataResult<Season>();
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, "Test Data/Season 01.nfo", CancellationToken.None));
}
[Fact]
public void Fetch_NullResult_ThrowsArgumentException()
{
var result = new MetadataResult<Season>()
{
Item = new Season()
};
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, string.Empty, CancellationToken.None));
}
}
}

View File

@ -12,7 +12,7 @@ using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
namespace Jellyfin.XbmcMetadata.Parsers.Tests
namespace Jellyfin.XbmcMetadata.Tests.Parsers
{
public class SeriesNfoParserTests
{

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<season>
<plot />
<outline />
<lockdata>false</lockdata>
<dateadded>2020-06-14 17:26:51</dateadded>
<title>Season 1</title>
<year>2019</year>
<tvdbid>359728</tvdbid>
<premiered>2019-11-08</premiered>
<releasedate>2019-11-08</releasedate>
<art>
<poster>/media/Serien/High School Musical The Musical The Series (2019)/Season 1/Season 1.jpeg</poster>
</art>
<actor>
<name>Olivia Rodrigo</name>
<role>Nini</role>
<type>Actor</type>
<sortorder>0</sortorder>
<thumb>/config/metadata/People/O/Olivia Rodrigo/poster.jpg</thumb>
</actor>
<actor>
<name>Kate Reinders</name>
<role>Miss Jenn</role>
<type>Actor</type>
<sortorder>1</sortorder>
<thumb>/config/metadata/People/K/Kate Reinders/poster.jpg</thumb>
</actor>
<actor>
<name>Sofia Wylie</name>
<role>Gina</role>
<type>Actor</type>
<sortorder>2</sortorder>
<thumb>/config/metadata/People/S/Sofia Wylie/poster.jpg</thumb>
</actor>
<actor>
<name>Matt Cornett</name>
<role>E.J.</role>
<type>Actor</type>
<sortorder>3</sortorder>
<thumb>/config/metadata/People/M/Matt Cornett/poster.jpg</thumb>
</actor>
<actor>
<name>Dara Reneé</name>
<role>Kourtney</role>
<type>Actor</type>
<sortorder>4</sortorder>
<thumb>/config/metadata/People/D/Dara Reneé/poster.jpg</thumb>
</actor>
<actor>
<name>Julia Lester</name>
<role>Ashlyn</role>
<type>Actor</type>
<sortorder>5</sortorder>
<thumb>/config/metadata/People/J/Julia Lester/poster.jpg</thumb>
</actor>
<actor>
<name>Joshua Bassett</name>
<role>Ricky</role>
<type>Actor</type>
<sortorder>6</sortorder>
<thumb>/config/metadata/People/J/Joshua Bassett/poster.jpg</thumb>
</actor>
<actor>
<name>Frankie A. Rodriguez</name>
<role>Carlos</role>
<type>Actor</type>
<sortorder>7</sortorder>
<thumb>/config/metadata/People/F/Frankie A. Rodriguez/poster.jpg</thumb>
</actor>
<actor>
<name>Larry Saperstein</name>
<role>Big Red</role>
<type>Actor</type>
<sortorder>8</sortorder>
<thumb>/config/metadata/People/L/Larry Saperstein/poster.jpg</thumb>
</actor>
<actor>
<name>Mark St. Cyr</name>
<role>Mr. Mazzara</role>
<type>Actor</type>
<sortorder>9</sortorder>
<thumb>/config/metadata/People/M/Mark St. Cyr/poster.jpg</thumb>
</actor>
<seasonnumber>1</seasonnumber>
</season>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<album>
<title>The Best of 1980-1990</title>
<musicbrainzalbumid>59b5a40b-e2fd-3f18-a218-e8c9aae12ab5</musicbrainzalbumid>
<musicbrainzreleasegroupid>6c301dbd-6ccb-3403-a6c4-6a22240a0297</musicbrainzreleasegroupid>
<scrapedmbid>false</scrapedmbid>
<artistdesc>U2</artistdesc>
<genre>Pop</genre>
<style>Rock/Pop</style>
<mood>Political</mood>
<compilation>false</compilation>
<review>The Best of 1980-1990 is the first greatest hits compilation by Irish rock band U2, released in November 1998. It mostly contains the group&apos;s hit singles from the eighties but also mixes in some live staples as well as one new recording, Sweetest Thing. In April 1999, a companion video (featuring music videos and live footage) was released. The album was followed by another compilation, The Best of 1990-2000, in 2002.&#x0A;A limited edition version containing a special B-sides disc was released on the same date as the single-disc version. At the time of release, the official word was that the 2-disc album would be available the first week the album went on sale, then pulled from the stores. While this threat never materialized, it did result in the 2-disc version being in very high demand. Both versions charted in the Billboard 200.&#x0A;The boy on the cover is Peter Rowan, brother of Bono&apos;s friend Guggi (real name Derek Rowan) of the Virgin Prunes. He also appears on the covers of the early EP Three, two of the band&apos;s first three albums (Boy and War), and Early Demos.</review>
<type>album / compilation</type>
<releasedate></releasedate>
<label>Island</label>
<thumb preview="https://assets.fanart.tv/preview/music/a3cb23fc-acd3-4ce0-8f36-1e5aa6a18432/albumcover/the-best-of-1980-1990-4e43a22cab023.jpg">https://assets.fanart.tv/fanart/music/a3cb23fc-acd3-4ce0-8f36-1e5aa6a18432/albumcover/the-best-of-1980-1990-4e43a22cab023.jpg</thumb>
<thumb preview="https://assets.fanart.tv/preview/music/a3cb23fc-acd3-4ce0-8f36-1e5aa6a18432/albumcover/the-best-of-1980-1990-5bc4301068645.jpg">https://assets.fanart.tv/fanart/music/a3cb23fc-acd3-4ce0-8f36-1e5aa6a18432/albumcover/the-best-of-1980-1990-5bc4301068645.jpg</thumb>
<thumb preview="https://www.theaudiodb.com/images/media/album/thumb/the-best-of-1980-1990-4e43a22cab023.jpg/preview">https://www.theaudiodb.com/images/media/album/thumb/the-best-of-1980-1990-4e43a22cab023.jpg</thumb>
<path>C:\KODI\Test- Music\U2\Best Of 1980-1990, The\</path>
<rating max="10">-1.000000</rating>
<userrating max="10">-1</userrating>
<votes>-1</votes>
<year>1989</year>
<albumArtistCredits>
<artist>U2</artist>
<musicBrainzArtistID>a3cb23fc-acd3-4ce0-8f36-1e5aa6a18432</musicBrainzArtistID>
</albumArtistCredits>
<releasetype>album</releasetype>
</album>

View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<episodedetails>
<title>The Bone Orchard</title>
<showtitle>American Gods</showtitle>
<ratings>
<rating name="tmdb" max="10" default="true">
<value>7.532000</value>
<votes>31</votes>
</rating>
</ratings>
<userrating>0</userrating>
<top250>0</top250>
<season>1</season>
<episode>1</episode>
<displayseason>-1</displayseason>
<displayepisode>-1</displayepisode>
<outline></outline>
<plot>When Shadow Moon is released from prison early after the death of his wife, he meets Mr. Wednesday and is recruited as his bodyguard. Shadow discovers that this may be more than he bargained for.</plot>
<tagline></tagline>
<runtime>0</runtime>
<thumb>http://image.tmdb.org/t/p/original/uvry4weK00pFLn7fxQ9M4m3Da2A.jpg</thumb>
<mpaa>16</mpaa>
<playcount>0</playcount>
<lastplayed></lastplayed>
<id>1276153</id>
<uniqueid type="tmdb" default="true">1276153</uniqueid>
<genre>Drama</genre>
<genre>Mystery</genre>
<genre>Sci-Fi &amp; Fantasy</genre>
<credits>Bryan Fuller</credits>
<credits>Michael Green</credits>
<director>David Slade</director>
<premiered>2017-04-30</premiered>
<year>2017</year>
<status></status>
<code></code>
<aired>2017-04-30</aired>
<studio>Starz</studio>
<trailer></trailer>
<actor>
<name>Jonathan Tucker</name>
<role>&apos;Low Key&apos; Lyesmith</role>
<order>10</order>
<thumb>http://image.tmdb.org/t/p/original/jvJpYDbwmUTACw7Yn7PKOP6CdlJ.jpg</thumb>
</actor>
<actor>
<name>Demore Barnes</name>
<role>Mr. Ibis</role>
<order>11</order>
<thumb>http://image.tmdb.org/t/p/original/4rEVzSIFPgiN14xYQnjKcKQ7tYE.jpg</thumb>
</actor>
<actor>
<name>Betty Gilpin</name>
<role>Audrey</role>
<order>12</order>
<thumb>http://image.tmdb.org/t/p/original/xFeqyem5i4Kf0nFjBZ4Oi9NM26k.jpg</thumb>
</actor>
<actor>
<name>Beth Grant</name>
<role>Jack</role>
<order>13</order>
<thumb>http://image.tmdb.org/t/p/original/zAT9GvzJE0ytL3C36L461cgKI9p.jpg</thumb>
</actor>
<actor>
<name>Joel Murray</name>
<role>Paunch</role>
<order>14</order>
<thumb>http://image.tmdb.org/t/p/original/t5syYfCgxbTC7XPrNeXhhhQULUf.jpg</thumb>
</actor>
<actor>
<name>Ricky Whittle</name>
<role>Shadow Moon</role>
<order>0</order>
<thumb>http://image.tmdb.org/t/p/original/cjeDbVfBp6Qvb3C74Dfy7BKDTQN.jpg</thumb>
</actor>
<actor>
<name>Ian McShane</name>
<role>Mr. Wednesday</role>
<order>1</order>
<thumb>http://image.tmdb.org/t/p/original/pY9ud4BJwHekNiO4MMItPbgkdAy.jpg</thumb>
</actor>
<actor>
<name>Emily Browning</name>
<role>Laura Moon</role>
<order>2</order>
<thumb>http://image.tmdb.org/t/p/original/fa1Kyj02wxwcdS6EHb2i27TNXvU.jpg</thumb>
</actor>
<actor>
<name>Pablo Schreiber</name>
<role>Mad Sweeney</role>
<order>3</order>
<thumb>http://image.tmdb.org/t/p/original/uo8YljeePz3pbj7gvWXdB4gOOW4.jpg</thumb>
</actor>
<actor>
<name>Bruce Langley</name>
<role>Technical Boy</role>
<order>4</order>
<thumb>http://image.tmdb.org/t/p/original/f4EOWUmznLqboq8Ce7jnlkHVK3Y.jpg</thumb>
</actor>
<actor>
<name>Yetide Badaki</name>
<role>Bilquis</role>
<order>5</order>
<thumb>http://image.tmdb.org/t/p/original/qfzkREHuI1JvMxBteIAjKX8qMEr.jpg</thumb>
</actor>
<resume>
<position>0.000000</position>
<total>0.000000</total>
</resume>
<dateadded>2017-10-07 14:25:47</dateadded>
</episodedetails>