Use MediaType enum

This commit is contained in:
Patrick Barron 2023-11-12 10:06:50 -05:00
parent 37f0fb6cc9
commit 8ef14502a9
9 changed files with 39 additions and 52 deletions

View File

@ -5,7 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.9.0-20231109.7" />
<PackageReference Include="Jellyfin.Model" Version="10.9.0-20231109.7" />
<PackageReference Include="Jellyfin.Controller" Version="10.9.0-20231112.1" />
<PackageReference Include="Jellyfin.Model" Version="10.9.0-20231112.1" />
</ItemGroup>
</Project>

View File

@ -5,8 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.9.0-20231109.7" />
<PackageReference Include="Jellyfin.Model" Version="10.9.0-20231109.7" />
<PackageReference Include="Jellyfin.Controller" Version="10.9.0-20231112.1" />
<PackageReference Include="Jellyfin.Model" Version="10.9.0-20231112.1" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="7.0.13" />
</ItemGroup>

View File

@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using Jellyfin.Plugin.Dlna.Model;
using Jellyfin.Plugin.Dlna.Playback.Extensions;
@ -17,7 +18,6 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
@ -129,7 +129,7 @@ public static class StreamingHelpers
var item = libraryManager.GetItemById(streamingRequest.Id);
state.IsInputVideo = string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase);
state.IsInputVideo = item.MediaType == MediaType.Video;
MediaSourceInfo? mediaSource = null;
if (string.IsNullOrWhiteSpace(streamingRequest.LiveStreamId))

View File

@ -494,7 +494,7 @@ namespace Jellyfin.Plugin.Dlna.ContentDirectory
{
var folder = (Folder)item;
string[] mediaTypes = Array.Empty<string>();
MediaType[] mediaTypes = Array.Empty<MediaType>();
bool? isFolder = null;
switch (search.SearchType)

View File

@ -181,13 +181,14 @@ namespace Jellyfin.Plugin.Dlna.Didl
if (item is IHasMediaSources)
{
if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
switch (item.MediaType)
{
AddAudioResource(writer, item, deviceId, filter, streamInfo);
}
else if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
{
AddVideoResource(writer, item, deviceId, filter, streamInfo);
case MediaType.Audio:
AddAudioResource(writer, item, deviceId, filter, streamInfo);
break;
case MediaType.Video:
AddVideoResource(writer, item, deviceId, filter, streamInfo);
break;
}
}
@ -828,15 +829,15 @@ namespace Jellyfin.Plugin.Dlna.Didl
writer.WriteString(classType ?? "object.container.storageFolder");
}
else if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
else if (item.MediaType == MediaType.Audio)
{
writer.WriteString("object.item.audioItem.musicTrack");
}
else if (string.Equals(item.MediaType, MediaType.Photo, StringComparison.OrdinalIgnoreCase))
else if (item.MediaType == MediaType.Photo)
{
writer.WriteString("object.item.imageItem.photo");
}
else if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
else if (item.MediaType == MediaType.Video)
{
if (!_profile.RequiresPlainVideoItems && item is Movie)
{
@ -1013,8 +1014,7 @@ namespace Jellyfin.Plugin.Dlna.Didl
if (!_profile.EnableAlbumArtInDidl)
{
if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase)
|| string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
if (item.MediaType is MediaType.Audio or MediaType.Video)
{
if (!stubType.HasValue)
{
@ -1023,7 +1023,7 @@ namespace Jellyfin.Plugin.Dlna.Didl
}
}
if (!_profile.EnableSingleAlbumArtLimit || string.Equals(item.MediaType, MediaType.Photo, StringComparison.OrdinalIgnoreCase))
if (!_profile.EnableSingleAlbumArtLimit || item.MediaType == MediaType.Photo)
{
AddImageResElement(item, writer, 4096, 4096, "jpg", "JPEG_LRG");
AddImageResElement(item, writer, 1024, 768, "jpg", "JPEG_MED");

View File

@ -5,8 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.9.0-20231109.7" />
<PackageReference Include="Jellyfin.Model" Version="10.9.0-20231109.7" />
<PackageReference Include="Jellyfin.Controller" Version="10.9.0-20231112.1" />
<PackageReference Include="Jellyfin.Model" Version="10.9.0-20231112.1" />
</ItemGroup>
<ItemGroup>

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
using Jellyfin.Data.Events;
using Jellyfin.Plugin.Dlna.Didl;
using Jellyfin.Plugin.Dlna.Extensions;
@ -17,7 +18,6 @@ using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Session;
using Microsoft.AspNetCore.WebUtilities;
@ -580,10 +580,9 @@ namespace Jellyfin.Plugin.Dlna.PlayTo
}
private PlaylistItem GetPlaylistItem(BaseItem item, MediaSourceInfo[] mediaSources, DeviceProfile profile, string deviceId, string? mediaSourceId, int? audioStreamIndex, int? subtitleStreamIndex)
{
if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
=> item.MediaType switch
{
return new PlaylistItem
MediaType.Video => new PlaylistItem
{
StreamInfo = new StreamBuilder(_mediaEncoder, _logger).GetOptimalVideoStream(new MediaOptions
{
@ -596,14 +595,9 @@ namespace Jellyfin.Plugin.Dlna.PlayTo
AudioStreamIndex = audioStreamIndex,
SubtitleStreamIndex = subtitleStreamIndex
}),
Profile = profile
};
}
if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
{
return new PlaylistItem
},
MediaType.Audio => new PlaylistItem
{
StreamInfo = new StreamBuilder(_mediaEncoder, _logger).GetOptimalAudioStream(new MediaOptions
{
@ -614,18 +608,11 @@ namespace Jellyfin.Plugin.Dlna.PlayTo
MaxBitrate = profile.MaxStreamingBitrate,
MediaSourceId = mediaSourceId
}),
Profile = profile
};
}
if (string.Equals(item.MediaType, MediaType.Photo, StringComparison.OrdinalIgnoreCase))
{
return PlaylistItemFactory.Create((Photo)item, profile);
}
throw new ArgumentException("Unrecognized item type.");
}
},
MediaType.Photo => PlaylistItemFactory.Create((Photo)item, profile),
_ => throw new ArgumentException("Unrecognized item type.")
};
/// <summary>
/// Plays the items.

View File

@ -33,19 +33,19 @@ namespace Jellyfin.Plugin.Dlna.PlayTo
{
var classType = UpnpClass ?? string.Empty;
if (classType.IndexOf(MediaBrowser.Model.Entities.MediaType.Audio, StringComparison.Ordinal) != -1)
if (classType.Contains("Audio", StringComparison.Ordinal))
{
return MediaBrowser.Model.Entities.MediaType.Audio;
return "Audio";
}
if (classType.IndexOf(MediaBrowser.Model.Entities.MediaType.Video, StringComparison.Ordinal) != -1)
if (classType.Contains("Video", StringComparison.Ordinal))
{
return MediaBrowser.Model.Entities.MediaType.Video;
return "Video";
}
if (classType.IndexOf("image", StringComparison.Ordinal) != -1)
if (classType.Contains("image", StringComparison.Ordinal))
{
return MediaBrowser.Model.Entities.MediaType.Photo;
return "Photo";
}
return null;

View File

@ -5,9 +5,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jellyfin.Common" Version="10.9.0-20231109.7" />
<PackageReference Include="Jellyfin.Controller" Version="10.9.0-20231109.7" />
<PackageReference Include="Jellyfin.Extensions" Version="10.9.0-20231109.7" />
<PackageReference Include="Jellyfin.Common" Version="10.9.0-20231112.1" />
<PackageReference Include="Jellyfin.Controller" Version="10.9.0-20231112.1" />
<PackageReference Include="Jellyfin.Extensions" Version="10.9.0-20231112.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
</ItemGroup>
</Project>