From f336d20b065c873f0f321c7a1cec565f5a77a806 Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 23 Nov 2020 09:49:42 -0700 Subject: [PATCH 1/3] Fix sending PlaybackInfo --- .../Controllers/MediaInfoController.cs | 56 ++++++++---- .../Models/MediaInfoDtos/PlaybackInfoDto.cs | 86 +++++++++++++++++++ 2 files changed, 123 insertions(+), 19 deletions(-) create mode 100644 Jellyfin.Api/Models/MediaInfoDtos/PlaybackInfoDto.cs diff --git a/Jellyfin.Api/Controllers/MediaInfoController.cs b/Jellyfin.Api/Controllers/MediaInfoController.cs index b42e6686ec..cab1aa19cd 100644 --- a/Jellyfin.Api/Controllers/MediaInfoController.cs +++ b/Jellyfin.Api/Controllers/MediaInfoController.cs @@ -81,6 +81,9 @@ namespace Jellyfin.Api.Controllers /// /// Gets live playback media info for an item. /// + /// + /// For backwards compatibility parameters can be sent via Query or Body, with Query having higher precedence. + /// /// The item id. /// The user id. /// The maximum streaming bitrate. @@ -90,13 +93,13 @@ namespace Jellyfin.Api.Controllers /// The maximum number of audio channels. /// The media source id. /// The livestream id. - /// The device profile. /// Whether to auto open the livestream. /// Whether to enable direct play. Default: true. /// Whether to enable direct stream. Default: true. /// Whether to enable transcoding. Default: true. /// Whether to allow to copy the video stream. Default: true. /// Whether to allow to copy the audio stream. Default: true. + /// The playback info. /// Playback info returned. /// A containing a with the playback info. [HttpPost("Items/{itemId}/PlaybackInfo")] @@ -111,18 +114,17 @@ namespace Jellyfin.Api.Controllers [FromQuery] int? maxAudioChannels, [FromQuery] string? mediaSourceId, [FromQuery] string? liveStreamId, - [FromBody] DeviceProfileDto? deviceProfile, - [FromQuery] bool autoOpenLiveStream = false, - [FromQuery] bool enableDirectPlay = true, - [FromQuery] bool enableDirectStream = true, - [FromQuery] bool enableTranscoding = true, - [FromQuery] bool allowVideoStreamCopy = true, - [FromQuery] bool allowAudioStreamCopy = true) + [FromQuery] bool? autoOpenLiveStream, + [FromQuery] bool? enableDirectPlay, + [FromQuery] bool? enableDirectStream, + [FromQuery] bool? enableTranscoding, + [FromQuery] bool? allowVideoStreamCopy, + [FromQuery] bool? allowAudioStreamCopy, + [FromBody] PlaybackInfoDto? playbackInfoDto) { var authInfo = _authContext.GetAuthorizationInfo(Request); - var profile = deviceProfile?.DeviceProfile; - + var profile = playbackInfoDto?.DeviceProfile?.DeviceProfile; _logger.LogInformation("GetPostedPlaybackInfo profile: {@Profile}", profile); if (profile == null) @@ -134,6 +136,22 @@ namespace Jellyfin.Api.Controllers } } + // Copy params from posted body + userId ??= playbackInfoDto?.UserId; + maxStreamingBitrate ??= playbackInfoDto?.MaxStreamingBitrate; + startTimeTicks ??= playbackInfoDto?.StartTimeTicks; + audioStreamIndex ??= playbackInfoDto?.AudioStreamIndex; + subtitleStreamIndex ??= playbackInfoDto?.SubtitleStreamIndex; + maxAudioChannels ??= playbackInfoDto?.MaxAudioChannels; + mediaSourceId ??= playbackInfoDto?.MediaSourceId; + liveStreamId ??= playbackInfoDto?.LiveStreamId; + autoOpenLiveStream ??= playbackInfoDto?.AutoOpenLiveStream ?? false; + enableDirectPlay ??= playbackInfoDto?.EnableDirectPlay ?? true; + enableDirectStream ??= playbackInfoDto?.EnableDirectStream ?? true; + enableTranscoding ??= playbackInfoDto?.EnableTranscoding ?? true; + allowVideoStreamCopy ??= playbackInfoDto?.AllowVideoStreamCopy ?? true; + allowAudioStreamCopy ??= playbackInfoDto?.AllowAudioStreamCopy ?? true; + var info = await _mediaInfoHelper.GetPlaybackInfo( itemId, userId, @@ -161,18 +179,18 @@ namespace Jellyfin.Api.Controllers maxAudioChannels, info!.PlaySessionId!, userId ?? Guid.Empty, - enableDirectPlay, - enableDirectStream, - enableTranscoding, - allowVideoStreamCopy, - allowAudioStreamCopy, + enableDirectPlay.Value, + enableDirectStream.Value, + enableTranscoding.Value, + allowVideoStreamCopy.Value, + allowAudioStreamCopy.Value, Request.HttpContext.GetNormalizedRemoteIp()); } _mediaInfoHelper.SortMediaSources(info, maxStreamingBitrate); } - if (autoOpenLiveStream) + if (autoOpenLiveStream.Value) { var mediaSource = string.IsNullOrWhiteSpace(mediaSourceId) ? info.MediaSources[0] : info.MediaSources.FirstOrDefault(i => string.Equals(i.Id, mediaSourceId, StringComparison.Ordinal)); @@ -183,9 +201,9 @@ namespace Jellyfin.Api.Controllers new LiveStreamRequest { AudioStreamIndex = audioStreamIndex, - DeviceProfile = deviceProfile?.DeviceProfile, - EnableDirectPlay = enableDirectPlay, - EnableDirectStream = enableDirectStream, + DeviceProfile = playbackInfoDto?.DeviceProfile?.DeviceProfile, + EnableDirectPlay = enableDirectPlay.Value, + EnableDirectStream = enableDirectStream.Value, ItemId = itemId, MaxAudioChannels = maxAudioChannels, MaxStreamingBitrate = maxStreamingBitrate, diff --git a/Jellyfin.Api/Models/MediaInfoDtos/PlaybackInfoDto.cs b/Jellyfin.Api/Models/MediaInfoDtos/PlaybackInfoDto.cs new file mode 100644 index 0000000000..818f78b529 --- /dev/null +++ b/Jellyfin.Api/Models/MediaInfoDtos/PlaybackInfoDto.cs @@ -0,0 +1,86 @@ +using System; +using Jellyfin.Api.Models.VideoDtos; + +namespace Jellyfin.Api.Models.MediaInfoDtos +{ + /// + /// Plabyback info dto. + /// + public class PlaybackInfoDto + { + /// + /// Gets or sets the playback userId. + /// + public Guid? UserId { get; set; } + + /// + /// Gets or sets the max streaming bitrate. + /// + public int? MaxStreamingBitrate { get; set; } + + /// + /// Gets or sets the start time in ticks. + /// + public long? StartTimeTicks { get; set; } + + /// + /// Gets or sets the audio stream index. + /// + public int? AudioStreamIndex { get; set; } + + /// + /// Gets or sets the subtitle stream index. + /// + public int? SubtitleStreamIndex { get; set; } + + /// + /// Gets or sets the max audio channels. + /// + public int? MaxAudioChannels { get; set; } + + /// + /// Gets or sets the media source id. + /// + public string? MediaSourceId { get; set; } + + /// + /// Gets or sets the live stream id. + /// + public string? LiveStreamId { get; set; } + + /// + /// Gets or sets the device profile. + /// + public DeviceProfileDto? DeviceProfile { get; set; } + + /// + /// Gets or sets a value indicating whether to enable direct play. + /// + public bool? EnableDirectPlay { get; set; } + + /// + /// Gets or sets a value indicating whether to enable direct stream. + /// + public bool? EnableDirectStream { get; set; } + + /// + /// Gets or sets a value indicating whether to enable transcoding. + /// + public bool? EnableTranscoding { get; set; } + + /// + /// Gets or sets a value indicating whether to enable video stream copy. + /// + public bool? AllowVideoStreamCopy { get; set; } + + /// + /// Gets or sets a value indicating whether to allow audio stream copy. + /// + public bool? AllowAudioStreamCopy { get; set; } + + /// + /// Gets or sets a value indicating whether to auto open the live stream. + /// + public bool? AutoOpenLiveStream { get; set; } + } +} \ No newline at end of file From fafddfc45eed4e76c4072167428b43d2ed026bcd Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 23 Nov 2020 09:51:24 -0700 Subject: [PATCH 2/3] Add TODO notice --- Jellyfin.Api/Controllers/MediaInfoController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Jellyfin.Api/Controllers/MediaInfoController.cs b/Jellyfin.Api/Controllers/MediaInfoController.cs index cab1aa19cd..c03a69cb9c 100644 --- a/Jellyfin.Api/Controllers/MediaInfoController.cs +++ b/Jellyfin.Api/Controllers/MediaInfoController.cs @@ -137,6 +137,7 @@ namespace Jellyfin.Api.Controllers } // Copy params from posted body + // TODO clean up when breaking API compatibility. userId ??= playbackInfoDto?.UserId; maxStreamingBitrate ??= playbackInfoDto?.MaxStreamingBitrate; startTimeTicks ??= playbackInfoDto?.StartTimeTicks; From 1dafd70f5141c1fa8fefa72dd97399f51df4d116 Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 23 Nov 2020 10:50:18 -0700 Subject: [PATCH 3/3] Don't nest DeviceProfile --- Jellyfin.Api/Controllers/MediaInfoController.cs | 5 ++--- .../Models/MediaInfoDtos/PlaybackInfoDto.cs | 4 ++-- Jellyfin.Api/Models/VideoDtos/DeviceProfileDto.cs | 15 --------------- 3 files changed, 4 insertions(+), 20 deletions(-) delete mode 100644 Jellyfin.Api/Models/VideoDtos/DeviceProfileDto.cs diff --git a/Jellyfin.Api/Controllers/MediaInfoController.cs b/Jellyfin.Api/Controllers/MediaInfoController.cs index c03a69cb9c..a76dc057a0 100644 --- a/Jellyfin.Api/Controllers/MediaInfoController.cs +++ b/Jellyfin.Api/Controllers/MediaInfoController.cs @@ -8,7 +8,6 @@ using Jellyfin.Api.Attributes; using Jellyfin.Api.Constants; using Jellyfin.Api.Helpers; using Jellyfin.Api.Models.MediaInfoDtos; -using Jellyfin.Api.Models.VideoDtos; using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Library; @@ -124,7 +123,7 @@ namespace Jellyfin.Api.Controllers { var authInfo = _authContext.GetAuthorizationInfo(Request); - var profile = playbackInfoDto?.DeviceProfile?.DeviceProfile; + var profile = playbackInfoDto?.DeviceProfile; _logger.LogInformation("GetPostedPlaybackInfo profile: {@Profile}", profile); if (profile == null) @@ -202,7 +201,7 @@ namespace Jellyfin.Api.Controllers new LiveStreamRequest { AudioStreamIndex = audioStreamIndex, - DeviceProfile = playbackInfoDto?.DeviceProfile?.DeviceProfile, + DeviceProfile = playbackInfoDto?.DeviceProfile, EnableDirectPlay = enableDirectPlay.Value, EnableDirectStream = enableDirectStream.Value, ItemId = itemId, diff --git a/Jellyfin.Api/Models/MediaInfoDtos/PlaybackInfoDto.cs b/Jellyfin.Api/Models/MediaInfoDtos/PlaybackInfoDto.cs index 818f78b529..2cfdba507e 100644 --- a/Jellyfin.Api/Models/MediaInfoDtos/PlaybackInfoDto.cs +++ b/Jellyfin.Api/Models/MediaInfoDtos/PlaybackInfoDto.cs @@ -1,5 +1,5 @@ using System; -using Jellyfin.Api.Models.VideoDtos; +using MediaBrowser.Model.Dlna; namespace Jellyfin.Api.Models.MediaInfoDtos { @@ -51,7 +51,7 @@ namespace Jellyfin.Api.Models.MediaInfoDtos /// /// Gets or sets the device profile. /// - public DeviceProfileDto? DeviceProfile { get; set; } + public DeviceProfile? DeviceProfile { get; set; } /// /// Gets or sets a value indicating whether to enable direct play. diff --git a/Jellyfin.Api/Models/VideoDtos/DeviceProfileDto.cs b/Jellyfin.Api/Models/VideoDtos/DeviceProfileDto.cs deleted file mode 100644 index db55dc34b5..0000000000 --- a/Jellyfin.Api/Models/VideoDtos/DeviceProfileDto.cs +++ /dev/null @@ -1,15 +0,0 @@ -using MediaBrowser.Model.Dlna; - -namespace Jellyfin.Api.Models.VideoDtos -{ - /// - /// Device profile dto. - /// - public class DeviceProfileDto - { - /// - /// Gets or sets device profile. - /// - public DeviceProfile? DeviceProfile { get; set; } - } -}