| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Globalization; |
| | | 4 | | using System.IO; |
| | | 5 | | using System.Linq; |
| | | 6 | | using System.Threading; |
| | | 7 | | using System.Threading.Tasks; |
| | | 8 | | using Jellyfin.Api.Extensions; |
| | | 9 | | using Jellyfin.Data.Enums; |
| | | 10 | | using Jellyfin.Extensions; |
| | | 11 | | using MediaBrowser.Common.Configuration; |
| | | 12 | | using MediaBrowser.Common.Extensions; |
| | | 13 | | using MediaBrowser.Controller.Configuration; |
| | | 14 | | using MediaBrowser.Controller.Entities; |
| | | 15 | | using MediaBrowser.Controller.Library; |
| | | 16 | | using MediaBrowser.Controller.MediaEncoding; |
| | | 17 | | using MediaBrowser.Controller.Streaming; |
| | | 18 | | using MediaBrowser.Model.Dlna; |
| | | 19 | | using MediaBrowser.Model.Dto; |
| | | 20 | | using MediaBrowser.Model.Entities; |
| | | 21 | | using Microsoft.AspNetCore.Http; |
| | | 22 | | using Microsoft.AspNetCore.Http.HttpResults; |
| | | 23 | | using Microsoft.Net.Http.Headers; |
| | | 24 | | |
| | | 25 | | namespace Jellyfin.Api.Helpers; |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// The streaming helpers. |
| | | 29 | | /// </summary> |
| | | 30 | | public static class StreamingHelpers |
| | | 31 | | { |
| | | 32 | | /// <summary> |
| | | 33 | | /// Gets the current streaming state. |
| | | 34 | | /// </summary> |
| | | 35 | | /// <param name="streamingRequest">The <see cref="StreamingRequestDto"/>.</param> |
| | | 36 | | /// <param name="httpContext">The <see cref="HttpContext"/>.</param> |
| | | 37 | | /// <param name="mediaSourceManager">Instance of the <see cref="IMediaSourceManager"/> interface.</param> |
| | | 38 | | /// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param> |
| | | 39 | | /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param> |
| | | 40 | | /// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</p |
| | | 41 | | /// <param name="mediaEncoder">Instance of the <see cref="IMediaEncoder"/> interface.</param> |
| | | 42 | | /// <param name="encodingHelper">Instance of <see cref="EncodingHelper"/>.</param> |
| | | 43 | | /// <param name="transcodeManager">Instance of the <see cref="ITranscodeManager"/> interface.</param> |
| | | 44 | | /// <param name="transcodingJobType">The <see cref="TranscodingJobType"/>.</param> |
| | | 45 | | /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> |
| | | 46 | | /// <returns>A <see cref="Task"/> containing the current <see cref="StreamState"/>.</returns> |
| | | 47 | | public static async Task<StreamState> GetStreamingState( |
| | | 48 | | StreamingRequestDto streamingRequest, |
| | | 49 | | HttpContext httpContext, |
| | | 50 | | IMediaSourceManager mediaSourceManager, |
| | | 51 | | IUserManager userManager, |
| | | 52 | | ILibraryManager libraryManager, |
| | | 53 | | IServerConfigurationManager serverConfigurationManager, |
| | | 54 | | IMediaEncoder mediaEncoder, |
| | | 55 | | EncodingHelper encodingHelper, |
| | | 56 | | ITranscodeManager transcodeManager, |
| | | 57 | | TranscodingJobType transcodingJobType, |
| | | 58 | | CancellationToken cancellationToken) |
| | | 59 | | { |
| | | 60 | | var httpRequest = httpContext.Request; |
| | | 61 | | if (!string.IsNullOrWhiteSpace(streamingRequest.Params)) |
| | | 62 | | { |
| | | 63 | | ParseParams(streamingRequest); |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | streamingRequest.StreamOptions = ParseStreamOptions(httpRequest.Query); |
| | | 67 | | if (httpRequest.Path.Value is null) |
| | | 68 | | { |
| | | 69 | | throw new ResourceNotFoundException(nameof(httpRequest.Path)); |
| | | 70 | | } |
| | | 71 | | |
| | | 72 | | var url = httpRequest.Path.Value.AsSpan().RightPart('.').ToString(); |
| | | 73 | | |
| | | 74 | | if (string.IsNullOrEmpty(streamingRequest.AudioCodec)) |
| | | 75 | | { |
| | | 76 | | streamingRequest.AudioCodec = encodingHelper.InferAudioCodec(url); |
| | | 77 | | } |
| | | 78 | | |
| | | 79 | | var state = new StreamState(mediaSourceManager, transcodingJobType, transcodeManager) |
| | | 80 | | { |
| | | 81 | | Request = streamingRequest, |
| | | 82 | | RequestedUrl = url, |
| | | 83 | | UserAgent = httpRequest.Headers[HeaderNames.UserAgent] |
| | | 84 | | }; |
| | | 85 | | |
| | | 86 | | var userId = httpContext.User.GetUserId(); |
| | | 87 | | if (!userId.IsEmpty()) |
| | | 88 | | { |
| | | 89 | | state.User = userManager.GetUserById(userId); |
| | | 90 | | } |
| | | 91 | | |
| | | 92 | | if (state.IsVideoRequest && !string.IsNullOrWhiteSpace(state.Request.VideoCodec)) |
| | | 93 | | { |
| | | 94 | | state.SupportedVideoCodecs = state.Request.VideoCodec.Split(',', StringSplitOptions.RemoveEmptyEntries); |
| | | 95 | | state.Request.VideoCodec = state.SupportedVideoCodecs.FirstOrDefault(); |
| | | 96 | | } |
| | | 97 | | |
| | | 98 | | if (!string.IsNullOrWhiteSpace(streamingRequest.AudioCodec)) |
| | | 99 | | { |
| | | 100 | | state.SupportedAudioCodecs = streamingRequest.AudioCodec.Split(',', StringSplitOptions.RemoveEmptyEntries); |
| | | 101 | | state.Request.AudioCodec = state.SupportedAudioCodecs.FirstOrDefault(mediaEncoder.CanEncodeToAudioCodec) |
| | | 102 | | ?? state.SupportedAudioCodecs.FirstOrDefault(); |
| | | 103 | | } |
| | | 104 | | |
| | | 105 | | if (!string.IsNullOrWhiteSpace(streamingRequest.SubtitleCodec)) |
| | | 106 | | { |
| | | 107 | | state.SupportedSubtitleCodecs = streamingRequest.SubtitleCodec.Split(',', StringSplitOptions.RemoveEmptyEntr |
| | | 108 | | state.Request.SubtitleCodec = state.SupportedSubtitleCodecs.FirstOrDefault(mediaEncoder.CanEncodeToSubtitleC |
| | | 109 | | ?? state.SupportedSubtitleCodecs.FirstOrDefault(); |
| | | 110 | | } |
| | | 111 | | |
| | | 112 | | var item = libraryManager.GetItemById<BaseItem>(streamingRequest.Id) |
| | | 113 | | ?? throw new ResourceNotFoundException(); |
| | | 114 | | |
| | | 115 | | state.IsInputVideo = item.MediaType == MediaType.Video; |
| | | 116 | | |
| | | 117 | | MediaSourceInfo? mediaSource = null; |
| | | 118 | | if (string.IsNullOrWhiteSpace(streamingRequest.LiveStreamId)) |
| | | 119 | | { |
| | | 120 | | var currentJob = !string.IsNullOrWhiteSpace(streamingRequest.PlaySessionId) |
| | | 121 | | ? transcodeManager.GetTranscodingJob(streamingRequest.PlaySessionId) |
| | | 122 | | : null; |
| | | 123 | | |
| | | 124 | | if (currentJob is not null) |
| | | 125 | | { |
| | | 126 | | mediaSource = currentJob.MediaSource; |
| | | 127 | | } |
| | | 128 | | |
| | | 129 | | if (mediaSource is null) |
| | | 130 | | { |
| | | 131 | | var mediaSources = await mediaSourceManager.GetPlaybackMediaSources(libraryManager.GetItemById<BaseItem> |
| | | 132 | | |
| | | 133 | | mediaSource = string.IsNullOrEmpty(streamingRequest.MediaSourceId) |
| | | 134 | | ? mediaSources[0] |
| | | 135 | | : mediaSources.FirstOrDefault(i => string.Equals(i.Id, streamingRequest.MediaSourceId, StringCompari |
| | | 136 | | |
| | | 137 | | if (mediaSource is null && Guid.Parse(streamingRequest.MediaSourceId).Equals(streamingRequest.Id)) |
| | | 138 | | { |
| | | 139 | | mediaSource = mediaSources[0]; |
| | | 140 | | } |
| | | 141 | | } |
| | | 142 | | } |
| | | 143 | | else |
| | | 144 | | { |
| | | 145 | | var liveStreamInfo = await mediaSourceManager.GetLiveStreamWithDirectStreamProvider(streamingRequest.LiveStr |
| | | 146 | | mediaSource = liveStreamInfo.Item1; |
| | | 147 | | state.DirectStreamProvider = liveStreamInfo.Item2; |
| | | 148 | | |
| | | 149 | | // Cap the max bitrate when it is too high. This is usually due to ffmpeg is unable to probe the source live |
| | | 150 | | if (mediaSource.FallbackMaxStreamingBitrate is not null && streamingRequest.VideoBitRate is not null) |
| | | 151 | | { |
| | | 152 | | streamingRequest.VideoBitRate = Math.Min(streamingRequest.VideoBitRate.Value, mediaSource.FallbackMaxStr |
| | | 153 | | } |
| | | 154 | | } |
| | | 155 | | |
| | | 156 | | var encodingOptions = serverConfigurationManager.GetEncodingOptions(); |
| | | 157 | | |
| | | 158 | | encodingHelper.AttachMediaSourceInfo(state, encodingOptions, mediaSource, url); |
| | | 159 | | |
| | | 160 | | string? containerInternal = Path.GetExtension(state.RequestedUrl); |
| | | 161 | | |
| | | 162 | | if (!string.IsNullOrEmpty(streamingRequest.Container)) |
| | | 163 | | { |
| | | 164 | | containerInternal = streamingRequest.Container; |
| | | 165 | | } |
| | | 166 | | |
| | | 167 | | if (string.IsNullOrEmpty(containerInternal)) |
| | | 168 | | { |
| | | 169 | | containerInternal = streamingRequest.Static ? |
| | | 170 | | StreamBuilder.NormalizeMediaSourceFormatIntoSingleContainer(state.InputContainer, null, DlnaProfileType. |
| | | 171 | | : GetOutputFileExtension(state, mediaSource); |
| | | 172 | | } |
| | | 173 | | |
| | | 174 | | var outputAudioCodec = streamingRequest.AudioCodec; |
| | | 175 | | state.OutputAudioCodec = outputAudioCodec; |
| | | 176 | | state.OutputContainer = (containerInternal ?? string.Empty).TrimStart('.'); |
| | | 177 | | state.OutputAudioChannels = encodingHelper.GetNumAudioChannelsParam(state, state.AudioStream, state.OutputAudioC |
| | | 178 | | if (EncodingHelper.LosslessAudioCodecs.Contains(outputAudioCodec)) |
| | | 179 | | { |
| | | 180 | | state.OutputAudioBitrate = state.AudioStream.BitRate ?? 0; |
| | | 181 | | } |
| | | 182 | | else |
| | | 183 | | { |
| | | 184 | | state.OutputAudioBitrate = encodingHelper.GetAudioBitrateParam(streamingRequest.AudioBitRate, streamingReque |
| | | 185 | | } |
| | | 186 | | |
| | | 187 | | if (outputAudioCodec.StartsWith("pcm_", StringComparison.Ordinal)) |
| | | 188 | | { |
| | | 189 | | containerInternal = ".pcm"; |
| | | 190 | | } |
| | | 191 | | |
| | | 192 | | if (state.VideoRequest is not null) |
| | | 193 | | { |
| | | 194 | | state.OutputVideoCodec = state.Request.VideoCodec; |
| | | 195 | | state.OutputVideoBitrate = encodingHelper.GetVideoBitrateParamValue(state.VideoRequest, state.VideoStream, s |
| | | 196 | | |
| | | 197 | | encodingHelper.TryStreamCopy(state); |
| | | 198 | | |
| | | 199 | | if (!EncodingHelper.IsCopyCodec(state.OutputVideoCodec) && state.OutputVideoBitrate.HasValue) |
| | | 200 | | { |
| | | 201 | | var isVideoResolutionNotRequested = !state.VideoRequest.Width.HasValue |
| | | 202 | | && !state.VideoRequest.Height.HasValue |
| | | 203 | | && !state.VideoRequest.MaxWidth.HasValue |
| | | 204 | | && !state.VideoRequest.MaxHeight.HasValue; |
| | | 205 | | |
| | | 206 | | if (isVideoResolutionNotRequested |
| | | 207 | | && state.VideoStream is not null |
| | | 208 | | && state.VideoRequest.VideoBitRate.HasValue |
| | | 209 | | && state.VideoStream.BitRate.HasValue |
| | | 210 | | && state.VideoRequest.VideoBitRate.Value >= state.VideoStream.BitRate.Value) |
| | | 211 | | { |
| | | 212 | | // Don't downscale the resolution if the width/height/MaxWidth/MaxHeight is not requested, |
| | | 213 | | // and the requested video bitrate is greater than source video bitrate. |
| | | 214 | | if (state.VideoStream.Width.HasValue || state.VideoStream.Height.HasValue) |
| | | 215 | | { |
| | | 216 | | state.VideoRequest.MaxWidth = state.VideoStream?.Width; |
| | | 217 | | state.VideoRequest.MaxHeight = state.VideoStream?.Height; |
| | | 218 | | } |
| | | 219 | | } |
| | | 220 | | else |
| | | 221 | | { |
| | | 222 | | var h264EquivalentBitrate = EncodingHelper.ScaleBitrate( |
| | | 223 | | state.OutputVideoBitrate.Value, |
| | | 224 | | state.ActualOutputVideoCodec, |
| | | 225 | | "h264"); |
| | | 226 | | var resolution = ResolutionNormalizer.Normalize( |
| | | 227 | | state.VideoStream?.BitRate, |
| | | 228 | | state.OutputVideoBitrate.Value, |
| | | 229 | | h264EquivalentBitrate, |
| | | 230 | | state.VideoRequest.MaxWidth, |
| | | 231 | | state.VideoRequest.MaxHeight, |
| | | 232 | | state.TargetFramerate); |
| | | 233 | | |
| | | 234 | | state.VideoRequest.MaxWidth = resolution.MaxWidth; |
| | | 235 | | state.VideoRequest.MaxHeight = resolution.MaxHeight; |
| | | 236 | | } |
| | | 237 | | } |
| | | 238 | | |
| | | 239 | | if (state.AudioStream is not null && !EncodingHelper.IsCopyCodec(state.OutputAudioCodec) && string.Equals(st |
| | | 240 | | { |
| | | 241 | | state.OutputAudioCodec = state.SupportedAudioCodecs.Where(c => !EncodingHelper.LosslessAudioCodecs.Conta |
| | | 242 | | } |
| | | 243 | | } |
| | | 244 | | |
| | | 245 | | var ext = string.IsNullOrWhiteSpace(state.OutputContainer) |
| | | 246 | | ? GetOutputFileExtension(state, mediaSource) |
| | | 247 | | : ("." + GetContainerFileExtension(state.OutputContainer)); |
| | | 248 | | |
| | | 249 | | state.OutputFilePath = GetOutputFilePath(state, ext, serverConfigurationManager, streamingRequest.DeviceId, stre |
| | | 250 | | |
| | | 251 | | return state; |
| | | 252 | | } |
| | | 253 | | |
| | | 254 | | /// <summary> |
| | | 255 | | /// Parses query parameters as StreamOptions. |
| | | 256 | | /// </summary> |
| | | 257 | | /// <param name="queryString">The query string.</param> |
| | | 258 | | /// <returns>A <see cref="Dictionary{String,String}"/> containing the stream options.</returns> |
| | | 259 | | private static Dictionary<string, string?> ParseStreamOptions(IQueryCollection queryString) |
| | | 260 | | { |
| | 0 | 261 | | Dictionary<string, string?> streamOptions = new Dictionary<string, string?>(); |
| | 0 | 262 | | foreach (var param in queryString) |
| | | 263 | | { |
| | 0 | 264 | | if (char.IsLower(param.Key[0])) |
| | | 265 | | { |
| | | 266 | | // This was probably not parsed initially and should be a StreamOptions |
| | | 267 | | // or the generated URL should correctly serialize it |
| | | 268 | | // TODO: This should be incorporated either in the lower framework for parsing requests |
| | 0 | 269 | | streamOptions[param.Key] = param.Value; |
| | | 270 | | } |
| | | 271 | | } |
| | | 272 | | |
| | 0 | 273 | | return streamOptions; |
| | | 274 | | } |
| | | 275 | | |
| | | 276 | | /// <summary> |
| | | 277 | | /// Gets the output file extension. |
| | | 278 | | /// </summary> |
| | | 279 | | /// <param name="state">The state.</param> |
| | | 280 | | /// <param name="mediaSource">The mediaSource.</param> |
| | | 281 | | /// <returns>System.String.</returns> |
| | | 282 | | private static string GetOutputFileExtension(StreamState state, MediaSourceInfo? mediaSource) |
| | | 283 | | { |
| | 0 | 284 | | var ext = Path.GetExtension(state.RequestedUrl); |
| | 0 | 285 | | if (!string.IsNullOrEmpty(ext)) |
| | | 286 | | { |
| | 0 | 287 | | return ext; |
| | | 288 | | } |
| | | 289 | | |
| | | 290 | | // Try to infer based on the desired video codec |
| | 0 | 291 | | if (state.IsVideoRequest) |
| | | 292 | | { |
| | 0 | 293 | | var videoCodec = state.Request.VideoCodec; |
| | | 294 | | |
| | 0 | 295 | | if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase)) |
| | | 296 | | { |
| | 0 | 297 | | return ".ts"; |
| | | 298 | | } |
| | | 299 | | |
| | 0 | 300 | | if (string.Equals(videoCodec, "hevc", StringComparison.OrdinalIgnoreCase) |
| | 0 | 301 | | || string.Equals(videoCodec, "av1", StringComparison.OrdinalIgnoreCase)) |
| | | 302 | | { |
| | 0 | 303 | | return ".mp4"; |
| | | 304 | | } |
| | | 305 | | |
| | 0 | 306 | | if (string.Equals(videoCodec, "theora", StringComparison.OrdinalIgnoreCase)) |
| | | 307 | | { |
| | 0 | 308 | | return ".ogv"; |
| | | 309 | | } |
| | | 310 | | |
| | 0 | 311 | | if (string.Equals(videoCodec, "vp8", StringComparison.OrdinalIgnoreCase) |
| | 0 | 312 | | || string.Equals(videoCodec, "vp9", StringComparison.OrdinalIgnoreCase) |
| | 0 | 313 | | || string.Equals(videoCodec, "vpx", StringComparison.OrdinalIgnoreCase)) |
| | | 314 | | { |
| | 0 | 315 | | return ".webm"; |
| | | 316 | | } |
| | | 317 | | |
| | 0 | 318 | | if (string.Equals(videoCodec, "wmv", StringComparison.OrdinalIgnoreCase)) |
| | | 319 | | { |
| | 0 | 320 | | return ".asf"; |
| | | 321 | | } |
| | | 322 | | } |
| | | 323 | | else |
| | | 324 | | { |
| | | 325 | | // Try to infer based on the desired audio codec |
| | 0 | 326 | | var audioCodec = state.Request.AudioCodec; |
| | | 327 | | |
| | 0 | 328 | | if (string.Equals("aac", audioCodec, StringComparison.OrdinalIgnoreCase)) |
| | | 329 | | { |
| | 0 | 330 | | return ".aac"; |
| | | 331 | | } |
| | | 332 | | |
| | 0 | 333 | | if (string.Equals("mp3", audioCodec, StringComparison.OrdinalIgnoreCase)) |
| | | 334 | | { |
| | 0 | 335 | | return ".mp3"; |
| | | 336 | | } |
| | | 337 | | |
| | 0 | 338 | | if (string.Equals("vorbis", audioCodec, StringComparison.OrdinalIgnoreCase)) |
| | | 339 | | { |
| | 0 | 340 | | return ".ogg"; |
| | | 341 | | } |
| | | 342 | | |
| | 0 | 343 | | if (string.Equals("wma", audioCodec, StringComparison.OrdinalIgnoreCase)) |
| | | 344 | | { |
| | 0 | 345 | | return ".wma"; |
| | | 346 | | } |
| | | 347 | | } |
| | | 348 | | |
| | | 349 | | // Fallback to the container of mediaSource |
| | 0 | 350 | | if (!string.IsNullOrEmpty(mediaSource?.Container)) |
| | | 351 | | { |
| | 0 | 352 | | var idx = mediaSource.Container.IndexOf(',', StringComparison.OrdinalIgnoreCase); |
| | 0 | 353 | | return '.' + (idx == -1 ? mediaSource.Container : mediaSource.Container[..idx]).Trim(); |
| | | 354 | | } |
| | | 355 | | |
| | 0 | 356 | | throw new InvalidOperationException("Failed to find an appropriate file extension"); |
| | | 357 | | } |
| | | 358 | | |
| | | 359 | | /// <summary> |
| | | 360 | | /// Gets the output file path for transcoding. |
| | | 361 | | /// </summary> |
| | | 362 | | /// <param name="state">The current <see cref="StreamState"/>.</param> |
| | | 363 | | /// <param name="outputFileExtension">The file extension of the output file.</param> |
| | | 364 | | /// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</p |
| | | 365 | | /// <param name="deviceId">The device id.</param> |
| | | 366 | | /// <param name="playSessionId">The play session id.</param> |
| | | 367 | | /// <returns>The complete file path, including the folder, for the transcoding file.</returns> |
| | | 368 | | private static string GetOutputFilePath(StreamState state, string outputFileExtension, IServerConfigurationManager s |
| | | 369 | | { |
| | 0 | 370 | | var data = $"{state.MediaPath}-{state.UserAgent}-{deviceId!}-{playSessionId!}"; |
| | | 371 | | |
| | 0 | 372 | | var filename = data.GetMD5().ToString("N", CultureInfo.InvariantCulture); |
| | 0 | 373 | | var ext = outputFileExtension.ToLowerInvariant(); |
| | 0 | 374 | | var folder = serverConfigurationManager.GetTranscodePath(); |
| | | 375 | | |
| | 0 | 376 | | return Path.Combine(folder, filename + ext); |
| | | 377 | | } |
| | | 378 | | |
| | | 379 | | /// <summary> |
| | | 380 | | /// Parses the parameters. |
| | | 381 | | /// </summary> |
| | | 382 | | /// <param name="request">The request.</param> |
| | | 383 | | private static void ParseParams(StreamingRequestDto request) |
| | | 384 | | { |
| | 0 | 385 | | if (string.IsNullOrEmpty(request.Params)) |
| | | 386 | | { |
| | 0 | 387 | | return; |
| | | 388 | | } |
| | | 389 | | |
| | 0 | 390 | | var vals = request.Params.Split(';'); |
| | | 391 | | |
| | 0 | 392 | | var videoRequest = request as VideoRequestDto; |
| | | 393 | | |
| | 0 | 394 | | for (var i = 0; i < vals.Length; i++) |
| | | 395 | | { |
| | 0 | 396 | | var val = vals[i]; |
| | | 397 | | |
| | 0 | 398 | | if (string.IsNullOrWhiteSpace(val)) |
| | | 399 | | { |
| | | 400 | | continue; |
| | | 401 | | } |
| | | 402 | | |
| | | 403 | | switch (i) |
| | | 404 | | { |
| | | 405 | | case 0: |
| | | 406 | | // DeviceProfileId |
| | | 407 | | break; |
| | | 408 | | case 1: |
| | 0 | 409 | | request.DeviceId = val; |
| | 0 | 410 | | break; |
| | | 411 | | case 2: |
| | 0 | 412 | | request.MediaSourceId = val; |
| | 0 | 413 | | break; |
| | | 414 | | case 3: |
| | 0 | 415 | | request.Static = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); |
| | 0 | 416 | | break; |
| | | 417 | | case 4: |
| | 0 | 418 | | if (videoRequest is not null) |
| | | 419 | | { |
| | 0 | 420 | | videoRequest.VideoCodec = val; |
| | | 421 | | } |
| | | 422 | | |
| | 0 | 423 | | break; |
| | | 424 | | case 5: |
| | 0 | 425 | | request.AudioCodec = val; |
| | 0 | 426 | | break; |
| | | 427 | | case 6: |
| | 0 | 428 | | if (videoRequest is not null) |
| | | 429 | | { |
| | 0 | 430 | | videoRequest.AudioStreamIndex = int.Parse(val, CultureInfo.InvariantCulture); |
| | | 431 | | } |
| | | 432 | | |
| | 0 | 433 | | break; |
| | | 434 | | case 7: |
| | 0 | 435 | | if (videoRequest is not null) |
| | | 436 | | { |
| | 0 | 437 | | videoRequest.SubtitleStreamIndex = int.Parse(val, CultureInfo.InvariantCulture); |
| | | 438 | | } |
| | | 439 | | |
| | 0 | 440 | | break; |
| | | 441 | | case 8: |
| | 0 | 442 | | if (videoRequest is not null) |
| | | 443 | | { |
| | 0 | 444 | | videoRequest.VideoBitRate = int.Parse(val, CultureInfo.InvariantCulture); |
| | | 445 | | } |
| | | 446 | | |
| | 0 | 447 | | break; |
| | | 448 | | case 9: |
| | 0 | 449 | | request.AudioBitRate = int.Parse(val, CultureInfo.InvariantCulture); |
| | 0 | 450 | | break; |
| | | 451 | | case 10: |
| | 0 | 452 | | request.MaxAudioChannels = int.Parse(val, CultureInfo.InvariantCulture); |
| | 0 | 453 | | break; |
| | | 454 | | case 11: |
| | 0 | 455 | | if (videoRequest is not null) |
| | | 456 | | { |
| | 0 | 457 | | videoRequest.MaxFramerate = float.Parse(val, CultureInfo.InvariantCulture); |
| | | 458 | | } |
| | | 459 | | |
| | 0 | 460 | | break; |
| | | 461 | | case 12: |
| | 0 | 462 | | if (videoRequest is not null) |
| | | 463 | | { |
| | 0 | 464 | | videoRequest.MaxWidth = int.Parse(val, CultureInfo.InvariantCulture); |
| | | 465 | | } |
| | | 466 | | |
| | 0 | 467 | | break; |
| | | 468 | | case 13: |
| | 0 | 469 | | if (videoRequest is not null) |
| | | 470 | | { |
| | 0 | 471 | | videoRequest.MaxHeight = int.Parse(val, CultureInfo.InvariantCulture); |
| | | 472 | | } |
| | | 473 | | |
| | 0 | 474 | | break; |
| | | 475 | | case 14: |
| | 0 | 476 | | request.StartTimeTicks = long.Parse(val, CultureInfo.InvariantCulture); |
| | 0 | 477 | | break; |
| | | 478 | | case 15: |
| | 0 | 479 | | if (videoRequest is not null) |
| | | 480 | | { |
| | 0 | 481 | | videoRequest.Level = val; |
| | | 482 | | } |
| | | 483 | | |
| | 0 | 484 | | break; |
| | | 485 | | case 16: |
| | 0 | 486 | | if (videoRequest is not null) |
| | | 487 | | { |
| | 0 | 488 | | videoRequest.MaxRefFrames = int.Parse(val, CultureInfo.InvariantCulture); |
| | | 489 | | } |
| | | 490 | | |
| | 0 | 491 | | break; |
| | | 492 | | case 17: |
| | 0 | 493 | | if (videoRequest is not null) |
| | | 494 | | { |
| | 0 | 495 | | videoRequest.MaxVideoBitDepth = int.Parse(val, CultureInfo.InvariantCulture); |
| | | 496 | | } |
| | | 497 | | |
| | 0 | 498 | | break; |
| | | 499 | | case 18: |
| | 0 | 500 | | if (videoRequest is not null) |
| | | 501 | | { |
| | 0 | 502 | | videoRequest.Profile = val; |
| | | 503 | | } |
| | | 504 | | |
| | 0 | 505 | | break; |
| | | 506 | | case 19: |
| | | 507 | | // cabac no longer used |
| | | 508 | | break; |
| | | 509 | | case 20: |
| | 0 | 510 | | request.PlaySessionId = val; |
| | 0 | 511 | | break; |
| | | 512 | | case 21: |
| | | 513 | | // api_key |
| | | 514 | | break; |
| | | 515 | | case 22: |
| | 0 | 516 | | request.LiveStreamId = val; |
| | 0 | 517 | | break; |
| | | 518 | | case 23: |
| | | 519 | | // Duplicating ItemId because of MediaMonkey |
| | | 520 | | break; |
| | | 521 | | case 24: |
| | 0 | 522 | | if (videoRequest is not null) |
| | | 523 | | { |
| | 0 | 524 | | videoRequest.CopyTimestamps = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); |
| | | 525 | | } |
| | | 526 | | |
| | 0 | 527 | | break; |
| | | 528 | | case 25: |
| | 0 | 529 | | if (!string.IsNullOrWhiteSpace(val) && videoRequest is not null) |
| | | 530 | | { |
| | 0 | 531 | | if (Enum.TryParse(val, out SubtitleDeliveryMethod method)) |
| | | 532 | | { |
| | 0 | 533 | | videoRequest.SubtitleMethod = method; |
| | | 534 | | } |
| | | 535 | | } |
| | | 536 | | |
| | 0 | 537 | | break; |
| | | 538 | | case 26: |
| | 0 | 539 | | request.TranscodingMaxAudioChannels = int.Parse(val, CultureInfo.InvariantCulture); |
| | 0 | 540 | | break; |
| | | 541 | | case 27: |
| | 0 | 542 | | if (videoRequest is not null) |
| | | 543 | | { |
| | 0 | 544 | | videoRequest.EnableSubtitlesInManifest = string.Equals("true", val, StringComparison.OrdinalIgno |
| | | 545 | | } |
| | | 546 | | |
| | 0 | 547 | | break; |
| | | 548 | | case 28: |
| | 0 | 549 | | request.Tag = val; |
| | 0 | 550 | | break; |
| | | 551 | | case 29: |
| | 0 | 552 | | if (videoRequest is not null) |
| | | 553 | | { |
| | 0 | 554 | | videoRequest.RequireAvc = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); |
| | | 555 | | } |
| | | 556 | | |
| | 0 | 557 | | break; |
| | | 558 | | case 30: |
| | 0 | 559 | | request.SubtitleCodec = val; |
| | 0 | 560 | | break; |
| | | 561 | | case 31: |
| | 0 | 562 | | if (videoRequest is not null) |
| | | 563 | | { |
| | 0 | 564 | | videoRequest.RequireNonAnamorphic = string.Equals("true", val, StringComparison.OrdinalIgnoreCas |
| | | 565 | | } |
| | | 566 | | |
| | 0 | 567 | | break; |
| | | 568 | | case 32: |
| | 0 | 569 | | if (videoRequest is not null) |
| | | 570 | | { |
| | 0 | 571 | | videoRequest.DeInterlace = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); |
| | | 572 | | } |
| | | 573 | | |
| | 0 | 574 | | break; |
| | | 575 | | case 33: |
| | 0 | 576 | | request.TranscodeReasons = val; |
| | | 577 | | break; |
| | | 578 | | } |
| | | 579 | | } |
| | 0 | 580 | | } |
| | | 581 | | |
| | | 582 | | /// <summary> |
| | | 583 | | /// Parses the container into its file extension. |
| | | 584 | | /// </summary> |
| | | 585 | | /// <param name="container">The container.</param> |
| | | 586 | | private static string? GetContainerFileExtension(string? container) |
| | | 587 | | { |
| | 0 | 588 | | if (string.Equals(container, "mpegts", StringComparison.OrdinalIgnoreCase)) |
| | | 589 | | { |
| | 0 | 590 | | return "ts"; |
| | | 591 | | } |
| | | 592 | | |
| | 0 | 593 | | if (string.Equals(container, "matroska", StringComparison.OrdinalIgnoreCase)) |
| | | 594 | | { |
| | 0 | 595 | | return "mkv"; |
| | | 596 | | } |
| | | 597 | | |
| | 0 | 598 | | return container; |
| | | 599 | | } |
| | | 600 | | } |