Switched to dictionary for media file extensions

pull/4/head
Mark McDowall 11 years ago
parent cd12ccec94
commit 7c324b7cd2

@ -10,89 +10,75 @@ namespace NzbDrone.Core.MediaFiles
{ {
public static class MediaFileExtensions public static class MediaFileExtensions
{ {
private static HashSet<MediaFileExtension> _fileExtensions; private static Dictionary<String, Quality> _fileExtensions;
static MediaFileExtensions() static MediaFileExtensions()
{ {
_fileExtensions = new HashSet<MediaFileExtension> _fileExtensions = new Dictionary<String, Quality>
{ {
new MediaFileExtension(".m4v", Quality.SDTV), { ".m4v", Quality.SDTV },
new MediaFileExtension(".3gp", Quality.SDTV), { ".3gp", Quality.SDTV },
new MediaFileExtension(".nsv", Quality.SDTV), { ".nsv", Quality.SDTV },
new MediaFileExtension(".ty", Quality.SDTV), { ".ty", Quality.SDTV },
new MediaFileExtension(".strm", Quality.SDTV), { ".strm", Quality.SDTV },
new MediaFileExtension(".rm", Quality.SDTV), { ".rm", Quality.SDTV },
new MediaFileExtension(".rmvb", Quality.SDTV), { ".rmvb", Quality.SDTV },
new MediaFileExtension(".m3u", Quality.SDTV), { ".m3u", Quality.SDTV },
new MediaFileExtension(".ifo", Quality.SDTV), { ".ifo", Quality.SDTV },
new MediaFileExtension(".mov", Quality.SDTV), { ".mov", Quality.SDTV },
new MediaFileExtension(".qt", Quality.SDTV), { ".qt", Quality.SDTV },
new MediaFileExtension(".divx", Quality.SDTV), { ".divx", Quality.SDTV },
new MediaFileExtension(".xvid", Quality.SDTV), { ".xvid", Quality.SDTV },
new MediaFileExtension(".bivx", Quality.SDTV), { ".bivx", Quality.SDTV },
new MediaFileExtension(".vob", Quality.SDTV), { ".vob", Quality.SDTV },
new MediaFileExtension(".nrg", Quality.SDTV), { ".nrg", Quality.SDTV },
new MediaFileExtension(".pva", Quality.SDTV), { ".pva", Quality.SDTV },
new MediaFileExtension(".wmv", Quality.SDTV), { ".wmv", Quality.SDTV },
new MediaFileExtension(".asf", Quality.SDTV), { ".asf", Quality.SDTV },
new MediaFileExtension(".asx", Quality.SDTV), { ".asx", Quality.SDTV },
new MediaFileExtension(".ogm", Quality.SDTV), { ".ogm", Quality.SDTV },
new MediaFileExtension(".m2v", Quality.SDTV), { ".m2v", Quality.SDTV },
new MediaFileExtension(".avi", Quality.SDTV), { ".avi", Quality.SDTV },
new MediaFileExtension(".bin", Quality.SDTV), { ".bin", Quality.SDTV },
new MediaFileExtension(".dat", Quality.SDTV), { ".dat", Quality.SDTV },
new MediaFileExtension(".dvr-ms", Quality.SDTV), { ".dvr-ms", Quality.SDTV },
new MediaFileExtension(".mpg", Quality.SDTV), { ".mpg", Quality.SDTV },
new MediaFileExtension(".mpeg", Quality.SDTV), { ".mpeg", Quality.SDTV },
new MediaFileExtension(".mp4", Quality.SDTV), { ".mp4", Quality.SDTV },
new MediaFileExtension(".avc", Quality.SDTV), { ".avc", Quality.SDTV },
new MediaFileExtension(".vp3", Quality.SDTV), { ".vp3", Quality.SDTV },
new MediaFileExtension(".svq3", Quality.SDTV), { ".svq3", Quality.SDTV },
new MediaFileExtension(".nuv", Quality.SDTV), { ".nuv", Quality.SDTV },
new MediaFileExtension(".viv", Quality.SDTV), { ".viv", Quality.SDTV },
new MediaFileExtension(".dv", Quality.SDTV), { ".dv", Quality.SDTV },
new MediaFileExtension(".fli", Quality.SDTV), { ".fli", Quality.SDTV },
new MediaFileExtension(".flv", Quality.SDTV), { ".flv", Quality.SDTV },
new MediaFileExtension(".wpl", Quality.SDTV), { ".wpl", Quality.SDTV },
//DVD //DVD
new MediaFileExtension(".img", Quality.DVD), { ".img", Quality.DVD },
new MediaFileExtension(".iso", Quality.DVD), { ".iso", Quality.DVD },
//HD //HD
new MediaFileExtension(".mkv", Quality.HDTV720p), { ".mkv", Quality.HDTV720p },
new MediaFileExtension(".ts", Quality.HDTV720p), { ".ts", Quality.HDTV720p },
new MediaFileExtension(".m2ts", Quality.HDTV720p) { ".m2ts", Quality.HDTV720p }
}; };
} }
public static HashSet<String> Extensions public static HashSet<String> Extensions
{ {
get { return new HashSet<String>(_fileExtensions.Select(e => e.Extension.ToLower())); } get { return new HashSet<String>(_fileExtensions.Keys); }
} }
public static Quality FindQuality(string extension) public static Quality FindQuality(string extension)
{ {
var mediaFileExtension = _fileExtensions.SingleOrDefault(e => e.Extension.Equals(extension, StringComparison.InvariantCultureIgnoreCase)); if (_fileExtensions.ContainsKey(extension))
if (mediaFileExtension == null)
{ {
return Quality.Unknown; return _fileExtensions[extension];
} }
return mediaFileExtension.Quality; return Quality.Unknown;
}
}
public class MediaFileExtension
{
public string Extension { get; set; }
public Quality Quality { get; set; }
public MediaFileExtension(string extension, Quality quality)
{
Extension = extension;
Quality = quality;
} }
} }
} }

Loading…
Cancel
Save