Skip to content

Commit

Permalink
feat: feat-mediaSourceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
chu-shen committed Oct 8, 2024
1 parent 670bdb7 commit 6dc9387
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 1 deletion.
122 changes: 122 additions & 0 deletions Jellyfin.Plugin.Bangumi.Test/Mock/MockedMediaSourceManager.cs
Original file line number Diff line number Diff line change
@@ -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<IMediaSourceProvider> providers)
{
throw new NotImplementedException();
}

public Task CloseLiveStream(string id)
{
throw new NotImplementedException();
}

public Task<MediaSourceInfo> 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<MediaSourceInfo> GetLiveStreamMediaInfo(string id, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<Tuple<MediaSourceInfo, IDirectStreamProvider>> GetLiveStreamWithDirectStreamProvider(string id, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public List<MediaAttachment> GetMediaAttachments(Guid itemId)
{
throw new NotImplementedException();
}

public List<MediaAttachment> GetMediaAttachments(MediaAttachmentQuery query)
{
throw new NotImplementedException();
}

public Task<MediaSourceInfo> GetMediaSource(BaseItem item, string mediaSourceId, string liveStreamId, bool enablePathSubstitution, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public List<MediaStream> GetMediaStreams(Guid itemId)
{
throw new NotImplementedException();
}

public List<MediaStream> GetMediaStreams(MediaStreamQuery query)
{
throw new NotImplementedException();
}

public MediaProtocol GetPathProtocol(string path)
{
throw new NotImplementedException();
}

public Task<List<MediaSourceInfo>> GetPlaybackMediaSources(BaseItem item, User user, bool allowMediaProbe, bool enablePathSubstitution, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<List<MediaSourceInfo>> GetRecordingStreamMediaSources(ActiveRecordingInfo info, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public List<MediaSourceInfo> GetStaticMediaSources(BaseItem item, bool enablePathSubstitution, User user = null)
{
return null;
}

public Task<LiveStreamResponse> OpenLiveStream(LiveStreamRequest request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<Tuple<LiveStreamResponse, IDirectStreamProvider>> 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();
}
}
1 change: 1 addition & 0 deletions Jellyfin.Plugin.Bangumi.Test/Util/ServiceLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static void Init(TestContext context)
serviceCollection.AddSingleton<IXmlSerializer, MockedXmlSerializer>();
serviceCollection.AddSingleton<IApplicationPaths, MockedApplicationPaths>();
serviceCollection.AddSingleton<ILibraryManager, MockedLibraryManager>();
serviceCollection.AddSingleton<IMediaSourceManager, MockedMediaSourceManager>();
serviceCollection.AddScoped<Bangumi.Plugin>();
serviceCollection.AddScoped<BookProvider>();
serviceCollection.AddScoped<EpisodeProvider>();
Expand Down
10 changes: 9 additions & 1 deletion Jellyfin.Plugin.Bangumi/Providers/EpisodeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace Jellyfin.Plugin.Bangumi.Providers;

public partial class EpisodeProvider(BangumiApi api, ILogger<EpisodeProvider> log, ILibraryManager libraryManager)
public partial class EpisodeProvider(BangumiApi api, ILogger<EpisodeProvider> log, ILibraryManager libraryManager, IMediaSourceManager mediaSourceManager)
: IRemoteMetadataProvider<Episode, EpisodeInfo>, IHasOrder
{
private static readonly Regex[] NonEpisodeFileNameRegex =
Expand Down Expand Up @@ -61,6 +61,14 @@ public partial class EpisodeProvider(BangumiApi api, ILogger<EpisodeProvider> lo
public async Task<MetadataResult<Episode>> 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);

Expand Down

0 comments on commit 6dc9387

Please sign in to comment.