From f336d20b065c873f0f321c7a1cec565f5a77a806 Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 23 Nov 2020 09:49:42 -0700 Subject: [PATCH] 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