Convert string MediaType to enum MediaType

This commit is contained in:
Cody Robibero 2023-05-13 12:44:31 -06:00
parent 74f61fbd79
commit 2920611ffc
47 changed files with 159 additions and 133 deletions

View File

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

View File

@ -174,13 +174,14 @@ namespace Emby.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;
}
}
@ -821,15 +822,15 @@ namespace Emby.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)
{
@ -1006,8 +1007,7 @@ namespace Emby.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 == MediaType.Audio || item.MediaType == MediaType.Video)
{
if (!stubType.HasValue)
{
@ -1016,7 +1016,7 @@ namespace Emby.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

@ -8,6 +8,7 @@ using System.Threading;
using System.Threading.Tasks;
using Emby.Dlna.Didl;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
using Jellyfin.Data.Events;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Drawing;
@ -577,7 +578,7 @@ namespace Emby.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))
if (item.MediaType == MediaType.Video)
{
return new PlaylistItem
{
@ -597,7 +598,7 @@ namespace Emby.Dlna.PlayTo
};
}
if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
if (item.MediaType == MediaType.Audio)
{
return new PlaylistItem
{
@ -615,7 +616,7 @@ namespace Emby.Dlna.PlayTo
};
}
if (string.Equals(item.MediaType, MediaType.Photo, StringComparison.OrdinalIgnoreCase))
if (item.MediaType == MediaType.Photo)
{
return PlaylistItemFactory.Create((Photo)item, profile);
}

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Jellyfin.Data.Enums;
namespace Emby.Dlna.PlayTo
{
@ -33,19 +34,19 @@ namespace Emby.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

@ -722,7 +722,7 @@ namespace Emby.Server.Implementations.Data
saveItemStatement.TryBind("@IsLocked", item.IsLocked);
saveItemStatement.TryBind("@Name", item.Name);
saveItemStatement.TryBind("@OfficialRating", item.OfficialRating);
saveItemStatement.TryBind("@MediaType", item.MediaType);
saveItemStatement.TryBind("@MediaType", item.MediaType.ToString());
saveItemStatement.TryBind("@Overview", item.Overview);
saveItemStatement.TryBind("@ParentIndexNumber", item.ParentIndexNumber);
saveItemStatement.TryBind("@PremiereDate", item.PremiereDate);
@ -3109,11 +3109,6 @@ namespace Emby.Server.Implementations.Data
return true;
}
private bool IsValidMediaType(string value)
{
return IsAlphaNumeric(value);
}
private bool IsValidPersonType(string value)
{
return IsAlphaNumeric(value);
@ -4124,15 +4119,14 @@ namespace Emby.Server.Implementations.Data
}
}
var queryMediaTypes = query.MediaTypes.Where(IsValidMediaType).ToArray();
if (queryMediaTypes.Length == 1)
if (query.MediaTypes.Length == 1)
{
whereClauses.Add("MediaType=@MediaTypes");
statement?.TryBind("@MediaTypes", queryMediaTypes[0]);
statement?.TryBind("@MediaTypes", query.MediaTypes[0].ToString());
}
else if (queryMediaTypes.Length > 1)
else if (query.MediaTypes.Length > 1)
{
var val = string.Join(',', queryMediaTypes.Select(i => "'" + i + "'"));
var val = string.Join(',', query.MediaTypes.Select(i => $"'{i}'"));
whereClauses.Add("MediaType in (" + val + ")");
}

View File

@ -11,6 +11,7 @@ using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using EasyCaching.Core.Configurations;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions.Json;
@ -186,11 +187,11 @@ namespace Emby.Server.Implementations.Library
{
SetDefaultAudioAndSubtitleStreamIndexes(item, source, user);
if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
if (item.MediaType == MediaType.Audio)
{
source.SupportsTranscoding = user.HasPermission(PermissionKind.EnableAudioPlaybackTranscoding);
}
else if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
else if (item.MediaType == MediaType.Video)
{
source.SupportsTranscoding = user.HasPermission(PermissionKind.EnableVideoPlaybackTranscoding);
source.SupportsDirectStream = user.HasPermission(PermissionKind.EnablePlaybackRemuxing);
@ -334,11 +335,11 @@ namespace Emby.Server.Implementations.Library
{
SetDefaultAudioAndSubtitleStreamIndexes(item, source, user);
if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
if (item.MediaType == MediaType.Audio)
{
source.SupportsTranscoding = user.HasPermission(PermissionKind.EnableAudioPlaybackTranscoding);
}
else if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
else if (item.MediaType == MediaType.Video)
{
source.SupportsTranscoding = user.HasPermission(PermissionKind.EnableVideoPlaybackTranscoding);
source.SupportsDirectStream = user.HasPermission(PermissionKind.EnablePlaybackRemuxing);
@ -417,9 +418,9 @@ namespace Emby.Server.Implementations.Library
public void SetDefaultAudioAndSubtitleStreamIndexes(BaseItem item, MediaSourceInfo source, User user)
{
// Item would only be null if the app didn't supply ItemId as part of the live stream open request
var mediaType = item is null ? MediaType.Video : item.MediaType;
var mediaType = item?.MediaType ?? MediaType.Video;
if (string.Equals(mediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
if (mediaType == MediaType.Video)
{
var userData = item is null ? new UserItemData() : _userDataManager.GetUserData(user, item);
@ -428,7 +429,7 @@ namespace Emby.Server.Implementations.Library
SetDefaultAudioStreamIndex(source, userData, user, allowRememberingSelection);
SetDefaultSubtitleStreamIndex(source, userData, user, allowRememberingSelection);
}
else if (string.Equals(mediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
else if (mediaType == MediaType.Audio)
{
var audio = source.MediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);

View File

@ -5,6 +5,7 @@
using System;
using System.IO;
using System.Linq;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Playlists;

View File

@ -317,7 +317,7 @@ namespace Emby.Server.Implementations.Library
}
}
var mediaTypes = new List<string>();
var mediaTypes = new List<MediaType>();
if (includeItemTypes.Length == 0)
{

View File

@ -63,7 +63,7 @@ namespace Emby.Server.Implementations.Library.Validators
{
var movies = _libraryManager.GetItemList(new InternalItemsQuery
{
MediaTypes = new string[] { MediaType.Video },
MediaTypes = new[] { MediaType.Video },
IncludeItemTypes = new[] { BaseItemKind.Movie },
IsVirtualItem = false,
OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) },

View File

@ -10,6 +10,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
@ -74,7 +75,7 @@ namespace Emby.Server.Implementations.Playlists
throw new ArgumentException(nameof(parentFolder));
}
if (string.IsNullOrEmpty(options.MediaType))
if (options.MediaType is null || options.MediaType == MediaType.Unknown)
{
foreach (var itemId in options.ItemIdList)
{
@ -84,7 +85,7 @@ namespace Emby.Server.Implementations.Playlists
throw new ArgumentException("No item exists with the supplied Id");
}
if (!string.IsNullOrEmpty(item.MediaType))
if (item.MediaType == MediaType.Unknown)
{
options.MediaType = item.MediaType;
}
@ -102,20 +103,20 @@ namespace Emby.Server.Implementations.Playlists
{
options.MediaType = folder.GetRecursiveChildren(i => !i.IsFolder && i.SupportsAddingToPlaylist)
.Select(i => i.MediaType)
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
.FirstOrDefault(i => i != MediaType.Unknown);
}
}
if (!string.IsNullOrEmpty(options.MediaType))
if (options.MediaType is null || options.MediaType == MediaType.Unknown)
{
break;
}
}
}
if (string.IsNullOrEmpty(options.MediaType))
if (options.MediaType is null || options.MediaType == MediaType.Unknown)
{
options.MediaType = "Audio";
options.MediaType = MediaType.Audio;
}
var user = _userManager.GetUserById(options.UserId);
@ -168,7 +169,7 @@ namespace Emby.Server.Implementations.Playlists
return path;
}
private List<BaseItem> GetPlaylistItems(IEnumerable<Guid> itemIds, string playlistMediaType, User user, DtoOptions options)
private List<BaseItem> GetPlaylistItems(IEnumerable<Guid> itemIds, MediaType playlistMediaType, User user, DtoOptions options)
{
var items = itemIds.Select(i => _libraryManager.GetItemById(i)).Where(i => i is not null);

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Dto;

View File

@ -95,7 +95,7 @@ public class ArtistsController : BaseJellyfinApiController
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFilter[] filters,
[FromQuery] bool? isFavorite,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] MediaType[] mediaTypes,
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string[] genres,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid[] genreIds,
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string[] officialRatings,
@ -299,7 +299,7 @@ public class ArtistsController : BaseJellyfinApiController
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFilter[] filters,
[FromQuery] bool? isFavorite,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] MediaType[] mediaTypes,
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string[] genres,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid[] genreIds,
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string[] officialRatings,

View File

@ -50,7 +50,7 @@ public class FilterController : BaseJellyfinApiController
[FromQuery] Guid? userId,
[FromQuery] Guid? parentId,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes)
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] MediaType[] mediaTypes)
{
userId = RequestHelpers.GetUserId(User, userId);
var user = userId.Value.Equals(default)

View File

@ -195,7 +195,7 @@ public class ItemsController : BaseJellyfinApiController
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFilter[] filters,
[FromQuery] bool? isFavorite,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] MediaType[] mediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] imageTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] sortBy,
[FromQuery] bool? isPlayed,
@ -652,7 +652,7 @@ public class ItemsController : BaseJellyfinApiController
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFilter[] filters,
[FromQuery] bool? isFavorite,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] MediaType[] mediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] imageTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] sortBy,
[FromQuery] bool? isPlayed,
@ -812,7 +812,7 @@ public class ItemsController : BaseJellyfinApiController
[FromQuery] string? searchTerm,
[FromQuery] Guid? parentId,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] MediaType[] mediaTypes,
[FromQuery] bool? enableUserData,
[FromQuery] int? imageTypeLimit,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes,

View File

@ -8,6 +8,7 @@ using Jellyfin.Api.Extensions;
using Jellyfin.Api.Helpers;
using Jellyfin.Api.ModelBinders;
using Jellyfin.Api.Models.PlaylistDtos;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Playlists;
@ -75,7 +76,7 @@ public class PlaylistsController : BaseJellyfinApiController
[FromQuery, ParameterObsolete] string? name,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder)), ParameterObsolete] IReadOnlyList<Guid> ids,
[FromQuery, ParameterObsolete] Guid? userId,
[FromQuery, ParameterObsolete] string? mediaType,
[FromQuery, ParameterObsolete] MediaType? mediaType,
[FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)] CreatePlaylistDto? createPlaylistRequest)
{
if (ids.Count == 0)

View File

@ -86,7 +86,7 @@ public class SearchController : BaseJellyfinApiController
[FromQuery, Required] string searchTerm,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] excludeItemTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] MediaType[] mediaTypes,
[FromQuery] Guid? parentId,
[FromQuery] bool? isMovie,
[FromQuery] bool? isSeries,

View File

@ -393,7 +393,7 @@ public class SessionController : BaseJellyfinApiController
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<ActionResult> PostCapabilities(
[FromQuery] string? id,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] playableMediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] MediaType[] playableMediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] GeneralCommandType[] supportedCommands,
[FromQuery] bool supportsMediaControl = false,
[FromQuery] bool supportsSync = false,

View File

@ -56,7 +56,7 @@ public class SuggestionsController : BaseJellyfinApiController
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult<QueryResult<BaseItemDto>> GetSuggestions(
[FromRoute, Required] Guid userId,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaType,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] MediaType[] mediaType,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] type,
[FromQuery] int? startIndex,
[FromQuery] int? limit,

View File

@ -160,7 +160,7 @@ public class TrailersController : BaseJellyfinApiController
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] excludeItemTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFilter[] filters,
[FromQuery] bool? isFavorite,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] MediaType[] mediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] imageTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] sortBy,
[FromQuery] bool? isPlayed,

View File

@ -76,7 +76,7 @@ public class YearsController : BaseJellyfinApiController
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] excludeItemTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] MediaType[] mediaTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] sortBy,
[FromQuery] bool? enableUserData,
[FromQuery] int? imageTypeLimit,
@ -191,7 +191,7 @@ public class YearsController : BaseJellyfinApiController
return _dtoService.GetBaseItemDto(item, dtoOptions);
}
private bool FilterItem(BaseItem f, IReadOnlyCollection<BaseItemKind> excludeItemTypes, IReadOnlyCollection<BaseItemKind> includeItemTypes, IReadOnlyCollection<string> mediaTypes)
private bool FilterItem(BaseItem f, IReadOnlyCollection<BaseItemKind> excludeItemTypes, IReadOnlyCollection<BaseItemKind> includeItemTypes, IReadOnlyCollection<MediaType> mediaTypes)
{
var baseItemKind = f.GetBaseItemKind();
// Exclude item types
@ -207,7 +207,7 @@ public class YearsController : BaseJellyfinApiController
}
// Include MediaTypes
if (mediaTypes.Count > 0 && !mediaTypes.Contains(f.MediaType ?? string.Empty, StringComparison.OrdinalIgnoreCase))
if (mediaTypes.Count > 0 && !mediaTypes.Contains(f.MediaType))
{
return false;
}

View File

@ -243,7 +243,7 @@ public class MediaInfoHelper
}
// Beginning of Playback Determination
var streamInfo = string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase)
var streamInfo = item.MediaType == MediaType.Audio
? streamBuilder.GetOptimalAudioStream(options)
: streamBuilder.GetOptimalVideoStream(options);

View File

@ -7,6 +7,7 @@ using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Api.Extensions;
using Jellyfin.Api.Models.StreamingDtos;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
@ -128,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

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions.Json.Converters;
namespace Jellyfin.Api.Models.PlaylistDtos;
@ -29,5 +30,5 @@ public class CreatePlaylistDto
/// <summary>
/// Gets or sets the media type.
/// </summary>
public string? MediaType { get; set; }
public MediaType? MediaType { get; set; }
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions.Json.Converters;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Session;
@ -16,7 +17,7 @@ public class ClientCapabilitiesDto
/// Gets or sets the list of playable media types.
/// </summary>
[JsonConverter(typeof(JsonCommaDelimitedArrayConverterFactory))]
public IReadOnlyList<string> PlayableMediaTypes { get; set; } = Array.Empty<string>();
public IReadOnlyList<MediaType> PlayableMediaTypes { get; set; } = Array.Empty<MediaType>();
/// <summary>
/// Gets or sets the list of supported commands.

View File

@ -0,0 +1,32 @@
namespace Jellyfin.Data.Enums;
/// <summary>
/// Media types.
/// </summary>
public enum MediaType
{
/// <summary>
/// Unknown media type.
/// </summary>
Unknown = 0,
/// <summary>
/// Video media.
/// </summary>
Video = 1,
/// <summary>
/// Audio media.
/// </summary>
Audio = 2,
/// <summary>
/// Photo media.
/// </summary>
Photo = 3,
/// <summary>
/// Book media.
/// </summary>
Book = 4
}

View File

@ -2,6 +2,7 @@
using System.Globalization;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Activity;
@ -89,14 +90,14 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Session
return name;
}
private static string GetPlaybackNotificationType(string mediaType)
private static string GetPlaybackNotificationType(MediaType mediaType)
{
if (string.Equals(mediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
if (mediaType == MediaType.Audio)
{
return NotificationType.AudioPlayback.ToString();
}
if (string.Equals(mediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
if (mediaType == MediaType.Video)
{
return NotificationType.VideoPlayback.ToString();
}

View File

@ -2,6 +2,7 @@
using System.Globalization;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Activity;
@ -97,14 +98,14 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Session
return name;
}
private static string? GetPlaybackStoppedNotificationType(string mediaType)
private static string? GetPlaybackStoppedNotificationType(MediaType mediaType)
{
if (string.Equals(mediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
if (mediaType == MediaType.Audio)
{
return NotificationType.AudioPlaybackStopped.ToString();
}
if (string.Equals(mediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
if (mediaType == MediaType.Video)
{
return NotificationType.VideoPlaybackStopped.ToString();
}

View File

@ -63,7 +63,7 @@ namespace MediaBrowser.Controller.Entities.Audio
/// </summary>
/// <value>The type of the media.</value>
[JsonIgnore]
public override string MediaType => Model.Entities.MediaType.Audio;
public override MediaType MediaType => MediaType.Audio;
public override double GetDefaultPrimaryImageAspectRatio()
{

View File

@ -422,7 +422,7 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
/// <value>The type of the media.</value>
[JsonIgnore]
public virtual string MediaType => null;
public virtual MediaType MediaType => MediaType.Unknown;
[JsonIgnore]
public virtual string[] PhysicalLocations

View File

@ -18,7 +18,7 @@ namespace MediaBrowser.Controller.Entities
}
[JsonIgnore]
public override string MediaType => Model.Entities.MediaType.Book;
public override MediaType MediaType => MediaType.Book;
public override bool SupportsPlayedStatus => true;

View File

@ -36,7 +36,7 @@ namespace MediaBrowser.Controller.Entities
ImageTypes = Array.Empty<ImageType>();
IncludeItemTypes = Array.Empty<BaseItemKind>();
ItemIds = Array.Empty<Guid>();
MediaTypes = Array.Empty<string>();
MediaTypes = Array.Empty<MediaType>();
MinSimilarityScore = 20;
OfficialRatings = Array.Empty<string>();
OrderBy = Array.Empty<(string, SortOrder)>();
@ -86,7 +86,7 @@ namespace MediaBrowser.Controller.Entities
public bool? IncludeItemsByName { get; set; }
public string[] MediaTypes { get; set; }
public MediaType[] MediaTypes { get; set; }
public BaseItemKind[] IncludeItemTypes { get; set; }

View File

@ -3,6 +3,7 @@
#pragma warning disable CS1591
using System.Text.Json.Serialization;
using Jellyfin.Data.Enums;
using MediaBrowser.Model.Drawing;
namespace MediaBrowser.Controller.Entities
@ -13,7 +14,7 @@ namespace MediaBrowser.Controller.Entities
public override bool SupportsLocalMetadata => false;
[JsonIgnore]
public override string MediaType => Model.Entities.MediaType.Photo;
public override MediaType MediaType => MediaType.Photo;
[JsonIgnore]
public override Folder LatestItemsIndexContainer => AlbumEntity;

View File

@ -476,7 +476,7 @@ namespace MediaBrowser.Controller.Entities
public static bool Filter(BaseItem item, User user, InternalItemsQuery query, IUserDataManager userDataManager, ILibraryManager libraryManager)
{
if (query.MediaTypes.Length > 0 && !query.MediaTypes.Contains(item.MediaType ?? string.Empty, StringComparison.OrdinalIgnoreCase))
if (query.MediaTypes.Length > 0 && !query.MediaTypes.Contains(item.MediaType))
{
return false;
}

View File

@ -9,6 +9,7 @@ using System.Linq;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
@ -256,7 +257,7 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
/// <value>The type of the media.</value>
[JsonIgnore]
public override string MediaType => Model.Entities.MediaType.Video;
public override MediaType MediaType => MediaType.Video;
public override List<string> GetUserDataKeys()
{

View File

@ -44,7 +44,7 @@ namespace MediaBrowser.Controller.LiveTv
public override LocationType LocationType => LocationType.Remote;
[JsonIgnore]
public override string MediaType => ChannelType == ChannelType.Radio ? Model.Entities.MediaType.Audio : Model.Entities.MediaType.Video;
public override MediaType MediaType => ChannelType == ChannelType.Radio ? MediaType.Audio : MediaType.Video;
[JsonIgnore]
public bool IsMovie { get; set; }

View File

@ -69,7 +69,7 @@ namespace MediaBrowser.Controller.Playlists
public override bool SupportsInheritedParentImages => false;
[JsonIgnore]
public override bool SupportsPlayedStatus => string.Equals(MediaType, "Video", StringComparison.OrdinalIgnoreCase);
public override bool SupportsPlayedStatus => MediaType == Jellyfin.Data.Enums.MediaType.Video;
[JsonIgnore]
public override bool AlwaysScanInternalMetadataPath => true;
@ -80,10 +80,10 @@ namespace MediaBrowser.Controller.Playlists
[JsonIgnore]
public override bool IsPreSorted => true;
public string PlaylistMediaType { get; set; }
public MediaType PlaylistMediaType { get; set; }
[JsonIgnore]
public override string MediaType => PlaylistMediaType;
public override MediaType MediaType => PlaylistMediaType;
[JsonIgnore]
private bool IsSharedItem
@ -107,9 +107,9 @@ namespace MediaBrowser.Controller.Playlists
return System.IO.Path.HasExtension(path) && !Directory.Exists(path);
}
public void SetMediaType(string value)
public void SetMediaType(MediaType? value)
{
PlaylistMediaType = value;
PlaylistMediaType = value ?? MediaType.Unknown;
}
public override double GetDefaultPrimaryImageAspectRatio()
@ -167,7 +167,7 @@ namespace MediaBrowser.Controller.Playlists
return base.GetChildren(user, true, query);
}
public static List<BaseItem> GetPlaylistItems(string playlistMediaType, IEnumerable<BaseItem> inputItems, User user, DtoOptions options)
public static List<BaseItem> GetPlaylistItems(MediaType playlistMediaType, IEnumerable<BaseItem> inputItems, User user, DtoOptions options)
{
if (user is not null)
{
@ -185,7 +185,7 @@ namespace MediaBrowser.Controller.Playlists
return list;
}
private static IEnumerable<BaseItem> GetPlaylistItems(BaseItem item, User user, string mediaType, DtoOptions options)
private static IEnumerable<BaseItem> GetPlaylistItems(BaseItem item, User user, MediaType mediaType, DtoOptions options)
{
if (item is MusicGenre musicGenre)
{

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Session;
@ -60,13 +61,13 @@ namespace MediaBrowser.Controller.Session
/// Gets the playable media types.
/// </summary>
/// <value>The playable media types.</value>
public IReadOnlyList<string> PlayableMediaTypes
public IReadOnlyList<MediaType> PlayableMediaTypes
{
get
{
if (Capabilities is null)
{
return Array.Empty<string>();
return Array.Empty<MediaType>();
}
return Capabilities.PlayableMediaTypes;

View File

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Xml;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Extensions;
using MediaBrowser.Controller.Playlists;
@ -31,7 +33,11 @@ namespace MediaBrowser.LocalMetadata.Parsers
switch (reader.Name)
{
case "PlaylistMediaType":
item.PlaylistMediaType = reader.ReadNormalizedString();
if (Enum.TryParse<MediaType>(reader.ReadNormalizedString(), out var mediaType))
{
item.PlaylistMediaType = mediaType;
}
break;
case "PlaylistItems":

View File

@ -1,6 +1,7 @@
using System.IO;
using System.Threading.Tasks;
using System.Xml;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
@ -48,12 +49,12 @@ namespace MediaBrowser.LocalMetadata.Savers
{
var game = (Playlist)item;
if (string.IsNullOrEmpty(game.PlaylistMediaType))
if (game.PlaylistMediaType == MediaType.Unknown)
{
return Task.CompletedTask;
}
return writer.WriteElementStringAsync(null, "PlaylistMediaType", null, game.PlaylistMediaType);
return writer.WriteElementStringAsync(null, "PlaylistMediaType", null, game.PlaylistMediaType.ToString());
}
/// <inheritdoc />

View File

@ -1,6 +1,7 @@
#pragma warning disable CA1819 // Properties should not return arrays
using System;
using System.ComponentModel;
using System.Linq;
using System.Xml.Serialization;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
@ -227,9 +228,12 @@ namespace MediaBrowser.Model.Dlna
/// The GetSupportedMediaTypes.
/// </summary>
/// <returns>The .</returns>
public string[] GetSupportedMediaTypes()
public MediaType[] GetSupportedMediaTypes()
{
return ContainerProfile.SplitValue(SupportedMediaTypes);
return ContainerProfile.SplitValue(SupportedMediaTypes)
.Select(m => Enum.TryParse<MediaType>(m, out var parsed) ? parsed : MediaType.Unknown)
.Where(m => m != MediaType.Unknown)
.ToArray();
}
/// <summary>

View File

@ -584,7 +584,7 @@ namespace MediaBrowser.Model.Dto
/// Gets or sets the type of the media.
/// </summary>
/// <value>The type of the media.</value>
public string MediaType { get; set; }
public MediaType MediaType { get; set; }
/// <summary>
/// Gets or sets the end date.

View File

@ -1,28 +0,0 @@
namespace MediaBrowser.Model.Entities
{
/// <summary>
/// Class MediaType.
/// </summary>
public static class MediaType
{
/// <summary>
/// The video.
/// </summary>
public const string Video = "Video";
/// <summary>
/// The audio.
/// </summary>
public const string Audio = "Audio";
/// <summary>
/// The photo.
/// </summary>
public const string Photo = "Photo";
/// <summary>
/// The book.
/// </summary>
public const string Book = "Book";
}
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Jellyfin.Data.Enums;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Model.Playlists;
@ -22,7 +23,7 @@ public class PlaylistCreationRequest
/// <summary>
/// Gets or sets the media type.
/// </summary>
public string? MediaType { get; set; }
public MediaType? MediaType { get; set; }
/// <summary>
/// Gets or sets the user id.

View File

@ -16,7 +16,7 @@ namespace MediaBrowser.Model.Search
{
Name = string.Empty;
MatchedTerm = string.Empty;
MediaType = string.Empty;
MediaType = Jellyfin.Data.Enums.MediaType.Unknown;
Artists = Array.Empty<string>();
}
@ -115,7 +115,7 @@ namespace MediaBrowser.Model.Search
/// Gets or sets the type of the media.
/// </summary>
/// <value>The type of the media.</value>
public string MediaType { get; set; }
public MediaType MediaType { get; set; }
/// <summary>
/// Gets or sets the start date.

View File

@ -16,7 +16,7 @@ namespace MediaBrowser.Model.Search
IncludePeople = true;
IncludeStudios = true;
MediaTypes = Array.Empty<string>();
MediaTypes = Array.Empty<MediaType>();
IncludeItemTypes = Array.Empty<BaseItemKind>();
ExcludeItemTypes = Array.Empty<BaseItemKind>();
}
@ -55,7 +55,7 @@ namespace MediaBrowser.Model.Search
public bool IncludeArtists { get; set; }
public string[] MediaTypes { get; set; }
public MediaType[] MediaTypes { get; set; }
public BaseItemKind[] IncludeItemTypes { get; set; }

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using Jellyfin.Data.Enums;
using MediaBrowser.Model.Dlna;
namespace MediaBrowser.Model.Session
@ -11,12 +12,12 @@ namespace MediaBrowser.Model.Session
{
public ClientCapabilities()
{
PlayableMediaTypes = Array.Empty<string>();
PlayableMediaTypes = Array.Empty<MediaType>();
SupportedCommands = Array.Empty<GeneralCommandType>();
SupportsPersistentIdentifier = true;
}
public IReadOnlyList<string> PlayableMediaTypes { get; set; }
public IReadOnlyList<MediaType> PlayableMediaTypes { get; set; }
public IReadOnlyList<GeneralCommandType> SupportedCommands { get; set; }

View File

@ -97,7 +97,7 @@ namespace MediaBrowser.Providers.MediaInfo
{
var query = new InternalItemsQuery
{
MediaTypes = new string[] { MediaType.Video },
MediaTypes = new[] { MediaType.Video },
IsVirtualItem = false,
IncludeItemTypes = types,
DtoOptions = new DtoOptions(true),