|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using System;
|
|
|
|
|
using MediaBrowser.Model.Extensions;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
@ -45,33 +46,50 @@ namespace MediaBrowser.Model.Net
|
|
|
|
|
".rec"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static readonly Dictionary<string, string> VideoFileExtensionsDictionary = VideoFileExtensions.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
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 readonly Dictionary<string, string> MimeTypeLookup =
|
|
|
|
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
|
|
|
|
{
|
|
|
|
|
{".jpg", "image/jpeg"},
|
|
|
|
|
{".jpeg", "image/jpeg"},
|
|
|
|
|
{".tbn", "image/jpeg"},
|
|
|
|
|
{".png", "image/png"},
|
|
|
|
|
{".gif", "image/gif"},
|
|
|
|
|
{".webp", "image/webp"},
|
|
|
|
|
{".ico", "image/vnd.microsoft.icon"},
|
|
|
|
|
{".mpg", "video/mpeg"},
|
|
|
|
|
{".mpeg", "video/mpeg"},
|
|
|
|
|
{".ogv", "video/ogg"},
|
|
|
|
|
{".mov", "video/quicktime"},
|
|
|
|
|
{".webm", "video/webm"},
|
|
|
|
|
{".mkv", "video/x-matroska"},
|
|
|
|
|
{".wmv", "video/x-ms-wmv"},
|
|
|
|
|
{".flv", "video/x-flv"},
|
|
|
|
|
{".avi", "video/x-msvideo"},
|
|
|
|
|
{".asf", "video/x-ms-asf"},
|
|
|
|
|
{".m4v", "video/x-m4v"}
|
|
|
|
|
};
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
@ -109,19 +127,19 @@ namespace MediaBrowser.Model.Net
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Type video
|
|
|
|
|
if (ext.Equals(".3gp", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".3gp"))
|
|
|
|
|
{
|
|
|
|
|
return "video/3gpp";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".3g2", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".3g2"))
|
|
|
|
|
{
|
|
|
|
|
return "video/3gpp2";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".ts", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".ts"))
|
|
|
|
|
{
|
|
|
|
|
return "video/mp2t";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".mpd", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".mpd"))
|
|
|
|
|
{
|
|
|
|
|
return "video/vnd.mpeg.dash.mpd";
|
|
|
|
|
}
|
|
|
|
@ -133,134 +151,154 @@ namespace MediaBrowser.Model.Net
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Type text
|
|
|
|
|
if (ext.Equals(".css", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".css"))
|
|
|
|
|
{
|
|
|
|
|
return "text/css";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".csv", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".csv"))
|
|
|
|
|
{
|
|
|
|
|
return "text/csv";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".html", StringComparison.OrdinalIgnoreCase) || ext.Equals(".htm", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".html"))
|
|
|
|
|
{
|
|
|
|
|
return "text/html; charset=UTF-8";
|
|
|
|
|
}
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".htm"))
|
|
|
|
|
{
|
|
|
|
|
return "text/html; charset=UTF-8";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".txt", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".txt"))
|
|
|
|
|
{
|
|
|
|
|
return "text/plain";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".xml", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".xml"))
|
|
|
|
|
{
|
|
|
|
|
return "application/xml";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Type document
|
|
|
|
|
if (ext.Equals(".pdf", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".pdf"))
|
|
|
|
|
{
|
|
|
|
|
return "application/pdf";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".mobi", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".mobi"))
|
|
|
|
|
{
|
|
|
|
|
return "application/x-mobipocket-ebook";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".epub", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".epub"))
|
|
|
|
|
{
|
|
|
|
|
return "application/epub+zip";
|
|
|
|
|
}
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".cbz"))
|
|
|
|
|
{
|
|
|
|
|
return "application/epub+zip";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".cbz", StringComparison.OrdinalIgnoreCase) || ext.Equals(".cbr", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".cbr"))
|
|
|
|
|
{
|
|
|
|
|
return "application/x-cdisplay";
|
|
|
|
|
return "application/epub+zip";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Type audio
|
|
|
|
|
if (ext.Equals(".mp3", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".mp3"))
|
|
|
|
|
{
|
|
|
|
|
return "audio/mpeg";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".m4a", StringComparison.OrdinalIgnoreCase) || ext.Equals(".aac", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".m4a"))
|
|
|
|
|
{
|
|
|
|
|
return "audio/mp4";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".webma", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".aac"))
|
|
|
|
|
{
|
|
|
|
|
return "audio/mp4";
|
|
|
|
|
}
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".webma"))
|
|
|
|
|
{
|
|
|
|
|
return "audio/webm";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".wav", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".wav"))
|
|
|
|
|
{
|
|
|
|
|
return "audio/wav";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".wma", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".wma"))
|
|
|
|
|
{
|
|
|
|
|
return "audio/x-ms-wma";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".flac", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".flac"))
|
|
|
|
|
{
|
|
|
|
|
return "audio/flac";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".aac", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".aac"))
|
|
|
|
|
{
|
|
|
|
|
return "audio/x-aac";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".ogg", StringComparison.OrdinalIgnoreCase) || ext.Equals(".oga", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".ogg"))
|
|
|
|
|
{
|
|
|
|
|
return "audio/ogg";
|
|
|
|
|
}
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".oga"))
|
|
|
|
|
{
|
|
|
|
|
return "audio/ogg";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Playlists
|
|
|
|
|
if (ext.Equals(".m3u8", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".m3u8"))
|
|
|
|
|
{
|
|
|
|
|
return "application/x-mpegURL";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Misc
|
|
|
|
|
if (ext.Equals(".dll", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".dll"))
|
|
|
|
|
{
|
|
|
|
|
return "application/octet-stream";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Web
|
|
|
|
|
if (ext.Equals(".js", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".js"))
|
|
|
|
|
{
|
|
|
|
|
return "application/x-javascript";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".json", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".json"))
|
|
|
|
|
{
|
|
|
|
|
return "application/json";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".map", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".map"))
|
|
|
|
|
{
|
|
|
|
|
return "application/x-javascript";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ext.Equals(".woff", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".woff"))
|
|
|
|
|
{
|
|
|
|
|
return "font/woff";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ext.Equals(".ttf", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".ttf"))
|
|
|
|
|
{
|
|
|
|
|
return "font/ttf";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".eot", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".eot"))
|
|
|
|
|
{
|
|
|
|
|
return "application/vnd.ms-fontobject";
|
|
|
|
|
}
|
|
|
|
|
if (ext.Equals(".svg", StringComparison.OrdinalIgnoreCase) || ext.Equals(".svgz", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".svg"))
|
|
|
|
|
{
|
|
|
|
|
return "image/svg+xml";
|
|
|
|
|
}
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".svgz"))
|
|
|
|
|
{
|
|
|
|
|
return "image/svg+xml";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ext.Equals(".srt", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".srt"))
|
|
|
|
|
{
|
|
|
|
|
return "text/plain";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ext.Equals(".vtt", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".vtt"))
|
|
|
|
|
{
|
|
|
|
|
return "text/vtt";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ext.Equals(".ttml", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (StringHelper.EqualsIgnoreCase(ext, ".ttml"))
|
|
|
|
|
{
|
|
|
|
|
return "application/ttml+xml";
|
|
|
|
|
}
|
|
|
|
|