diff --git a/Jellyfin.Plugin.Bangumi.Test/Mock/MockedMediaSourceManager.cs b/Jellyfin.Plugin.Bangumi.Test/Mock/MockedMediaSourceManager.cs new file mode 100644 index 0000000..a2ff561 --- /dev/null +++ b/Jellyfin.Plugin.Bangumi.Test/Mock/MockedMediaSourceManager.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Jellyfin.Data.Entities; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.Persistence; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.MediaInfo; + +namespace Jellyfin.Plugin.Bangumi.Test.Mock; + +public class MockedMediaSourceManager : IMediaSourceManager +{ + public Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudio, string cacheKey, bool addProbeDelay, bool isLiveStream, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public void AddParts(IEnumerable providers) + { + throw new NotImplementedException(); + } + + public Task CloseLiveStream(string id) + { + throw new NotImplementedException(); + } + + public Task GetLiveStream(string id, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public ILiveStream GetLiveStreamInfo(string id) + { + throw new NotImplementedException(); + } + + public ILiveStream GetLiveStreamInfoByUniqueId(string uniqueId) + { + throw new NotImplementedException(); + } + + public Task GetLiveStreamMediaInfo(string id, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public Task> GetLiveStreamWithDirectStreamProvider(string id, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public List GetMediaAttachments(Guid itemId) + { + throw new NotImplementedException(); + } + + public List GetMediaAttachments(MediaAttachmentQuery query) + { + throw new NotImplementedException(); + } + + public Task GetMediaSource(BaseItem item, string mediaSourceId, string liveStreamId, bool enablePathSubstitution, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public List GetMediaStreams(Guid itemId) + { + throw new NotImplementedException(); + } + + public List GetMediaStreams(MediaStreamQuery query) + { + throw new NotImplementedException(); + } + + public MediaProtocol GetPathProtocol(string path) + { + throw new NotImplementedException(); + } + + public Task> GetPlaybackMediaSources(BaseItem item, User user, bool allowMediaProbe, bool enablePathSubstitution, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public Task> GetRecordingStreamMediaSources(ActiveRecordingInfo info, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public List GetStaticMediaSources(BaseItem item, bool enablePathSubstitution, User user = null) + { + return null; + } + + public Task OpenLiveStream(LiveStreamRequest request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public Task> OpenLiveStreamInternal(LiveStreamRequest request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public void SetDefaultAudioAndSubtitleStreamIndices(BaseItem item, MediaSourceInfo source, User user) + { + throw new NotImplementedException(); + } + + public bool SupportsDirectStream(string path, MediaProtocol protocol) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/Jellyfin.Plugin.Bangumi.Test/Util/ServiceLocator.cs b/Jellyfin.Plugin.Bangumi.Test/Util/ServiceLocator.cs index 15b0924..4bb6776 100644 --- a/Jellyfin.Plugin.Bangumi.Test/Util/ServiceLocator.cs +++ b/Jellyfin.Plugin.Bangumi.Test/Util/ServiceLocator.cs @@ -24,6 +24,7 @@ public static void Init(TestContext context) serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); serviceCollection.AddScoped(); serviceCollection.AddScoped(); serviceCollection.AddScoped(); diff --git a/Jellyfin.Plugin.Bangumi/Providers/EpisodeProvider.cs b/Jellyfin.Plugin.Bangumi/Providers/EpisodeProvider.cs index a9f1136..d173e62 100644 --- a/Jellyfin.Plugin.Bangumi/Providers/EpisodeProvider.cs +++ b/Jellyfin.Plugin.Bangumi/Providers/EpisodeProvider.cs @@ -17,7 +17,7 @@ namespace Jellyfin.Plugin.Bangumi.Providers; -public partial class EpisodeProvider(BangumiApi api, ILogger log, ILibraryManager libraryManager) +public partial class EpisodeProvider(BangumiApi api, ILogger log, ILibraryManager libraryManager, IMediaSourceManager mediaSourceManager) : IRemoteMetadataProvider, IHasOrder { private static readonly Regex[] NonEpisodeFileNameRegex = @@ -61,6 +61,14 @@ public partial class EpisodeProvider(BangumiApi api, ILogger lo public async Task> GetMetadata(EpisodeInfo info, CancellationToken token) { token.ThrowIfCancellationRequested(); + + var mediaSourceInfos = mediaSourceManager.GetStaticMediaSources(libraryManager.FindByPath(info.Path, false), false); + if (mediaSourceInfos is not null) + { + log.LogInformation("视频时长(分钟): " + TimeSpan.FromTicks(mediaSourceInfos[0].RunTimeTicks ?? 0).Minutes); + log.LogInformation("文件大小(MB): " + (mediaSourceInfos[0].Size ?? 0) / (1024 * 1024)); + } + var localConfiguration = await LocalConfiguration.ForPath(info.Path); var episode = await GetEpisode(info, localConfiguration, token);