Merge pull request #5235 from Ullmie02/nfo-tests

This commit is contained in:
Bond-009 2021-02-15 20:17:57 +01:00 committed by GitHub
commit 91ee1b1d02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 271 additions and 10 deletions

View File

@ -1,5 +1,6 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
@ -14,6 +15,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: InternalsVisibleTo("Jellyfin.XbmcMetadata.Tests")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from

View File

@ -0,0 +1,65 @@
using System.Linq;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.System;
using MediaBrowser.XbmcMetadata.Savers;
using Xunit;
namespace Jellyfin.XbmcMetadata.Tests.Location
{
public class MovieNfoLocationTests
{
[Fact]
public static void Movie_MixedFolder_Success()
{
var movie = new Movie() { Path = "/media/movies/Avengers Endgame.mp4", IsInMixedFolder = true };
var paths = MovieNfoSaver.GetMovieSavePaths(new ItemInfo(movie)).ToArray();
Assert.Single(paths);
Assert.Contains("/media/movies/Avengers Endgame.nfo", paths);
}
[Fact]
public static void Movie_SeparateFolder_Success()
{
var movie = new Movie() { Path = "/media/movies/Avengers Endgame/Avengers Endgame.mp4" };
var path1 = "/media/movies/Avengers Endgame/Avengers Endgame.nfo";
var path2 = "/media/movies/Avengers Endgame/movie.nfo";
// uses ContainingFolderPath which uses Operating system specific paths
if (MediaBrowser.Common.System.OperatingSystem.Id == OperatingSystemId.Windows)
{
movie.Path = movie.Path.Replace('/', '\\');
path1 = path1.Replace('/', '\\');
path2 = path2.Replace('/', '\\');
}
var paths = MovieNfoSaver.GetMovieSavePaths(new ItemInfo(movie)).ToArray();
Assert.Equal(2, paths.Length);
Assert.Contains(path1, paths);
Assert.Contains(path2, paths);
}
[Fact]
public void Movie_DVD_Success()
{
var movie = new Movie() { Path = "/media/movies/Avengers Endgame", VideoType = VideoType.Dvd };
var path1 = "/media/movies/Avengers Endgame/Avengers Endgame.nfo";
var path2 = "/media/movies/Avengers Endgame/VIDEO_TS/VIDEO_TS.nfo";
// uses ContainingFolderPath which uses Operating system specific paths
if (MediaBrowser.Common.System.OperatingSystem.Id == OperatingSystemId.Windows)
{
movie.Path = movie.Path.Replace('/', '\\');
path1 = path1.Replace('/', '\\');
path2 = path2.Replace('/', '\\');
}
var paths = MovieNfoSaver.GetMovieSavePaths(new ItemInfo(movie)).ToArray();
Assert.Equal(2, paths.Length);
Assert.Contains(path1, paths);
Assert.Contains(path2, paths);
}
}
}

View File

@ -66,6 +66,10 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Equal(2017, item.ProductionYear);
Assert.Single(item.Studios);
Assert.Contains("Starz", item.Studios);
Assert.Equal(1, item.IndexNumberEnd);
Assert.Equal(2, item.AirsAfterSeasonNumber);
Assert.Equal(3, item.AirsBeforeSeasonNumber);
Assert.Equal(1, item.AirsBeforeEpisodeNumber);
Assert.Equal("tt5017734", item.ProviderIds[MetadataProvider.Imdb.ToString()]);
Assert.Equal("1276153", item.ProviderIds[MetadataProvider.Tmdb.ToString()]);

View File

@ -4,6 +4,7 @@ using System.Threading;
using Jellyfin.Data.Entities;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
@ -60,11 +61,11 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
{
var result = new MetadataResult<Video>()
{
Item = new Video()
Item = new Movie()
};
_parser.Fetch(result, "Test Data/Justice League.nfo", CancellationToken.None);
var item = result.Item;
var item = (Movie)result.Item;
Assert.Equal("Justice League", item.OriginalTitle);
Assert.Equal("Justice for all.", item.Tagline);
@ -78,22 +79,31 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Contains("Sci-Fi", item.Genres);
Assert.Equal(new DateTime(2017, 11, 15), item.PremiereDate);
Assert.Equal(new DateTime(2017, 11, 16), item.EndDate);
Assert.Single(item.Studios);
Assert.Contains("DC Comics", item.Studios);
Assert.Equal("1.777778", item.AspectRatio);
Assert.Equal(Video3DFormat.HalfSideBySide, item.Video3DFormat);
Assert.Equal(1920, item.Width);
Assert.Equal(1080, item.Height);
Assert.Equal(new TimeSpan(0, 0, 6268).Ticks, item.RunTimeTicks);
Assert.True(item.HasSubtitles);
Assert.Equal(7.6f, item.CriticRating);
Assert.Equal("8.7", item.CustomRating);
Assert.Equal("en", item.PreferredMetadataLanguage);
Assert.Equal("us", item.PreferredMetadataCountryCode);
Assert.Single(item.RemoteTrailers);
Assert.Equal("https://www.youtube.com/watch?v=dQw4w9WgXcQ", item.RemoteTrailers[0].Url);
Assert.Equal(19, result.People.Count);
Assert.Equal(20, result.People.Count);
var writers = result.People.Where(x => x.Type == PersonType.Writer).ToArray();
Assert.Equal(2, writers.Length);
Assert.Equal(3, writers.Length);
var writerNames = writers.Select(x => x.Name);
Assert.Contains("Jerry Siegel", writerNames);
Assert.Contains("Joe Shuster", writerNames);
Assert.Contains("Test", writerNames);
var directors = result.People.Where(x => x.Type == PersonType.Director).ToArray();
Assert.Single(directors);
@ -120,6 +130,26 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Equal(2, userData.PlayCount);
Assert.True(userData.Played);
Assert.Equal(new DateTime(2021, 02, 11, 07, 47, 23), userData.LastPlayedDate);
// Movie set
Assert.Equal("702342", item.ProviderIds[MetadataProvider.TmdbCollection.ToString()]);
Assert.Equal("Justice League Collection", item.CollectionName);
}
[Theory]
[InlineData("Test Data/Tmdb.nfo", "Tmdb", "30287")]
[InlineData("Test Data/Imdb.nfo", "Imdb", "tt0944947")]
public void Parse_UrlFile_Success(string path, string provider, string id)
{
var result = new MetadataResult<Video>()
{
Item = new Movie()
};
_parser.Fetch(result, path, CancellationToken.None);
var item = (Movie)result.Item;
Assert.Equal(id, item.ProviderIds[provider]);
}
[Fact]
@ -135,7 +165,7 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
{
var result = new MetadataResult<Video>()
{
Item = new Video()
Item = new Movie()
};
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, string.Empty, CancellationToken.None));

View File

@ -0,0 +1,73 @@
using System;
using System.Linq;
using System.Threading;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
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 MusicVideoNfoParserTests
{
private readonly MovieNfoParser _parser;
public MusicVideoNfoParserTests()
{
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());
var user = new Mock<IUserManager>();
var userData = new Mock<IUserDataManager>();
_parser = new MovieNfoParser(new NullLogger<BaseNfoParser<MusicVideo>>(), config.Object, providerManager.Object, user.Object, userData.Object);
}
[Fact]
public void Fetch_Valid_Succes()
{
var result = new MetadataResult<Video>()
{
Item = new MusicVideo()
};
_parser.Fetch(result, "Test Data/Dancing Queen.nfo", CancellationToken.None);
var item = (MusicVideo)result.Item;
Assert.Equal("Dancing Queen", item.Name);
Assert.Single(item.Artists);
Assert.Contains("ABBA", item.Artists);
Assert.Equal("Arrival", item.Album);
}
[Fact]
public void Fetch_WithNullItem_ThrowsArgumentException()
{
var result = new MetadataResult<Video>();
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, "Test Data/Dancing Queen.nfo", CancellationToken.None));
}
[Fact]
public void Fetch_NullResult_ThrowsArgumentException()
{
var result = new MetadataResult<Video>()
{
Item = new MusicVideo()
};
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, string.Empty, CancellationToken.None));
}
}
}

View File

@ -49,6 +49,7 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Equal(0, item.RunTimeTicks);
Assert.Equal("46639", item.ProviderIds[MetadataProvider.Tmdb.ToString()]);
Assert.Equal("253573", item.ProviderIds[MetadataProvider.Tvdb.ToString()]);
Assert.Equal("tt11111", item.ProviderIds[MetadataProvider.Imdb.ToString()]);
Assert.Equal(3, item.Genres.Length);
Assert.Contains("Drama", item.Genres);
@ -58,6 +59,10 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Equal(new DateTime(2017, 4, 30), item.PremiereDate);
Assert.Single(item.Studios);
Assert.Contains("Starz", item.Studios);
Assert.Equal("9 PM", item.AirTime);
Assert.Single(item.AirDays);
Assert.Contains(DayOfWeek.Friday, item.AirDays);
Assert.Equal(SeriesStatus.Ended, item.Status);
Assert.Equal(6, result.People.Count);
@ -73,6 +78,21 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Equal(new DateTime(2017, 10, 7, 14, 25, 47), item.DateCreated);
}
[Theory]
[InlineData("Test Data/Tvdb.nfo", "Tvdb", "121361")]
public void Parse_UrlFile_Success(string path, string provider, string id)
{
var result = new MetadataResult<Series>()
{
Item = new Series()
};
_parser.Fetch(result, path, CancellationToken.None);
var item = (Series)result.Item;
Assert.Equal(id, item.ProviderIds[provider]);
}
[Fact]
public void Fetch_WithNullItem_ThrowsArgumentException()
{

View File

@ -126,7 +126,7 @@
<episodeguide>
<url cache="tmdb-46639-en.json">http://api.themoviedb.org/3/tv/46639?api_key=6a5be4999abf74eba1f9a8311294c267&amp;language=en</url>
</episodeguide>
<id>46639</id>
<id IMDB="tt11111" TMDB="46639">253573</id>
<uniqueid type="tmdb" default="true">46639</uniqueid>
<uniqueid type="tvdb">253573</uniqueid>
<genre>Drama</genre>
@ -134,7 +134,9 @@
<genre>Sci-Fi &amp; Fantasy</genre>
<premiered>2017-04-30</premiered>
<year>2017</year>
<status></status>
<status>ended</status>
<airs_time>9 PM</airs_time>
<airs_dayofweek>Friday</airs_dayofweek>
<code></code>
<aired></aired>
<studio>Starz</studio>

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<musicvideo>
<title>Dancing Queen</title>
<userrating>0</userrating>
<top250>0</top250>
<track>3</track>
<album>Arrival</album>
<outline></outline>
<plot>Dancing Queen est un des tubes emblématiques de l&apos;ère disco produits par le groupe suédois ABBA en 1976. Ce tube connaît un regain de popularité en 1994 lors de la sortie de Priscilla, folle du désert, et fait « presque » partie de la distribution du film Muriel.&#x0A;Le groupe a également enregistré une version espagnole de ce titre, La reina del baile, pour le marché d&apos;Amérique latine. On peut retrouver ces versions en espagnol des succès de ABBA sur l&apos;abum Oro. Le 18 juin 1976, ABBA a interprété cette chanson lors d&apos;un spectacle télévisé organisé en l&apos;honneur du roi Charles XVI Gustave de Suède, qui venait de se marier. Le titre sera repris en 2011 par Glee dans la saison 2, épisode 20.</plot>
<tagline></tagline>
<runtime>2</runtime>
<thumb preview="https://www.theaudiodb.com/images/media/album/thumb/arrival-4ee244732bbde.jpg/preview">https://www.theaudiodb.com/images/media/album/thumb/arrival-4ee244732bbde.jpg</thumb>
<thumb preview="https://assets.fanart.tv/preview/music/d87e52c5-bb8d-4da8-b941-9f4928627dc8/albumcover/arrival-548ab7a698b49.jpg">https://assets.fanart.tv/fanart/music/d87e52c5-bb8d-4da8-b941-9f4928627dc8/albumcover/arrival-548ab7a698b49.jpg</thumb>
<mpaa></mpaa>
<playcount>0</playcount>
<lastplayed></lastplayed>
<id></id>
<genre>Pop</genre>
<director>John Smith</director>
<premiered>1976-01-01</premiered>
<year>1976</year>
<status></status>
<code></code>
<aired></aired>
<studio>Studio 54</studio>
<trailer></trailer>
<fileinfo>
<streamdetails>
<video>
<codec>hevc</codec>
<aspect>1.792230</aspect>
<width>716</width>
<height>568</height>
<durationinseconds>143</durationinseconds>
<stereomode></stereomode>
</video>
<audio>
<codec>ac3</codec>
<language>eng</language>
<channels>2</channels>
</audio>
</streamdetails>
</fileinfo>
<artist>ABBA</artist>
<resume>
<position>0.000000</position>
<total>0.000000</total>
</resume>
<dateadded>2018-09-10 09:46:06</dateadded>
</musicvideo>

View File

@ -0,0 +1 @@
https://www.imdb.com/title/tt0944947/

View File

@ -24,6 +24,11 @@
<votes>119873</votes>
</rating>
</ratings>
<criticrating>7.6</criticrating>
<language>en</language>
<countrycode>us</countrycode>
<customrating>8.7</customrating>
<aspectratio>1.777778</aspectratio>
<userrating>0</userrating>
<top250>0</top250>
<outline>Fueled by his restored faith in humanity and inspired by Superman&apos;s selfless act, Bruce Wayne enlists the help of his new-found ally, Diana Prince, to face an even greater enemy.</outline>
@ -94,20 +99,22 @@
<country>USA</country>
<country>Canada</country>
<country>UK</country>
<set>
<set tmdbcolid="702342">
<name>Justice League Collection</name>
<overview>Based on the DC Comics superhero team</overview>
</set>
<credits>Jerry Siegel</credits>
<credits>Joe Shuster</credits>
<director>Zack Snyder</director>
<director>Zack Snyder,</director>
<writer>Test</writer>
<premiered>2017-11-15</premiered>
<enddate>2017-11-16</enddate>
<year>2017</year>
<status></status>
<code></code>
<aired></aired>
<studio>DC Comics</studio>
<trailer></trailer>
<trailer>plugin://plugin.video.youtube/?action=play_video&amp;videoid=dQw4w9WgXcQ</trailer>
<fileinfo>
<streamdetails>
<video>
@ -117,6 +124,7 @@
<height>1080</height>
<durationinseconds>6268</durationinseconds>
<stereomode></stereomode>
<format3d>HSBS</format3d>
</video>
<audio>
<codec>truehd</codec>

View File

@ -14,6 +14,10 @@
<episode>1</episode>
<displayseason>-1</displayseason>
<displayepisode>-1</displayepisode>
<episodenumberend>1</episodenumberend>
<airsbefore_episode>1</airsbefore_episode>
<airsafter_season>2</airsafter_season>
<airsbefore_season>3</airsbefore_season>
<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>

View File

@ -0,0 +1 @@
https://www.themoviedb.org/movie/30287-fallo

View File

@ -0,0 +1 @@
https://www.thetvdb.com/?tab=series&id=121361