|
@@ -12,6 +12,10 @@ namespace MediaBrowser.Model.Net
|
|
|
/// <summary>
|
|
|
/// Class MimeTypes.
|
|
|
/// </summary>
|
|
|
+ ///
|
|
|
+ /// http://en.wikipedia.org/wiki/Internet_media_type
|
|
|
+ /// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
|
|
+ /// http://www.iana.org/assignments/media-types/media-types.xhtml
|
|
|
public static class MimeTypes
|
|
|
{
|
|
|
/// <summary>
|
|
@@ -50,81 +54,26 @@ namespace MediaBrowser.Model.Net
|
|
|
".wtv",
|
|
|
};
|
|
|
|
|
|
- // http://en.wikipedia.org/wiki/Internet_media_type
|
|
|
- // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
|
|
- // http://www.iana.org/assignments/media-types/media-types.xhtml
|
|
|
- // Add more as needed
|
|
|
+ /// <summary>
|
|
|
+ /// Used for extensions not in <see cref="Model.MimeTypes"/> or to override them.
|
|
|
+ /// </summary>
|
|
|
private static readonly Dictionary<string, string> _mimeTypeLookup = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
|
|
{
|
|
|
// Type application
|
|
|
- { ".7z", "application/x-7z-compressed" },
|
|
|
- { ".azw", "application/vnd.amazon.ebook" },
|
|
|
{ ".azw3", "application/vnd.amazon.ebook" },
|
|
|
- { ".cbz", "application/x-cbz" },
|
|
|
- { ".cbr", "application/epub+zip" },
|
|
|
- { ".eot", "application/vnd.ms-fontobject" },
|
|
|
- { ".epub", "application/epub+zip" },
|
|
|
- { ".js", "application/x-javascript" },
|
|
|
- { ".json", "application/json" },
|
|
|
- { ".m3u8", "application/x-mpegURL" },
|
|
|
- { ".map", "application/x-javascript" },
|
|
|
- { ".mobi", "application/x-mobipocket-ebook" },
|
|
|
- { ".opf", "application/oebps-package+xml" },
|
|
|
- { ".pdf", "application/pdf" },
|
|
|
- { ".rar", "application/vnd.rar" },
|
|
|
- { ".srt", "application/x-subrip" },
|
|
|
- { ".ttml", "application/ttml+xml" },
|
|
|
- { ".wasm", "application/wasm" },
|
|
|
- { ".xml", "application/xml" },
|
|
|
- { ".zip", "application/zip" },
|
|
|
|
|
|
// Type image
|
|
|
- { ".bmp", "image/bmp" },
|
|
|
- { ".gif", "image/gif" },
|
|
|
- { ".ico", "image/vnd.microsoft.icon" },
|
|
|
- { ".jpg", "image/jpeg" },
|
|
|
- { ".jpeg", "image/jpeg" },
|
|
|
- { ".png", "image/png" },
|
|
|
- { ".svg", "image/svg+xml" },
|
|
|
- { ".svgz", "image/svg+xml" },
|
|
|
{ ".tbn", "image/jpeg" },
|
|
|
- { ".tif", "image/tiff" },
|
|
|
- { ".tiff", "image/tiff" },
|
|
|
- { ".webp", "image/webp" },
|
|
|
-
|
|
|
- // Type font
|
|
|
- { ".ttf", "font/ttf" },
|
|
|
- { ".woff", "font/woff" },
|
|
|
- { ".woff2", "font/woff2" },
|
|
|
|
|
|
// Type text
|
|
|
{ ".ass", "text/x-ssa" },
|
|
|
{ ".ssa", "text/x-ssa" },
|
|
|
- { ".css", "text/css" },
|
|
|
- { ".csv", "text/csv" },
|
|
|
{ ".edl", "text/plain" },
|
|
|
- { ".rtf", "text/rtf" },
|
|
|
- { ".txt", "text/plain" },
|
|
|
- { ".vtt", "text/vtt" },
|
|
|
+ { ".html", "text/html; charset=UTF-8" },
|
|
|
+ { ".htm", "text/html; charset=UTF-8" },
|
|
|
|
|
|
// Type video
|
|
|
- { ".3gp", "video/3gpp" },
|
|
|
- { ".3g2", "video/3gpp2" },
|
|
|
- { ".asf", "video/x-ms-asf" },
|
|
|
- { ".avi", "video/x-msvideo" },
|
|
|
- { ".flv", "video/x-flv" },
|
|
|
- { ".mp4", "video/mp4" },
|
|
|
- { ".m4s", "video/mp4" },
|
|
|
- { ".m4v", "video/x-m4v" },
|
|
|
{ ".mpegts", "video/mp2t" },
|
|
|
- { ".mpg", "video/mpeg" },
|
|
|
- { ".mkv", "video/x-matroska" },
|
|
|
- { ".mov", "video/quicktime" },
|
|
|
- { ".mpd", "video/vnd.mpeg.dash.mpd" },
|
|
|
- { ".ogv", "video/ogg" },
|
|
|
- { ".ts", "video/mp2t" },
|
|
|
- { ".webm", "video/webm" },
|
|
|
- { ".wmv", "video/x-ms-wmv" },
|
|
|
|
|
|
// Type audio
|
|
|
{ ".aac", "audio/aac" },
|
|
@@ -133,37 +82,47 @@ namespace MediaBrowser.Model.Net
|
|
|
{ ".dsf", "audio/dsf" },
|
|
|
{ ".dsp", "audio/dsp" },
|
|
|
{ ".flac", "audio/flac" },
|
|
|
- { ".m4a", "audio/mp4" },
|
|
|
{ ".m4b", "audio/m4b" },
|
|
|
- { ".mid", "audio/midi" },
|
|
|
- { ".midi", "audio/midi" },
|
|
|
{ ".mp3", "audio/mpeg" },
|
|
|
- { ".oga", "audio/ogg" },
|
|
|
- { ".ogg", "audio/ogg" },
|
|
|
- { ".opus", "audio/ogg" },
|
|
|
{ ".vorbis", "audio/vorbis" },
|
|
|
- { ".wav", "audio/wav" },
|
|
|
{ ".webma", "audio/webm" },
|
|
|
- { ".wma", "audio/x-ms-wma" },
|
|
|
{ ".wv", "audio/x-wavpack" },
|
|
|
{ ".xsp", "audio/xsp" },
|
|
|
};
|
|
|
|
|
|
- private static readonly Dictionary<string, string> _extensionLookup = CreateExtensionLookup();
|
|
|
-
|
|
|
- private static Dictionary<string, string> CreateExtensionLookup()
|
|
|
+ private static readonly Dictionary<string, string> _extensionLookup = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
|
|
{
|
|
|
- var dict = _mimeTypeLookup
|
|
|
- .GroupBy(i => i.Value)
|
|
|
- .ToDictionary(x => x.Key, x => x.First().Key, StringComparer.OrdinalIgnoreCase);
|
|
|
+ // Type application
|
|
|
+ { "application/x-cbz", ".cbz" },
|
|
|
+ { "application/x-javascript", ".js" },
|
|
|
+ { "application/xml", ".xml" },
|
|
|
+ { "application/x-mpegURL", ".m3u8" },
|
|
|
+
|
|
|
+ // Type audio
|
|
|
+ { "audio/aac", ".aac" },
|
|
|
+ { "audio/ac3", ".ac3" },
|
|
|
+ { "audio/dsf", ".dsf" },
|
|
|
+ { "audio/dsp", ".dsp" },
|
|
|
+ { "audio/flac", ".flac" },
|
|
|
+ { "audio/m4b", ".m4b" },
|
|
|
+ { "audio/vorbis", ".vorbis" },
|
|
|
+ { "audio/x-ape", ".ape" },
|
|
|
+ { "audio/xsp", ".xsp" },
|
|
|
+ { "audio/x-wavpack", ".wv" },
|
|
|
|
|
|
- dict["image/jpg"] = ".jpg";
|
|
|
- dict["image/x-png"] = ".png";
|
|
|
+ // Type image
|
|
|
+ { "image/jpg", ".jpg" },
|
|
|
+ { "image/x-png", ".png" },
|
|
|
|
|
|
- dict["audio/x-aac"] = ".aac";
|
|
|
+ // Type text
|
|
|
+ { "text/plain", ".txt" },
|
|
|
+ { "text/rtf", ".rtf" },
|
|
|
+ { "text/x-ssa", ".ssa" },
|
|
|
|
|
|
- return dict;
|
|
|
- }
|
|
|
+ // Type video
|
|
|
+ { "video/vnd.mpeg.dash.mpd", ".mpd" },
|
|
|
+ { "video/x-matroska", ".mkv" },
|
|
|
+ };
|
|
|
|
|
|
public static string GetMimeType(string path) => GetMimeType(path, "application/octet-stream");
|
|
|
|
|
@@ -188,29 +147,15 @@ namespace MediaBrowser.Model.Net
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Catch-all for all video types that don't require specific mime types
|
|
|
- if (_videoFileExtensions.Contains(ext))
|
|
|
- {
|
|
|
- return string.Concat("video/", ext.AsSpan(1));
|
|
|
- }
|
|
|
-
|
|
|
- // Type text
|
|
|
- if (string.Equals(ext, ".html", StringComparison.OrdinalIgnoreCase)
|
|
|
- || string.Equals(ext, ".htm", StringComparison.OrdinalIgnoreCase))
|
|
|
- {
|
|
|
- return "text/html; charset=UTF-8";
|
|
|
- }
|
|
|
-
|
|
|
- if (string.Equals(ext, ".log", StringComparison.OrdinalIgnoreCase)
|
|
|
- || string.Equals(ext, ".srt", StringComparison.OrdinalIgnoreCase))
|
|
|
+ if (Model.MimeTypes.TryGetMimeType(filename, out var mimeType))
|
|
|
{
|
|
|
- return "text/plain";
|
|
|
+ return mimeType;
|
|
|
}
|
|
|
|
|
|
- // Misc
|
|
|
- if (string.Equals(ext, ".dll", StringComparison.OrdinalIgnoreCase))
|
|
|
+ // Catch-all for all video types that don't require specific mime types
|
|
|
+ if (_videoFileExtensions.Contains(ext))
|
|
|
{
|
|
|
- return "application/octet-stream";
|
|
|
+ return string.Concat("video/", ext.AsSpan(1));
|
|
|
}
|
|
|
|
|
|
return defaultValue;
|
|
@@ -231,6 +176,12 @@ namespace MediaBrowser.Model.Net
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ var extensions = Model.MimeTypes.GetMimeTypeExtensions(mimeType);
|
|
|
+ if (extensions.Any())
|
|
|
+ {
|
|
|
+ return "." + extensions.First();
|
|
|
+ }
|
|
|
+
|
|
|
return null;
|
|
|
}
|
|
|
}
|