jellyfin/MediaBrowser.Common/Net/MimeTypes.cs

161 lines
5.6 KiB
C#
Raw Normal View History

2012-08-09 15:35:15 +00:00
using System;
using System.IO;
namespace MediaBrowser.Common.Net
{
public static class MimeTypes
{
public static string JsonMimeType = "application/json";
2012-08-09 15:35:15 +00:00
public static string GetMimeType(string path)
{
string ext = Path.GetExtension(path);
// http://en.wikipedia.org/wiki/Internet_media_type
// Add more as needed
// Type video
if (ext.EndsWith("mpg", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("mpeg", StringComparison.OrdinalIgnoreCase))
{
return "video/mpeg";
}
else if (ext.EndsWith("mp4", StringComparison.OrdinalIgnoreCase))
{
return "video/mp4";
}
else if (ext.EndsWith("ogv", StringComparison.OrdinalIgnoreCase))
{
return "video/ogg";
}
else if (ext.EndsWith("mov", StringComparison.OrdinalIgnoreCase))
{
return "video/quicktime";
}
else if (ext.EndsWith("webm", StringComparison.OrdinalIgnoreCase))
{
return "video/webm";
}
else if (ext.EndsWith("mkv", StringComparison.OrdinalIgnoreCase))
{
return "video/x-matroska";
}
else if (ext.EndsWith("wmv", StringComparison.OrdinalIgnoreCase))
{
return "video/x-ms-wmv";
}
else if (ext.EndsWith("flv", StringComparison.OrdinalIgnoreCase))
{
return "video/x-flv";
}
else if (ext.EndsWith("avi", StringComparison.OrdinalIgnoreCase))
{
return "video/avi";
}
2012-08-11 22:05:04 +00:00
else if (ext.EndsWith("m4v", StringComparison.OrdinalIgnoreCase))
{
return "video/x-m4v";
}
2012-08-12 15:24:14 +00:00
else if (ext.EndsWith("asf", StringComparison.OrdinalIgnoreCase))
{
return "video/x-ms-asf";
}
2012-08-12 17:05:20 +00:00
else if (ext.EndsWith("3gp", StringComparison.OrdinalIgnoreCase))
{
return "video/3gpp";
}
2012-08-14 12:58:15 +00:00
else if (ext.EndsWith("3g2", StringComparison.OrdinalIgnoreCase))
{
return "video/3gpp2";
}
2012-08-12 17:05:20 +00:00
else if (ext.EndsWith("ts", StringComparison.OrdinalIgnoreCase))
{
return "video/mp2t";
}
2012-08-09 15:35:15 +00:00
// Type text
else if (ext.EndsWith("css", StringComparison.OrdinalIgnoreCase))
{
return "text/css";
}
else if (ext.EndsWith("csv", StringComparison.OrdinalIgnoreCase))
{
return "text/csv";
}
else if (ext.EndsWith("html", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("html", StringComparison.OrdinalIgnoreCase))
{
return "text/html";
}
else if (ext.EndsWith("txt", StringComparison.OrdinalIgnoreCase))
{
return "text/plain";
}
// Type image
else if (ext.EndsWith("gif", StringComparison.OrdinalIgnoreCase))
{
return "image/gif";
}
else if (ext.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("jpeg", StringComparison.OrdinalIgnoreCase))
{
return "image/jpeg";
}
else if (ext.EndsWith("png", StringComparison.OrdinalIgnoreCase))
{
return "image/png";
}
else if (ext.EndsWith("ico", StringComparison.OrdinalIgnoreCase))
{
return "image/vnd.microsoft.icon";
}
// Type audio
else if (ext.EndsWith("mp3", StringComparison.OrdinalIgnoreCase))
{
return "audio/mpeg";
}
else if (ext.EndsWith("m4a", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("aac", StringComparison.OrdinalIgnoreCase))
{
return "audio/mp4";
}
else if (ext.EndsWith("webma", StringComparison.OrdinalIgnoreCase))
{
return "audio/webm";
}
else if (ext.EndsWith("wav", StringComparison.OrdinalIgnoreCase))
{
return "audio/wav";
}
2012-08-12 15:24:14 +00:00
else if (ext.EndsWith("wma", StringComparison.OrdinalIgnoreCase))
{
return "audio/x-ms-wma";
}
else if (ext.EndsWith("flac", StringComparison.OrdinalIgnoreCase))
{
return "audio/flac";
}
else if (ext.EndsWith("aac", StringComparison.OrdinalIgnoreCase))
{
return "audio/x-aac";
}
2012-08-09 15:35:15 +00:00
else if (ext.EndsWith("ogg", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("oga", StringComparison.OrdinalIgnoreCase))
{
return "audio/ogg";
}
2012-08-12 17:05:20 +00:00
// Playlists
else if (ext.EndsWith("m3u8", StringComparison.OrdinalIgnoreCase))
{
return "application/x-mpegURL";
}
2012-09-03 19:12:02 +00:00
// Misc
else if (ext.EndsWith("dll", StringComparison.OrdinalIgnoreCase))
{
return "application/x-msdownload";
}
2012-08-09 15:35:15 +00:00
throw new InvalidOperationException("Argument not supported: " + path);
}
}
}