Skip to content

Commit

Permalink
Use MediaType enum
Browse files Browse the repository at this point in the history
  • Loading branch information
barronpm committed Nov 12, 2023
1 parent 37f0fb6 commit 8ef1450
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
4 changes: 2 additions & 2 deletions src/Jellyfin.Plugin.Dlna.Playback/StreamingHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand All @@ -17,7 +18,6 @@
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;
Expand Down Expand Up @@ -129,7 +129,7 @@ public static async Task<StreamState> GetStreamingState(

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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ private static QueryResult<BaseItem> GetChildrenSorted(BaseItem item, User user,
{
var folder = (Folder)item;

string[] mediaTypes = Array.Empty<string>();
MediaType[] mediaTypes = Array.Empty<MediaType>();
bool? isFolder = null;

switch (search.SearchType)
Expand Down
24 changes: 12 additions & 12 deletions src/Jellyfin.Plugin.Dlna/Didl/DidlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,14 @@ public void WriteItemElement(

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;
}
}

Expand Down Expand Up @@ -828,15 +829,15 @@ private void WriteObjectClass(XmlWriter writer, BaseItem item, StubType? stubTyp

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)
{
Expand Down Expand Up @@ -1013,8 +1014,7 @@ private void AddCover(BaseItem item, StubType? stubType, XmlWriter writer)

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)
{
Expand All @@ -1023,7 +1023,7 @@ private void AddCover(BaseItem item, StubType? stubType, XmlWriter writer)
}
}

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");
Expand Down
4 changes: 2 additions & 2 deletions src/Jellyfin.Plugin.Dlna/Jellyfin.Plugin.Dlna.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
31 changes: 9 additions & 22 deletions src/Jellyfin.Plugin.Dlna/PlayTo/PlayToController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -17,7 +18,6 @@
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;
Expand Down Expand Up @@ -580,10 +580,9 @@ private PlaylistItem CreatePlaylistItem(
}

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
{
Expand All @@ -596,14 +595,9 @@ private PlaylistItem GetPlaylistItem(BaseItem item, MediaSourceInfo[] mediaSourc
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
{
Expand All @@ -614,18 +608,11 @@ private PlaylistItem GetPlaylistItem(BaseItem item, MediaSourceInfo[] mediaSourc
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.
Expand Down
12 changes: 6 additions & 6 deletions src/Jellyfin.Plugin.Dlna/PlayTo/uBaseObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ public string MediaType
{
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;
Expand Down
6 changes: 3 additions & 3 deletions src/Rssdp/Rssdp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 8ef1450

Please sign in to comment.