| | 1 | | #pragma warning disable CS1591 |
| | 2 | |
|
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Globalization; |
| | 6 | | using System.Linq; |
| | 7 | | using MediaBrowser.Model.MediaInfo; |
| | 8 | |
|
| | 9 | | namespace MediaBrowser.MediaEncoding.Encoder |
| | 10 | | { |
| | 11 | | public static class EncodingUtils |
| | 12 | | { |
| | 13 | | public static string GetInputArgument(string inputPrefix, string inputFile, MediaProtocol protocol) |
| | 14 | | { |
| 0 | 15 | | if (protocol != MediaProtocol.File) |
| | 16 | | { |
| 0 | 17 | | return string.Format(CultureInfo.InvariantCulture, "\"{0}\"", inputFile); |
| | 18 | | } |
| | 19 | |
|
| 0 | 20 | | return GetFileInputArgument(inputFile, inputPrefix); |
| | 21 | | } |
| | 22 | |
|
| | 23 | | public static string GetInputArgument(string inputPrefix, IReadOnlyList<string> inputFiles, MediaProtocol protoc |
| | 24 | | { |
| 0 | 25 | | if (protocol != MediaProtocol.File) |
| | 26 | | { |
| 0 | 27 | | return string.Format(CultureInfo.InvariantCulture, "\"{0}\"", inputFiles[0]); |
| | 28 | | } |
| | 29 | |
|
| 0 | 30 | | return GetConcatInputArgument(inputFiles, inputPrefix); |
| | 31 | | } |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// Gets the concat input argument. |
| | 35 | | /// </summary> |
| | 36 | | /// <param name="inputFiles">The input files.</param> |
| | 37 | | /// <param name="inputPrefix">The input prefix.</param> |
| | 38 | | /// <returns>System.String.</returns> |
| | 39 | | private static string GetConcatInputArgument(IReadOnlyList<string> inputFiles, string inputPrefix) |
| | 40 | | { |
| | 41 | | // Get all streams |
| | 42 | | // If there's more than one we'll need to use the concat command |
| 0 | 43 | | if (inputFiles.Count > 1) |
| | 44 | | { |
| 0 | 45 | | var files = string.Join('|', inputFiles.Select(NormalizePath)); |
| | 46 | |
|
| 0 | 47 | | return string.Format(CultureInfo.InvariantCulture, "concat:\"{0}\"", files); |
| | 48 | | } |
| | 49 | |
|
| | 50 | | // Determine the input path for video files |
| 0 | 51 | | return GetFileInputArgument(inputFiles[0], inputPrefix); |
| | 52 | | } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Gets the file input argument. |
| | 56 | | /// </summary> |
| | 57 | | /// <param name="path">The path.</param> |
| | 58 | | /// <param name="inputPrefix">The path prefix.</param> |
| | 59 | | /// <returns>System.String.</returns> |
| | 60 | | private static string GetFileInputArgument(string path, string inputPrefix) |
| | 61 | | { |
| 0 | 62 | | if (path.Contains("://", StringComparison.Ordinal)) |
| | 63 | | { |
| 0 | 64 | | return string.Format(CultureInfo.InvariantCulture, "\"{0}\"", path); |
| | 65 | | } |
| | 66 | |
|
| | 67 | | // Quotes are valid path characters in linux and they need to be escaped here with a leading \ |
| 0 | 68 | | path = NormalizePath(path); |
| | 69 | |
|
| 0 | 70 | | return string.Format(CultureInfo.InvariantCulture, "{1}:\"{0}\"", path, inputPrefix); |
| | 71 | | } |
| | 72 | |
|
| | 73 | | /// <summary> |
| | 74 | | /// Normalizes the path. |
| | 75 | | /// </summary> |
| | 76 | | /// <param name="path">The path.</param> |
| | 77 | | /// <returns>System.String.</returns> |
| | 78 | | public static string NormalizePath(string path) |
| | 79 | | { |
| | 80 | | // Quotes are valid path characters in linux and they need to be escaped here with a leading \ |
| 0 | 81 | | return path.Replace("\"", "\\\"", StringComparison.Ordinal); |
| | 82 | | } |
| | 83 | | } |
| | 84 | | } |