Skip to content

Commit

Permalink
feat: support collection metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
cxfksword committed Sep 4, 2024
1 parent 025a42e commit 90dcea6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
50 changes: 50 additions & 0 deletions Jellyfin.Plugin.MetaShark.Test/BoxSetProviderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Jellyfin.Plugin.MetaShark.Api;
using Jellyfin.Plugin.MetaShark.Core;
using Jellyfin.Plugin.MetaShark.Providers;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Moq;

namespace Jellyfin.Plugin.MetaShark.Test
{
[TestClass]
public class BoxSetProviderTest
{

ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
builder.AddSimpleConsole(options =>
{
options.IncludeScopes = true;
options.SingleLine = true;
options.TimestampFormat = "hh:mm:ss ";
}));


[TestMethod]
public void TestGetMetadata()
{
var info = new BoxSetInfo() { Name = "攻壳机动队(系列)", MetadataLanguage = "zh" };
var httpClientFactory = new DefaultHttpClientFactory();
var libraryManagerStub = new Mock<ILibraryManager>();
libraryManagerStub.Setup(x => x.ParseName(info.Name)).Returns(new ItemLookupInfo(){Name = info.Name});
var httpContextAccessorStub = new Mock<IHttpContextAccessor>();
var doubanApi = new DoubanApi(loggerFactory);
var tmdbApi = new TmdbApi(loggerFactory);
var omdbApi = new OmdbApi(loggerFactory);
var imdbApi = new ImdbApi(loggerFactory);

Task.Run(async () =>
{
var provider = new BoxSetProvider(httpClientFactory, loggerFactory, libraryManagerStub.Object, httpContextAccessorStub.Object, doubanApi, tmdbApi, omdbApi, imdbApi);
var result = await provider.GetMetadata(info, CancellationToken.None);
Assert.IsNotNull(result);

var str = result.ToJson();
Console.WriteLine(result.ToJson());
}).GetAwaiter().GetResult();
}

}
}
19 changes: 5 additions & 14 deletions Jellyfin.Plugin.MetaShark/Providers/BoxSetProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Plugin.MetaShark.Api;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
Expand Down Expand Up @@ -98,7 +96,11 @@ public async Task<MetadataResult<BoxSet>> GetMetadata(BoxSetInfo info, Cancellat

if (searchResults is not null && searchResults.Count > 0)
{
tmdbId = searchResults[0].Id;
tmdbId = searchResults.FirstOrDefault(x => x.Name == info.Name)?.Id ?? 0;
if (tmdbId <= 0)
{
tmdbId = searchResults[0].Id;
}
}
}

Expand All @@ -116,17 +118,6 @@ public async Task<MetadataResult<BoxSet>> GetMetadata(BoxSetInfo info, Cancellat
Overview = collection.Overview,
};

var oldBotSet = _libraryManager.GetItemList(new InternalItemsQuery
{
IncludeItemTypes = new[] { BaseItemKind.BoxSet },
CollapseBoxSetItems = false,
Recursive = true
}).Select(b => b as BoxSet).FirstOrDefault(x => x.Name == collection.Name);
if (oldBotSet != null)
{
item.LinkedChildren = oldBotSet.LinkedChildren;
}

item.SetProviderId(MetadataProvider.Tmdb, collection.Id.ToString(CultureInfo.InvariantCulture));

result.HasMetadata = true;
Expand Down

0 comments on commit 90dcea6

Please sign in to comment.