| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 | 
							- using MediaBrowser.Model.Extensions;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.IO;
 
- using System.Linq;
 
- namespace MediaBrowser.Model.Net
 
- {
 
-     /// <summary>
 
-     /// Class MimeTypes
 
-     /// </summary>
 
-     public static class MimeTypes
 
-     {
 
-         /// <summary>
 
-         /// Any extension in this list is considered a video file - can be added to at runtime for extensibility
 
-         /// </summary>
 
-         private static readonly List<string> VideoFileExtensions = new List<string>
 
-             {
 
-                 ".mkv",
 
-                 ".m2t",
 
-                 ".m2ts",
 
-                 ".img",
 
-                 ".iso",
 
-                 ".mk3d",
 
-                 ".ts",
 
-                 ".rmvb",
 
-                 ".mov",
 
-                 ".avi",
 
-                 ".mpg",
 
-                 ".mpeg",
 
-                 ".wmv",
 
-                 ".mp4",
 
-                 ".divx",
 
-                 ".dvr-ms",
 
-                 ".wtv",
 
-                 ".ogm",
 
-                 ".ogv",
 
-                 ".asf",
 
-                 ".m4v",
 
-                 ".flv",
 
-                 ".f4v",
 
-                 ".3gp",
 
-                 ".webm",
 
-                 ".mts",
 
-                 ".m2v",
 
-                 ".rec"
 
-         };
 
-         private static Dictionary<string, string> GetVideoFileExtensionsDictionary()
 
-         {
 
-             Dictionary<string, string> dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
 
-             foreach (string ext in VideoFileExtensions)
 
-             {
 
-                 dict[ext] = ext;
 
-             }
 
-             return dict;
 
-         }
 
-         private static readonly Dictionary<string, string> VideoFileExtensionsDictionary = GetVideoFileExtensionsDictionary();
 
-         // http://en.wikipedia.org/wiki/Internet_media_type
 
-         // Add more as needed
 
-         private static Dictionary<string, string> GetMimeTypeLookup()
 
-         {
 
-             Dictionary<string, string> dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
 
-             dict.Add(".jpg", "image/jpeg");
 
-             dict.Add(".jpeg", "image/jpeg");
 
-             dict.Add(".tbn", "image/jpeg");
 
-             dict.Add(".png", "image/png");
 
-             dict.Add(".gif", "image/gif");
 
-             dict.Add(".webp", "image/webp");
 
-             dict.Add(".ico", "image/vnd.microsoft.icon");
 
-             dict.Add(".mpg", "video/mpeg");
 
-             dict.Add(".mpeg", "video/mpeg");
 
-             dict.Add(".ogv", "video/ogg");
 
-             dict.Add(".mov", "video/quicktime");
 
-             dict.Add(".webm", "video/webm");
 
-             dict.Add(".mkv", "video/x-matroska");
 
-             dict.Add(".wmv", "video/x-ms-wmv");
 
-             dict.Add(".flv", "video/x-flv");
 
-             dict.Add(".avi", "video/x-msvideo");
 
-             dict.Add(".asf", "video/x-ms-asf");
 
-             dict.Add(".m4v", "video/x-m4v");
 
-             return dict;
 
-         }
 
-         private static readonly Dictionary<string, string> MimeTypeLookup = GetMimeTypeLookup();
 
-         private static readonly Dictionary<string, string> ExtensionLookup = CreateExtensionLookup();
 
-         private static Dictionary<string, string> CreateExtensionLookup()
 
-         {
 
-             var dict = MimeTypeLookup
 
-                 .GroupBy(i => i.Value)
 
-                 .ToDictionary(x => x.Key, x => x.First().Key, StringComparer.OrdinalIgnoreCase);
 
-             dict["image/jpg"] = ".jpg";
 
-             return dict;
 
-         }
 
-         /// <summary>
 
-         /// Gets the type of the MIME.
 
-         /// </summary>
 
-         /// <param name="path">The path.</param>
 
-         /// <returns>System.String.</returns>
 
-         /// <exception cref="ArgumentNullException">path</exception>
 
-         /// <exception cref="InvalidOperationException">Argument not supported:  + path</exception>
 
-         public static string GetMimeType(string path)
 
-         {
 
-             if (string.IsNullOrEmpty(path))
 
-             {
 
-                 throw new ArgumentNullException("path");
 
-             }
 
-             var ext = Path.GetExtension(path) ?? string.Empty;
 
-             string result;
 
-             if (MimeTypeLookup.TryGetValue(ext, out result))
 
-             {
 
-                 return result;
 
-             }
 
-             // Type video
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".3gp"))
 
-             {
 
-                 return "video/3gpp";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".3g2"))
 
-             {
 
-                 return "video/3gpp2";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".ts"))
 
-             {
 
-                 return "video/mp2t";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".mpd"))
 
-             {
 
-                 return "video/vnd.mpeg.dash.mpd";
 
-             }
 
-             // Catch-all for all video types that don't require specific mime types
 
-             if (VideoFileExtensionsDictionary.ContainsKey(ext))
 
-             {
 
-                 return "video/" + ext.TrimStart('.').ToLower();
 
-             }
 
-             // Type text
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".css"))
 
-             {
 
-                 return "text/css";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".csv"))
 
-             {
 
-                 return "text/csv";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".html"))
 
-             {
 
-                 return "text/html; charset=UTF-8";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".htm"))
 
-             {
 
-                 return "text/html; charset=UTF-8";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".txt"))
 
-             {
 
-                 return "text/plain";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".xml"))
 
-             {
 
-                 return "application/xml";
 
-             }
 
-             // Type document
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".pdf"))
 
-             {
 
-                 return "application/pdf";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".mobi"))
 
-             {
 
-                 return "application/x-mobipocket-ebook";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".epub"))
 
-             {
 
-                 return "application/epub+zip";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".cbz"))
 
-             {
 
-                 return "application/epub+zip";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".cbr"))
 
-             {
 
-                 return "application/epub+zip";
 
-             }
 
-             // Type audio
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".mp3"))
 
-             {
 
-                 return "audio/mpeg";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".m4a"))
 
-             {
 
-                 return "audio/mp4";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".aac"))
 
-             {
 
-                 return "audio/mp4";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".webma"))
 
-             {
 
-                 return "audio/webm";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".wav"))
 
-             {
 
-                 return "audio/wav";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".wma"))
 
-             {
 
-                 return "audio/x-ms-wma";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".flac"))
 
-             {
 
-                 return "audio/flac";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".aac"))
 
-             {
 
-                 return "audio/x-aac";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".ogg"))
 
-             {
 
-                 return "audio/ogg";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".oga"))
 
-             {
 
-                 return "audio/ogg";
 
-             }
 
-             // Playlists
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".m3u8"))
 
-             {
 
-                 return "application/x-mpegURL";
 
-             }
 
-             // Misc
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".dll"))
 
-             {
 
-                 return "application/octet-stream";
 
-             }
 
-             // Web
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".js"))
 
-             {
 
-                 return "application/x-javascript";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".json"))
 
-             {
 
-                 return "application/json";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".map"))
 
-             {
 
-                 return "application/x-javascript";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".woff"))
 
-             {
 
-                 return "font/woff";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".ttf"))
 
-             {
 
-                 return "font/ttf";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".eot"))
 
-             {
 
-                 return "application/vnd.ms-fontobject";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".svg"))
 
-             {
 
-                 return "image/svg+xml";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".svgz"))
 
-             {
 
-                 return "image/svg+xml";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".srt"))
 
-             {
 
-                 return "text/plain";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".vtt"))
 
-             {
 
-                 return "text/vtt";
 
-             }
 
-             if (StringHelper.EqualsIgnoreCase(ext, ".ttml"))
 
-             {
 
-                 return "application/ttml+xml";
 
-             }
 
-             return "application/octet-stream";
 
-         }
 
-         public static string ToExtension(string mimeType)
 
-         {
 
-             if (string.IsNullOrEmpty(mimeType))
 
-             {
 
-                 throw new ArgumentNullException("mimeType");
 
-             }
 
-             string result;
 
-             if (ExtensionLookup.TryGetValue(mimeType, out result))
 
-             {
 
-                 return result;
 
-             }
 
-             throw new ArgumentNullException("Unable to determine extension for mimeType: " + mimeType);
 
-         }
 
-     }
 
- }
 
 
  |