Query media streams by type instead of filtering

This commit is contained in:
Joe Rogers 2021-11-17 22:03:52 +01:00
parent c32a421ea7
commit 7cf5767949
No known key found for this signature in database
GPG Key ID: 0074AD57B8FDBBB4
7 changed files with 12 additions and 18 deletions

View File

@ -126,15 +126,6 @@ namespace MediaBrowser.Controller.Entities.Audio
return base.GetBlockUnratedType();
}
public List<MediaStream> GetMediaStreams(MediaStreamType type)
{
return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
{
ItemId = Id,
Type = type
});
}
public SongInfo GetLookupInfo()
{
var info = GetItemLookupInfo<SongInfo>();

View File

@ -1107,10 +1107,16 @@ namespace MediaBrowser.Controller.Entities
}
public virtual List<MediaStream> GetMediaStreams()
{
return GetMediaStreams(null);
}
public virtual List<MediaStream> GetMediaStreams(MediaStreamType? type)
{
return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
{
ItemId = Id
ItemId = Id,
Type = type
});
}

View File

@ -49,10 +49,7 @@ namespace MediaBrowser.Providers.MediaInfo
{
var audio = (Audio)item;
var imageStreams =
audio.GetMediaStreams(MediaStreamType.EmbeddedImage)
.Where(i => i.Type == MediaStreamType.EmbeddedImage)
.ToList();
var imageStreams = audio.GetMediaStreams(MediaStreamType.EmbeddedImage);
// Can't extract if we didn't find a video stream in the file
if (imageStreams.Count == 0)

View File

@ -139,7 +139,7 @@ namespace MediaBrowser.Providers.MediaInfo
}
// Fall back to EmbeddedImage streams
var imageStreams = item.GetMediaStreams().FindAll(i => i.Type == MediaStreamType.EmbeddedImage);
var imageStreams = item.GetMediaStreams(MediaStreamType.EmbeddedImage);
if (imageStreams.Count == 0)
{

View File

@ -83,7 +83,7 @@ namespace MediaBrowser.Providers.MediaInfo
? TimeSpan.FromTicks(item.RunTimeTicks.Value / 10)
: TimeSpan.FromSeconds(10);
var videoStream = item.GetDefaultVideoStream() ?? item.GetMediaStreams().FirstOrDefault(i => i.Type == MediaStreamType.Video);
var videoStream = item.GetDefaultVideoStream() ?? item.GetMediaStreams(MediaStreamType.Video).FirstOrDefault();
if (videoStream == null)
{

View File

@ -147,7 +147,7 @@ namespace Jellyfin.Providers.Tests.MediaInfo
movie.Setup(item => item.GetMediaSources(It.IsAny<bool>()))
.Returns(new List<MediaSourceInfo> { new () { MediaAttachments = mediaAttachments } } );
movie.Setup(item => item.GetMediaStreams())
movie.Setup(item => item.GetMediaStreams(MediaStreamType.EmbeddedImage))
.Returns(mediaStreams);
return movie.Object;

View File

@ -167,7 +167,7 @@ namespace Jellyfin.Providers.Tests.MediaInfo
movie.Setup(item => item.GetDefaultVideoStream())
.Returns(defaultStream!);
movie.Setup(item => item.GetMediaStreams())
movie.Setup(item => item.GetMediaStreams(MediaStreamType.Video))
.Returns(mediaStreams);
return movie.Object;