Delete tvdb and tmdb providers

This commit is contained in:
Zoe Roux
2023-03-18 23:59:11 +09:00
parent 505ebb48bc
commit dca91feff8
22 changed files with 0 additions and 2173 deletions
@@ -1,210 +0,0 @@
// Kyoo - A portable and vast media library solution.
// Copyright (c) Kyoo.
//
// See AUTHORS.md and LICENSE file in the project root for full license information.
//
// Kyoo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Kyoo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
using System.Threading.Tasks;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models;
using Kyoo.Abstractions.Models.Exceptions;
using Kyoo.Core.Controllers;
using Kyoo.Core.Models.Options;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
namespace Kyoo.Tests.Identifier
{
public class Identifier
{
private readonly Mock<ILibraryManager> _manager;
private readonly IIdentifier _identifier;
public Identifier()
{
Mock<IOptionsMonitor<MediaOptions>> options = new();
options.Setup(x => x.CurrentValue).Returns(new MediaOptions
{
Regex = new[]
{
"^\\/?(?<Collection>.+)?\\/(?<Show>.+?)(?: \\((?<StartYear>\\d+)\\))?\\/\\k<Show>(?: \\(\\d+\\))? S(?<Season>\\d+)E(?<Episode>\\d+)\\..*$",
"^\\/?(?<Collection>.+)?\\/(?<Show>.+?)(?: \\((?<StartYear>\\d+)\\))?\\/\\k<Show>(?: \\(\\d+\\))? (?<Absolute>\\d+)\\..*$",
"^\\/?(?<Collection>.+)?\\/(?<Show>.+?)(?: \\((?<StartYear>\\d+)\\))?\\/\\k<Show>(?: \\(\\d+\\))?\\..*$"
},
SubtitleRegex = new[]
{
"^(?<Episode>.+)\\.(?<Language>\\w{1,3})\\.(?<Default>default\\.)?(?<Forced>forced\\.)?.*$"
}
});
_manager = new Mock<ILibraryManager>();
_identifier = new RegexIdentifier(options.Object, _manager.Object);
}
[Fact]
public async Task EpisodeIdentification()
{
_manager.Setup(x => x.GetAll<Library>(null, default, default)).ReturnsAsync(new[]
{
new Library {Paths = new [] {"/kyoo/Library/"}}
});
(Collection collection, Show show, Season season, Episode episode) = await _identifier.Identify(
"/kyoo/Library/Collection/Show (2000)/Show S01E01.extension");
Assert.Equal("Collection", collection.Name);
Assert.Equal("collection", collection.Slug);
Assert.Equal("Show", show.Title);
Assert.Equal("show", show.Slug);
Assert.Equal(2000, show.StartAir!.Value.Year);
Assert.Equal(1, season.SeasonNumber);
Assert.Equal(1, episode.SeasonNumber);
Assert.Equal(1, episode.EpisodeNumber);
Assert.Null(episode.AbsoluteNumber);
}
[Fact]
public async Task EpisodeIdentificationWithoutLibraryTrailingSlash()
{
_manager.Setup(x => x.GetAll<Library>(null, default, default)).ReturnsAsync(new[]
{
new Library {Paths = new [] {"/kyoo/Library"}}
});
(Collection collection, Show show, Season season, Episode episode) = await _identifier.Identify(
"/kyoo/Library/Collection/Show (2000)/Show S01E01.extension");
Assert.Equal("Collection", collection.Name);
Assert.Equal("collection", collection.Slug);
Assert.Equal("Show", show.Title);
Assert.Equal("show", show.Slug);
Assert.Equal(2000, show.StartAir!.Value.Year);
Assert.Equal(1, season.SeasonNumber);
Assert.Equal(1, episode.SeasonNumber);
Assert.Equal(1, episode.EpisodeNumber);
Assert.Null(episode.AbsoluteNumber);
}
[Fact]
public async Task EpisodeIdentificationMultiplePaths()
{
_manager.Setup(x => x.GetAll<Library>(null, default, default)).ReturnsAsync(new[]
{
new Library {Paths = new [] {"/kyoo", "/kyoo/Library/"}}
});
(Collection collection, Show show, Season season, Episode episode) = await _identifier.Identify(
"/kyoo/Library/Collection/Show (2000)/Show S01E01.extension");
Assert.Equal("Collection", collection.Name);
Assert.Equal("collection", collection.Slug);
Assert.Equal("Show", show.Title);
Assert.Equal("show", show.Slug);
Assert.Equal(2000, show.StartAir!.Value.Year);
Assert.Equal(1, season.SeasonNumber);
Assert.Equal(1, episode.SeasonNumber);
Assert.Equal(1, episode.EpisodeNumber);
Assert.Null(episode.AbsoluteNumber);
}
[Fact]
public async Task AbsoluteEpisodeIdentification()
{
_manager.Setup(x => x.GetAll<Library>(null, default, default)).ReturnsAsync(new[]
{
new Library {Paths = new [] {"/kyoo", "/kyoo/Library/"}}
});
(Collection collection, Show show, Season season, Episode episode) = await _identifier.Identify(
"/kyoo/Library/Collection/Show (2000)/Show 100.extension");
Assert.Equal("Collection", collection.Name);
Assert.Equal("collection", collection.Slug);
Assert.Equal("Show", show.Title);
Assert.Equal("show", show.Slug);
Assert.Equal(2000, show.StartAir!.Value.Year);
Assert.Null(season);
Assert.Null(episode.SeasonNumber);
Assert.Null(episode.EpisodeNumber);
Assert.Equal(100, episode.AbsoluteNumber);
}
[Fact]
public async Task MovieEpisodeIdentification()
{
_manager.Setup(x => x.GetAll<Library>(null, default, default)).ReturnsAsync(new[]
{
new Library {Paths = new [] {"/kyoo", "/kyoo/Library/"}}
});
(Collection collection, Show show, Season season, Episode episode) = await _identifier.Identify(
"/kyoo/Library/Collection/Show (2000)/Show.extension");
Assert.Equal("Collection", collection.Name);
Assert.Equal("collection", collection.Slug);
Assert.Equal("Show", show.Title);
Assert.Equal("show", show.Slug);
Assert.Equal(2000, show.StartAir!.Value.Year);
Assert.Null(season);
Assert.True(show.IsMovie);
Assert.Null(episode.SeasonNumber);
Assert.Null(episode.EpisodeNumber);
Assert.Null(episode.AbsoluteNumber);
}
[Fact]
public async Task InvalidEpisodeIdentification()
{
_manager.Setup(x => x.GetAll<Library>(null, default, default)).ReturnsAsync(new[]
{
new Library {Paths = new [] {"/kyoo", "/kyoo/Library/"}}
});
await Assert.ThrowsAsync<IdentificationFailedException>(() => _identifier.Identify("/invalid/path"));
}
[Fact]
public async Task SubtitleIdentification()
{
_manager.Setup(x => x.GetAll<Library>(null, default, default)).ReturnsAsync(new[]
{
new Library {Paths = new [] {"/kyoo", "/kyoo/Library/"}}
});
Track track = await _identifier.IdentifyTrack("/kyoo/Library/Collection/Show (2000)/Show.eng.default.str");
Assert.True(track.IsExternal);
Assert.Equal("eng", track.Language);
Assert.Equal("subrip", track.Codec);
Assert.True(track.IsDefault);
Assert.False(track.IsForced);
Assert.StartsWith("/kyoo/Library/Collection/Show (2000)/Show", track.Episode.Path);
}
[Fact]
public async Task SubtitleIdentificationUnknownCodec()
{
_manager.Setup(x => x.GetAll<Library>(null, default, default)).ReturnsAsync(new[]
{
new Library {Paths = new [] {"/kyoo", "/kyoo/Library/"}}
});
Track track = await _identifier.IdentifyTrack("/kyoo/Library/Collection/Show (2000)/Show.eng.default.extension");
Assert.True(track.IsExternal);
Assert.Equal("eng", track.Language);
Assert.Equal("extension", track.Codec);
Assert.True(track.IsDefault);
Assert.False(track.IsForced);
Assert.StartsWith("/kyoo/Library/Collection/Show (2000)/Show", track.Episode.Path);
}
[Fact]
public async Task InvalidSubtitleIdentification()
{
_manager.Setup(x => x.GetAll<Library>(null, default, default)).ReturnsAsync(new[]
{
new Library {Paths = new [] {"/kyoo", "/kyoo/Library/"}}
});
await Assert.ThrowsAsync<IdentificationFailedException>(() => _identifier.IdentifyTrack("/invalid/path"));
}
}
}
@@ -1,143 +0,0 @@
// Kyoo - A portable and vast media library solution.
// Copyright (c) Kyoo.
//
// See AUTHORS.md and LICENSE file in the project root for full license information.
//
// Kyoo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Kyoo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models;
using Kyoo.Core.Controllers;
using Microsoft.Extensions.Logging;
using Moq;
using Xunit;
using Xunit.Abstractions;
namespace Kyoo.Tests.Identifier
{
public class ProviderTests
{
private readonly ILoggerFactory _factory;
public ProviderTests(ITestOutputHelper output)
{
_factory = LoggerFactory.Create(x =>
{
x.ClearProviders();
x.AddXunit(output);
});
}
[Fact]
public async Task NoProviderGetTest()
{
AProviderComposite provider = new ProviderComposite(Array.Empty<IMetadataProvider>(),
_factory.CreateLogger<ProviderComposite>());
Show show = new()
{
ID = 4,
Genres = new[] { new Genre("genre") }
};
Show ret = await provider.Get(show);
KAssert.DeepEqual(show, ret);
}
[Fact]
public async Task NoProviderSearchTest()
{
AProviderComposite provider = new ProviderComposite(Array.Empty<IMetadataProvider>(),
_factory.CreateLogger<ProviderComposite>());
ICollection<Show> ret = await provider.Search<Show>("show");
Assert.Empty(ret);
}
[Fact]
public async Task OneProviderGetTest()
{
Show show = new()
{
ID = 4,
Genres = new[] { new Genre("genre") }
};
Mock<IMetadataProvider> mock = new();
mock.Setup(x => x.Get(show)).ReturnsAsync(new Show
{
Title = "title",
Genres = new[] { new Genre("ToMerge") }
});
AProviderComposite provider = new ProviderComposite(new[]
{
mock.Object
},
_factory.CreateLogger<ProviderComposite>());
Show ret = await provider.Get(show);
Assert.Equal(4, ret.ID);
Assert.Equal("title", ret.Title);
Assert.Equal(2, ret.Genres.Count);
Assert.Contains("genre", ret.Genres.Select(x => x.Slug));
Assert.Contains("tomerge", ret.Genres.Select(x => x.Slug));
}
[Fact]
public async Task FailingProviderGetTest()
{
Show show = new()
{
ID = 4,
Genres = new[] { new Genre("genre") }
};
Mock<IMetadataProvider> mock = new();
mock.Setup(x => x.Provider).Returns(new Provider("mock", string.Empty));
mock.Setup(x => x.Get(show)).ReturnsAsync(new Show
{
Title = "title",
Genres = new[] { new Genre("ToMerge") }
});
Mock<IMetadataProvider> mockTwo = new();
mockTwo.Setup(x => x.Provider).Returns(new Provider("mockTwo", string.Empty));
mockTwo.Setup(x => x.Get(show)).ReturnsAsync(new Show
{
Title = "title2",
Status = Status.Finished,
Genres = new[] { new Genre("ToMerge") }
});
Mock<IMetadataProvider> mockFailing = new();
mockFailing.Setup(x => x.Provider).Returns(new Provider("mockFail", string.Empty));
mockFailing.Setup(x => x.Get(show)).Throws<ArgumentException>();
AProviderComposite provider = new ProviderComposite(new[]
{
mock.Object,
mockTwo.Object,
mockFailing.Object
},
_factory.CreateLogger<ProviderComposite>());
Show ret = await provider.Get(show);
Assert.Equal(4, ret.ID);
Assert.Equal("title", ret.Title);
Assert.Equal(Status.Finished, ret.Status);
Assert.Equal(2, ret.Genres.Count);
Assert.Contains("genre", ret.Genres.Select(x => x.Slug));
Assert.Contains("tomerge", ret.Genres.Select(x => x.Slug));
}
}
}
@@ -1,177 +0,0 @@
// Kyoo - A portable and vast media library solution.
// Copyright (c) Kyoo.
//
// See AUTHORS.md and LICENSE file in the project root for full license information.
//
// Kyoo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Kyoo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
using System;
using System.Linq;
using Kyoo.Abstractions.Models;
using Kyoo.TheTvdb;
using TvDbSharper.Dto;
using Xunit;
namespace Kyoo.Tests.Identifier.Tvdb
{
public class ConvertorTests
{
[Fact]
public void SeriesSearchToShow()
{
SeriesSearchResult result = new()
{
Slug = "slug",
SeriesName = "name",
Aliases = new[] { "Aliases" },
Overview = "overview",
Status = "Ended",
FirstAired = "2021-07-23",
Poster = "/poster",
Id = 5
};
Provider provider = TestSample.Get<Provider>();
Show show = result.ToShow(provider);
Assert.Equal("slug", show.Slug);
Assert.Equal("name", show.Title);
Assert.Single(show.Aliases);
Assert.Equal("Aliases", show.Aliases[0]);
Assert.Equal("overview", show.Overview);
Assert.Equal(new DateTime(2021, 7, 23), show.StartAir);
Assert.Equal("https://www.thetvdb.com/poster", show.Images[Images.Poster]);
Assert.Single(show.ExternalIDs);
Assert.Equal("5", show.ExternalIDs.First().DataID);
Assert.Equal(provider, show.ExternalIDs.First().Provider);
Assert.Equal("https://www.thetvdb.com/series/slug", show.ExternalIDs.First().Link);
Assert.Equal(Status.Finished, show.Status);
}
[Fact]
public void SeriesSearchToShowInvalidDate()
{
SeriesSearchResult result = new()
{
Slug = "slug",
SeriesName = "name",
Aliases = new[] { "Aliases" },
Overview = "overview",
Status = "ad",
FirstAired = "2e021-07-23",
Poster = "/poster",
Id = 5
};
Provider provider = TestSample.Get<Provider>();
Show show = result.ToShow(provider);
Assert.Equal("slug", show.Slug);
Assert.Equal("name", show.Title);
Assert.Single(show.Aliases);
Assert.Equal("Aliases", show.Aliases[0]);
Assert.Equal("overview", show.Overview);
Assert.Null(show.StartAir);
Assert.Equal("https://www.thetvdb.com/poster", show.Images[Images.Poster]);
Assert.Single(show.ExternalIDs);
Assert.Equal("5", show.ExternalIDs.First().DataID);
Assert.Equal(provider, show.ExternalIDs.First().Provider);
Assert.Equal("https://www.thetvdb.com/series/slug", show.ExternalIDs.First().Link);
Assert.Equal(Status.Unknown, show.Status);
}
[Fact]
public void SeriesToShow()
{
Series result = new()
{
Slug = "slug",
SeriesName = "name",
Aliases = new[] { "Aliases" },
Overview = "overview",
Status = "Continuing",
FirstAired = "2021-07-23",
Poster = "poster",
FanArt = "fanart",
Id = 5,
Genre = new[]
{
"Action",
"Test With Sp??acial characters"
}
};
Provider provider = TestSample.Get<Provider>();
Show show = result.ToShow(provider);
Assert.Equal("slug", show.Slug);
Assert.Equal("name", show.Title);
Assert.Single(show.Aliases);
Assert.Equal("Aliases", show.Aliases[0]);
Assert.Equal("overview", show.Overview);
Assert.Equal(new DateTime(2021, 7, 23), show.StartAir);
Assert.Equal("https://www.thetvdb.com/banners/poster", show.Images[Images.Poster]);
Assert.Equal("https://www.thetvdb.com/banners/fanart", show.Images[Images.Thumbnail]);
Assert.Single(show.ExternalIDs);
Assert.Equal("5", show.ExternalIDs.First().DataID);
Assert.Equal(provider, show.ExternalIDs.First().Provider);
Assert.Equal("https://www.thetvdb.com/series/slug", show.ExternalIDs.First().Link);
Assert.Equal(Status.Airing, show.Status);
Assert.Equal(2, show.Genres.Count);
Assert.Equal("action", show.Genres.ToArray()[0].Slug);
Assert.Equal("Action", show.Genres.ToArray()[0].Name);
Assert.Equal("Test With Sp??acial characters", show.Genres.ToArray()[1].Name);
Assert.Equal("test-with-spacial-characters", show.Genres.ToArray()[1].Slug);
}
[Fact]
public void ActorToPeople()
{
Actor actor = new()
{
Id = 5,
Image = "image",
Name = "Name",
Role = "role"
};
PeopleRole people = actor.ToPeopleRole();
Assert.Equal("name", people.Slug);
Assert.Equal("Name", people.People.Name);
Assert.Equal("role", people.Role);
Assert.Equal("https://www.thetvdb.com/banners/image", people.People.Images[Images.Poster]);
}
[Fact]
public void EpisodeRecordToEpisode()
{
EpisodeRecord record = new()
{
Id = 5,
AiredSeason = 2,
AiredEpisodeNumber = 3,
AbsoluteNumber = 23,
EpisodeName = "title",
Overview = "overview",
Filename = "thumb"
};
Provider provider = TestSample.Get<Provider>();
Episode episode = record.ToEpisode(provider);
Assert.Equal("title", episode.Title);
Assert.Equal(2, episode.SeasonNumber);
Assert.Equal(3, episode.EpisodeNumber);
Assert.Equal(23, episode.AbsoluteNumber);
Assert.Equal("overview", episode.Overview);
Assert.Equal("https://www.thetvdb.com/banners/thumb", episode.Images[Images.Thumbnail]);
}
}
}
-1
View File
@@ -31,6 +31,5 @@
<ItemGroup>
<ProjectReference Include="../../src/Kyoo.Abstractions/Kyoo.Abstractions.csproj" />
<ProjectReference Include="..\..\src\Kyoo.Host\Kyoo.Host.csproj" />
<ProjectReference Include="../../src/Kyoo.TheTvdb/Kyoo.TheTvdb.csproj" />
</ItemGroup>
</Project>