rama creada apartir de master en j
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace adas_core.Domain.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// Provides static utility methods for handling media-related operations.
|
||||
/// </summary>
|
||||
public static class MediaUtils
|
||||
{
|
||||
public static readonly Dictionary<string, string> Mapping = new(StringComparer.InvariantCultureIgnoreCase)
|
||||
@@ -89,32 +92,50 @@ public static class MediaUtils
|
||||
{ ".wmv", "video/x-ms-wmv" }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Determines the MIME type associated with the file extension of the specified path.
|
||||
/// Performs a case-insensitive lookup against a known extension mapping and falls back to <c>application/octet-stream</c> when the extension is not recognized.
|
||||
/// </summary>
|
||||
/// <param name="filePath">The file path whose extension is used to resolve the MIME type.</param>
|
||||
/// <returns>The corresponding MIME type string if the extension is found in the mapping; otherwise, the default <c>application/octet-stream</c> value.</returns>
|
||||
public static string GetMimeType(string filePath)
|
||||
{
|
||||
var extension = Path.GetExtension(filePath).ToLowerInvariant();
|
||||
return Mapping.TryGetValue(extension, out var mimeType) ? mimeType : "application/octet-stream";
|
||||
}
|
||||
{
|
||||
var extension = Path.GetExtension(filePath).ToLowerInvariant();
|
||||
return Mapping.TryGetValue(extension, out var mimeType) ? mimeType : "application/octet-stream";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified file path corresponds to a supported video file by comparing its extension against a predefined list of video formats (e.g., .mp4, .avi, .mkv, .mov).
|
||||
/// The comparison is case-insensitive.
|
||||
/// </summary>
|
||||
/// <param name="filePath">The path of the file to evaluate.</param>
|
||||
/// <returns><c>true</c> if the file extension matches one of the supported video extensions; otherwise, <c>false</c>.</returns>
|
||||
public static bool IsVideoFile(string filePath)
|
||||
{
|
||||
// Extensiones de video soportadas
|
||||
var videoExtensions = new[]
|
||||
{ ".mp4", ".avi", ".mkv", ".mpeg", ".ogv", ".webm", ".3gp", ".3g2", ".mov", ".wmv", ".m3u8" };
|
||||
return videoExtensions.Contains(Path.GetExtension(filePath), StringComparer.InvariantCultureIgnoreCase);
|
||||
}
|
||||
{
|
||||
// Extensiones de video soportadas
|
||||
var videoExtensions = new[]
|
||||
{ ".mp4", ".avi", ".mkv", ".mpeg", ".ogv", ".webm", ".3gp", ".3g2", ".mov", ".wmv", ".m3u8" };
|
||||
return videoExtensions.Contains(Path.GetExtension(filePath), StringComparer.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the duration of the video at the specified path, expressed in milliseconds.
|
||||
/// Returns null if the duration cannot be read, with the underlying error logged to the console.
|
||||
/// </summary>
|
||||
/// <param name="videoPath">The file path of the video whose duration should be retrieved.</param>
|
||||
/// <returns>The video duration in milliseconds, or null if an error occurs while reading the file.</returns>
|
||||
public static long? GetVideoDuration(string videoPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var file = File.Create(videoPath);
|
||||
var duration = file.Properties.Duration;
|
||||
return (long)duration.TotalMilliseconds;
|
||||
try
|
||||
{
|
||||
var file = File.Create(videoPath);
|
||||
var duration = file.Properties.Duration;
|
||||
return (long)duration.TotalMilliseconds;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user