mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-25 17:17:02 +00:00
Moved media file extensions to a static class
This commit is contained in:
parent
5d46ce6cee
commit
cd12ccec94
5 changed files with 103 additions and 43 deletions
|
@ -69,7 +69,7 @@ public void should_check_top_level_directory_only_when_allDirectories_is_false()
|
|||
public void should_return_video_files_only()
|
||||
{
|
||||
var path = @"C:\Test\";
|
||||
|
||||
var test = Subject.GetVideoFiles(path);
|
||||
Subject.GetVideoFiles(path).Should().HaveCount(4);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,16 +21,6 @@ public class DiskScanService :
|
|||
IDiskScanService,
|
||||
IHandle<SeriesUpdatedEvent>
|
||||
{
|
||||
private readonly HashSet<string> _mediaExtensions;
|
||||
|
||||
private const string EXTENSIONS =
|
||||
//XBMC
|
||||
".m4v .3gp .nsv .ts .ty .strm .rm .rmvb .m3u .ifo .mov .qt .divx .xvid .bivx .vob .nrg .img " +
|
||||
".iso .pva .wmv .asf .asx .ogm .m2v .avi .bin .dat .dvr-ms .mpg .mpeg .mp4 .mkv .avc .vp3 " +
|
||||
".svq3 .nuv .viv .dv .fli .flv .wpl " +
|
||||
//Other
|
||||
".m2ts";
|
||||
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IMakeImportDecision _importDecisionMaker;
|
||||
private readonly IImportApprovedEpisodes _importApprovedEpisodes;
|
||||
|
@ -47,8 +37,6 @@ public DiskScanService(IDiskProvider diskProvider,
|
|||
_importApprovedEpisodes = importApprovedEpisodes;
|
||||
_messageAggregator = messageAggregator;
|
||||
_logger = logger;
|
||||
|
||||
_mediaExtensions = new HashSet<string>(EXTENSIONS.Split(' ').Select(c => c.ToLower()));
|
||||
}
|
||||
|
||||
private void Scan(Series series)
|
||||
|
@ -77,7 +65,7 @@ public string[] GetVideoFiles(string path, bool allDirectories = true)
|
|||
var searchOption = allDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||
var filesOnDisk = _diskProvider.GetFiles(path, searchOption);
|
||||
|
||||
var mediaFileList = filesOnDisk.Where(c => _mediaExtensions.Contains(Path.GetExtension(c).ToLower())).ToList();
|
||||
var mediaFileList = filesOnDisk.Where(c => MediaFileExtensions.Extensions.Contains(Path.GetExtension(c).ToLower())).ToList();
|
||||
|
||||
_logger.Trace("{0} video files were found in {1}", mediaFileList.Count, path);
|
||||
return mediaFileList.ToArray();
|
||||
|
|
98
NzbDrone.Core/MediaFiles/MediaFileExtensions.cs
Normal file
98
NzbDrone.Core/MediaFiles/MediaFileExtensions.cs
Normal file
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
public static class MediaFileExtensions
|
||||
{
|
||||
private static HashSet<MediaFileExtension> _fileExtensions;
|
||||
|
||||
static MediaFileExtensions()
|
||||
{
|
||||
_fileExtensions = new HashSet<MediaFileExtension>
|
||||
{
|
||||
new MediaFileExtension(".m4v", Quality.SDTV),
|
||||
new MediaFileExtension(".3gp", Quality.SDTV),
|
||||
new MediaFileExtension(".nsv", Quality.SDTV),
|
||||
new MediaFileExtension(".ty", Quality.SDTV),
|
||||
new MediaFileExtension(".strm", Quality.SDTV),
|
||||
new MediaFileExtension(".rm", Quality.SDTV),
|
||||
new MediaFileExtension(".rmvb", Quality.SDTV),
|
||||
new MediaFileExtension(".m3u", Quality.SDTV),
|
||||
new MediaFileExtension(".ifo", Quality.SDTV),
|
||||
new MediaFileExtension(".mov", Quality.SDTV),
|
||||
new MediaFileExtension(".qt", Quality.SDTV),
|
||||
new MediaFileExtension(".divx", Quality.SDTV),
|
||||
new MediaFileExtension(".xvid", Quality.SDTV),
|
||||
new MediaFileExtension(".bivx", Quality.SDTV),
|
||||
new MediaFileExtension(".vob", Quality.SDTV),
|
||||
new MediaFileExtension(".nrg", Quality.SDTV),
|
||||
new MediaFileExtension(".pva", Quality.SDTV),
|
||||
new MediaFileExtension(".wmv", Quality.SDTV),
|
||||
new MediaFileExtension(".asf", Quality.SDTV),
|
||||
new MediaFileExtension(".asx", Quality.SDTV),
|
||||
new MediaFileExtension(".ogm", Quality.SDTV),
|
||||
new MediaFileExtension(".m2v", Quality.SDTV),
|
||||
new MediaFileExtension(".avi", Quality.SDTV),
|
||||
new MediaFileExtension(".bin", Quality.SDTV),
|
||||
new MediaFileExtension(".dat", Quality.SDTV),
|
||||
new MediaFileExtension(".dvr-ms", Quality.SDTV),
|
||||
new MediaFileExtension(".mpg", Quality.SDTV),
|
||||
new MediaFileExtension(".mpeg", Quality.SDTV),
|
||||
new MediaFileExtension(".mp4", Quality.SDTV),
|
||||
new MediaFileExtension(".avc", Quality.SDTV),
|
||||
new MediaFileExtension(".vp3", Quality.SDTV),
|
||||
new MediaFileExtension(".svq3", Quality.SDTV),
|
||||
new MediaFileExtension(".nuv", Quality.SDTV),
|
||||
new MediaFileExtension(".viv", Quality.SDTV),
|
||||
new MediaFileExtension(".dv", Quality.SDTV),
|
||||
new MediaFileExtension(".fli", Quality.SDTV),
|
||||
new MediaFileExtension(".flv", Quality.SDTV),
|
||||
new MediaFileExtension(".wpl", Quality.SDTV),
|
||||
|
||||
//DVD
|
||||
new MediaFileExtension(".img", Quality.DVD),
|
||||
new MediaFileExtension(".iso", Quality.DVD),
|
||||
|
||||
//HD
|
||||
new MediaFileExtension(".mkv", Quality.HDTV720p),
|
||||
new MediaFileExtension(".ts", Quality.HDTV720p),
|
||||
new MediaFileExtension(".m2ts", Quality.HDTV720p)
|
||||
};
|
||||
}
|
||||
|
||||
public static HashSet<String> Extensions
|
||||
{
|
||||
get { return new HashSet<String>(_fileExtensions.Select(e => e.Extension.ToLower())); }
|
||||
}
|
||||
|
||||
public static Quality FindQuality(string extension)
|
||||
{
|
||||
var mediaFileExtension = _fileExtensions.SingleOrDefault(e => e.Extension.Equals(extension, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (mediaFileExtension == null)
|
||||
{
|
||||
return Quality.Unknown;
|
||||
}
|
||||
|
||||
return mediaFileExtension.Quality;
|
||||
}
|
||||
}
|
||||
|
||||
public class MediaFileExtension
|
||||
{
|
||||
public string Extension { get; set; }
|
||||
public Quality Quality { get; set; }
|
||||
|
||||
public MediaFileExtension(string extension, Quality quality)
|
||||
{
|
||||
Extension = extension;
|
||||
Quality = quality;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -228,6 +228,7 @@
|
|||
<Compile Include="Instrumentation\Commands\DeleteLogFilesCommand.cs" />
|
||||
<Compile Include="Instrumentation\Commands\TrimLogCommand.cs" />
|
||||
<Compile Include="Instrumentation\DeleteLogFilesService.cs" />
|
||||
<Compile Include="MediaFiles\MediaFileExtensions.cs" />
|
||||
<Compile Include="MetadataSource\Trakt\TraktException.cs" />
|
||||
<Compile Include="NzbDroneClientException.cs" />
|
||||
<Compile Include="ProgressMessaging\NewProgressMessageEvent.cs" />
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
|
@ -152,35 +153,7 @@ public static QualityModel ParseQuality(string name)
|
|||
{
|
||||
try
|
||||
{
|
||||
switch (Path.GetExtension(name).ToLower())
|
||||
{
|
||||
case ".avi":
|
||||
case ".xvid":
|
||||
case ".divx":
|
||||
case ".wmv":
|
||||
case ".mp4":
|
||||
case ".mpg":
|
||||
case ".mpeg":
|
||||
case ".mov":
|
||||
case ".rm":
|
||||
case ".rmvb":
|
||||
case ".flv":
|
||||
case ".dvr-ms":
|
||||
case ".ogm":
|
||||
case ".strm":
|
||||
|
||||
{
|
||||
result.Quality = Quality.SDTV;
|
||||
break;
|
||||
}
|
||||
case ".mkv":
|
||||
case ".ts":
|
||||
case ".m2ts":
|
||||
{
|
||||
result.Quality = Quality.HDTV720p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
result.Quality = MediaFileExtensions.FindQuality(Path.GetExtension(name));
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue