2021-01-09 15:00:59 +01:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
2021-02-11 13:36:35 +01:00
|
|
|
using Jellyfin.Data.Entities;
|
2021-01-09 15:00:59 +01:00
|
|
|
using MediaBrowser.Common.Configuration;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2021-02-13 22:41:12 +01:00
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
2021-02-09 12:42:55 +01:00
|
|
|
using MediaBrowser.Controller.Library;
|
2021-01-09 15:00:59 +01:00
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Configuration;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.Providers;
|
2021-02-09 11:19:19 +01:00
|
|
|
using MediaBrowser.Providers.Plugins.Tmdb.Movies;
|
2021-01-09 15:00:59 +01:00
|
|
|
using MediaBrowser.XbmcMetadata.Parsers;
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
using Moq;
|
|
|
|
using Xunit;
|
|
|
|
|
2021-01-20 19:46:44 +01:00
|
|
|
namespace Jellyfin.XbmcMetadata.Tests.Parsers
|
2021-01-09 15:00:59 +01:00
|
|
|
{
|
|
|
|
public class MovieNfoParserTests
|
|
|
|
{
|
2021-01-09 20:14:50 +01:00
|
|
|
private readonly MovieNfoParser _parser;
|
2021-02-11 13:36:35 +01:00
|
|
|
private readonly IUserDataManager _userDataManager;
|
|
|
|
private readonly User _testUser;
|
2021-01-09 20:14:50 +01:00
|
|
|
|
|
|
|
public MovieNfoParserTests()
|
2021-01-09 15:00:59 +01:00
|
|
|
{
|
2021-02-11 13:36:35 +01:00
|
|
|
_testUser = new User("Test User", "Auth provider", "Reset provider");
|
|
|
|
|
2021-01-09 15:00:59 +01:00
|
|
|
var providerManager = new Mock<IProviderManager>();
|
2021-02-09 11:19:19 +01:00
|
|
|
|
|
|
|
var tmdbExternalId = new TmdbMovieExternalId();
|
|
|
|
var externalIdInfo = new ExternalIdInfo(tmdbExternalId.ProviderName, tmdbExternalId.Key, tmdbExternalId.Type, tmdbExternalId.UrlFormatString);
|
|
|
|
|
2021-01-09 15:00:59 +01:00
|
|
|
providerManager.Setup(x => x.GetExternalIdInfos(It.IsAny<IHasProviderIds>()))
|
2021-02-09 11:19:19 +01:00
|
|
|
.Returns(new[] { externalIdInfo });
|
|
|
|
|
2021-02-11 13:36:35 +01:00
|
|
|
var nfoConfig = new XbmcMetadataOptions()
|
|
|
|
{
|
|
|
|
UserId = "F38E6443-090B-4F7A-BD12-9CFF5020F7BC"
|
|
|
|
};
|
|
|
|
var configManager = new Mock<IConfigurationManager>();
|
|
|
|
configManager.Setup(x => x.GetConfiguration(It.IsAny<string>()))
|
|
|
|
.Returns(nfoConfig);
|
|
|
|
|
2021-02-09 12:42:55 +01:00
|
|
|
var user = new Mock<IUserManager>();
|
2021-02-11 13:36:35 +01:00
|
|
|
user.Setup(x => x.GetUserById(It.IsAny<Guid>()))
|
|
|
|
.Returns(_testUser);
|
|
|
|
|
2021-02-09 12:42:55 +01:00
|
|
|
var userData = new Mock<IUserDataManager>();
|
2021-02-11 13:36:35 +01:00
|
|
|
userData.Setup(x => x.GetUserData(_testUser, It.IsAny<BaseItem>()))
|
|
|
|
.Returns(new UserItemData());
|
2021-02-09 12:42:55 +01:00
|
|
|
|
2021-02-11 13:36:35 +01:00
|
|
|
_userDataManager = userData.Object;
|
|
|
|
_parser = new MovieNfoParser(new NullLogger<MovieNfoParser>(), configManager.Object, providerManager.Object, user.Object, userData.Object);
|
2021-01-09 20:14:50 +01:00
|
|
|
}
|
2021-01-09 15:00:59 +01:00
|
|
|
|
2021-01-09 20:14:50 +01:00
|
|
|
[Fact]
|
2021-02-09 07:21:08 +01:00
|
|
|
public void Fetch_Valid_Success()
|
2021-01-09 20:14:50 +01:00
|
|
|
{
|
2021-01-09 15:00:59 +01:00
|
|
|
var result = new MetadataResult<Video>()
|
|
|
|
{
|
2021-02-13 22:41:12 +01:00
|
|
|
Item = new Movie()
|
2021-01-09 15:00:59 +01:00
|
|
|
};
|
2021-01-09 20:14:50 +01:00
|
|
|
|
|
|
|
_parser.Fetch(result, "Test Data/Justice League.nfo", CancellationToken.None);
|
2021-02-13 22:41:12 +01:00
|
|
|
var item = (Movie)result.Item;
|
2021-01-09 15:00:59 +01:00
|
|
|
|
|
|
|
Assert.Equal("Justice League", item.OriginalTitle);
|
|
|
|
Assert.Equal("Justice for all.", item.Tagline);
|
2021-02-09 11:19:19 +01:00
|
|
|
Assert.Equal("tt0974015", item.ProviderIds[MetadataProvider.Imdb.ToString()]);
|
|
|
|
Assert.Equal("141052", item.ProviderIds[MetadataProvider.Tmdb.ToString()]);
|
2021-01-09 15:00:59 +01:00
|
|
|
|
|
|
|
Assert.Equal(4, item.Genres.Length);
|
|
|
|
Assert.Contains("Action", item.Genres);
|
|
|
|
Assert.Contains("Adventure", item.Genres);
|
|
|
|
Assert.Contains("Fantasy", item.Genres);
|
|
|
|
Assert.Contains("Sci-Fi", item.Genres);
|
|
|
|
|
|
|
|
Assert.Equal(new DateTime(2017, 11, 15), item.PremiereDate);
|
2021-02-13 22:41:12 +01:00
|
|
|
Assert.Equal(new DateTime(2017, 11, 16), item.EndDate);
|
2021-01-09 15:00:59 +01:00
|
|
|
Assert.Single(item.Studios);
|
|
|
|
Assert.Contains("DC Comics", item.Studios);
|
|
|
|
|
|
|
|
Assert.Equal("1.777778", item.AspectRatio);
|
2021-02-13 22:41:12 +01:00
|
|
|
Assert.Equal(Video3DFormat.HalfSideBySide, item.Video3DFormat);
|
2021-01-09 15:00:59 +01:00
|
|
|
Assert.Equal(1920, item.Width);
|
|
|
|
Assert.Equal(1080, item.Height);
|
|
|
|
Assert.Equal(new TimeSpan(0, 0, 6268).Ticks, item.RunTimeTicks);
|
|
|
|
Assert.True(item.HasSubtitles);
|
2021-02-13 22:41:12 +01:00
|
|
|
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);
|
2021-01-09 15:00:59 +01:00
|
|
|
|
2021-02-13 22:41:12 +01:00
|
|
|
Assert.Equal(20, result.People.Count);
|
2021-01-09 15:00:59 +01:00
|
|
|
|
|
|
|
var writers = result.People.Where(x => x.Type == PersonType.Writer).ToArray();
|
2021-02-13 22:41:12 +01:00
|
|
|
Assert.Equal(3, writers.Length);
|
2021-01-09 15:00:59 +01:00
|
|
|
var writerNames = writers.Select(x => x.Name);
|
|
|
|
Assert.Contains("Jerry Siegel", writerNames);
|
|
|
|
Assert.Contains("Joe Shuster", writerNames);
|
2021-02-13 22:41:12 +01:00
|
|
|
Assert.Contains("Test", writerNames);
|
2021-01-09 15:00:59 +01:00
|
|
|
|
|
|
|
var directors = result.People.Where(x => x.Type == PersonType.Director).ToArray();
|
|
|
|
Assert.Single(directors);
|
|
|
|
Assert.Equal("Zack Snyder", directors[0].Name);
|
|
|
|
|
|
|
|
var actors = result.People.Where(x => x.Type == PersonType.Actor).ToArray();
|
|
|
|
Assert.Equal(15, actors.Length);
|
|
|
|
|
|
|
|
// Only test one actor
|
|
|
|
var aquaman = actors.FirstOrDefault(x => x.Role.Equals("Aquaman", StringComparison.Ordinal));
|
|
|
|
Assert.NotNull(aquaman);
|
|
|
|
Assert.Equal("Jason Momoa", aquaman!.Name);
|
|
|
|
Assert.Equal(5, aquaman!.SortOrder);
|
|
|
|
Assert.Equal("https://m.media-amazon.com/images/M/MV5BMTI5MTU5NjM1MV5BMl5BanBnXkFtZTcwODc4MDk0Mw@@._V1_SX1024_SY1024_.jpg", aquaman!.ImageUrl);
|
2021-01-09 20:14:50 +01:00
|
|
|
|
2021-01-23 18:06:26 +01:00
|
|
|
var lyricist = result.People.FirstOrDefault(x => x.Type == PersonType.Lyricist);
|
|
|
|
Assert.NotNull(lyricist);
|
|
|
|
Assert.Equal("Test Lyricist", lyricist!.Name);
|
|
|
|
|
2021-01-09 20:14:50 +01:00
|
|
|
Assert.Equal(new DateTime(2019, 8, 6, 9, 1, 18), item.DateCreated);
|
2021-02-13 22:41:12 +01:00
|
|
|
|
2021-02-11 13:36:35 +01:00
|
|
|
// userData
|
|
|
|
var userData = _userDataManager.GetUserData(_testUser, item);
|
|
|
|
Assert.Equal(2, userData.PlayCount);
|
|
|
|
Assert.True(userData.Played);
|
|
|
|
Assert.Equal(new DateTime(2021, 02, 11, 07, 47, 23), userData.LastPlayedDate);
|
2021-02-15 12:00:51 +01:00
|
|
|
|
2021-02-13 22:41:12 +01:00
|
|
|
// Movie set
|
|
|
|
Assert.Equal("702342", item.ProviderIds[MetadataProvider.TmdbCollection.ToString()]);
|
|
|
|
Assert.Equal("Justice League Collection", item.CollectionName);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
2021-02-15 11:39:00 +01:00
|
|
|
[InlineData("Test Data/Tmdb.nfo", "Tmdb", "30287")]
|
|
|
|
[InlineData("Test Data/Imdb.nfo", "Imdb", "tt0944947")]
|
2021-02-13 22:41:12 +01:00
|
|
|
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]);
|
2021-01-09 20:14:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void Fetch_WithNullItem_ThrowsArgumentException()
|
|
|
|
{
|
|
|
|
var result = new MetadataResult<Video>();
|
|
|
|
|
|
|
|
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, "Test Data/Justice League.nfo", CancellationToken.None));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void Fetch_NullResult_ThrowsArgumentException()
|
|
|
|
{
|
|
|
|
var result = new MetadataResult<Video>()
|
|
|
|
{
|
2021-02-13 22:41:12 +01:00
|
|
|
Item = new Movie()
|
2021-01-09 20:14:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, string.Empty, CancellationToken.None));
|
2021-01-09 15:00:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|