jellyfin-server/MediaBrowser.Common/Net/MimeTypes.cs

119 lines
4.2 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 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-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";
}
else if (ext.EndsWith("ogg", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("oga", StringComparison.OrdinalIgnoreCase))
{
return "audio/ogg";
}
throw new InvalidOperationException("Argument not supported: " + path);
}
}
}