mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-16 23:26:22 +00:00
add new naming project
This commit is contained in:
@@ -26,6 +26,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Server.Implementations.Library;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Channels
|
||||
{
|
||||
@@ -318,13 +319,13 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
|
||||
if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
files = files.Where(i => EntityResolutionHelper.IsVideoFile(i.FullName));
|
||||
files = files.Where(i => _libraryManager.IsVideoFile(i.FullName));
|
||||
}
|
||||
else
|
||||
{
|
||||
files = files.Where(i => EntityResolutionHelper.IsAudioFile(i.FullName));
|
||||
files = files.Where(i => _libraryManager.IsAudioFile(i.FullName));
|
||||
}
|
||||
|
||||
|
||||
var file = files
|
||||
.FirstOrDefault(i => i.Name.StartsWith(filenamePrefix, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Connect
|
||||
{
|
||||
public static class Validator
|
||||
{
|
||||
static Regex ValidEmailRegex = CreateValidEmailRegex();
|
||||
static readonly Regex ValidEmailRegex = CreateValidEmailRegex();
|
||||
|
||||
/// <summary>
|
||||
/// Taken from http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx
|
||||
@@ -17,9 +12,9 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
/// <returns></returns>
|
||||
private static Regex CreateValidEmailRegex()
|
||||
{
|
||||
string validEmailPattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
|
||||
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
|
||||
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";
|
||||
const string validEmailPattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
|
||||
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
|
||||
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";
|
||||
|
||||
return new Regex(validEmailPattern, RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Server.Implementations.Library;
|
||||
using MediaBrowser.Server.Implementations.Library.Resolvers.TV;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
{
|
||||
@@ -55,18 +57,18 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
FileSize = new FileInfo(path).Length
|
||||
};
|
||||
|
||||
var seriesName = TVUtils.GetSeriesNameFromEpisodeFile(path);
|
||||
var seriesName = SeriesResolver.GetSeriesNameFromEpisodeFile(path);
|
||||
|
||||
if (!string.IsNullOrEmpty(seriesName))
|
||||
{
|
||||
var season = TVUtils.GetSeasonNumberFromEpisodeFile(path);
|
||||
var season = SeriesResolver.GetSeasonNumberFromEpisodeFile(path);
|
||||
|
||||
result.ExtractedSeasonNumber = season;
|
||||
|
||||
if (season.HasValue)
|
||||
{
|
||||
// Passing in true will include a few extra regex's
|
||||
var episode = TVUtils.GetEpisodeNumberFromFile(path, true);
|
||||
var episode = SeriesResolver.GetEpisodeNumberFromFile(path, true);
|
||||
|
||||
result.ExtractedEpisodeNumber = episode;
|
||||
|
||||
@@ -74,7 +76,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
{
|
||||
_logger.Debug("Extracted information from {0}. Series name {1}, Season {2}, Episode {3}", path, seriesName, season, episode);
|
||||
|
||||
var endingEpisodeNumber = TVUtils.GetEndingEpisodeNumberFromFile(path);
|
||||
var endingEpisodeNumber = SeriesResolver.GetEndingEpisodeNumberFromFile(path);
|
||||
|
||||
result.ExtractedEndingEpisodeNumber = endingEpisodeNumber;
|
||||
|
||||
@@ -253,7 +255,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
try
|
||||
{
|
||||
var filesOfOtherExtensions = Directory.EnumerateFiles(folder, "*", SearchOption.TopDirectoryOnly)
|
||||
.Where(i => EntityResolutionHelper.IsVideoFile(i) && string.Equals(_fileSystem.GetFileNameWithoutExtension(i), targetFileNameWithoutExtension, StringComparison.OrdinalIgnoreCase));
|
||||
.Where(i => _libraryManager.IsVideoFile(i) && string.Equals(_fileSystem.GetFileNameWithoutExtension(i), targetFileNameWithoutExtension, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
episodePaths.AddRange(filesOfOtherExtensions);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Server.Implementations.Library;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
{
|
||||
@@ -45,7 +46,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
|
||||
var eligibleFiles = watchLocations.SelectMany(GetFilesToOrganize)
|
||||
.OrderBy(_fileSystem.GetCreationTimeUtc)
|
||||
.Where(i => EntityResolutionHelper.IsVideoFile(i.FullName) && i.Length >= minFileBytes)
|
||||
.Where(i => _libraryManager.IsVideoFile(i.FullName) && i.Length >= minFileBytes)
|
||||
.ToList();
|
||||
|
||||
progress.Report(10);
|
||||
|
||||
@@ -6,7 +6,6 @@ using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Localization;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using MediaBrowser.Model.Channels;
|
||||
using MediaBrowser.Model.Configuration;
|
||||
using MediaBrowser.Model.Entities;
|
||||
@@ -25,13 +24,15 @@ namespace MediaBrowser.Server.Implementations.Intros
|
||||
private readonly IChannelManager _channelManager;
|
||||
private readonly ILocalizationManager _localization;
|
||||
private readonly IConfigurationManager _serverConfig;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
public DefaultIntroProvider(ISecurityManager security, IChannelManager channelManager, ILocalizationManager localization, IConfigurationManager serverConfig)
|
||||
public DefaultIntroProvider(ISecurityManager security, IChannelManager channelManager, ILocalizationManager localization, IConfigurationManager serverConfig, ILibraryManager libraryManager)
|
||||
{
|
||||
_security = security;
|
||||
_channelManager = channelManager;
|
||||
_localization = localization;
|
||||
_serverConfig = serverConfig;
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<IntroInfo>> GetIntros(BaseItem item, User user)
|
||||
@@ -226,7 +227,7 @@ namespace MediaBrowser.Server.Implementations.Intros
|
||||
}
|
||||
|
||||
return Directory.EnumerateFiles(options.CustomIntroPath, "*", SearchOption.AllDirectories)
|
||||
.Where(EntityResolutionHelper.IsVideoFile);
|
||||
.Where(_libraryManager.IsVideoFile);
|
||||
}
|
||||
|
||||
private bool FilterByParentalRating(int? ratingLevel, BaseItem item)
|
||||
|
||||
@@ -14,10 +14,12 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
public class CoreResolutionIgnoreRule : IResolverIgnoreRule
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
public CoreResolutionIgnoreRule(IFileSystem fileSystem)
|
||||
public CoreResolutionIgnoreRule(IFileSystem fileSystem, ILibraryManager libraryManager)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -89,7 +91,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
if (args.Parent != null)
|
||||
{
|
||||
// Don't resolve these into audio files
|
||||
if (string.Equals(_fileSystem.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && EntityResolutionHelper.IsAudioFile(filename))
|
||||
if (string.Equals(_fileSystem.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && _libraryManager.IsAudioFile(filename))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Library
|
||||
{
|
||||
/// <summary>
|
||||
/// Class EntityResolutionHelper
|
||||
/// </summary>
|
||||
public static class EntityResolutionHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Any folder named in this list will be ignored - can be added to at runtime for extensibility
|
||||
/// </summary>
|
||||
public static readonly List<string> IgnoreFolders = new List<string>
|
||||
{
|
||||
"metadata",
|
||||
"ps3_update",
|
||||
"ps3_vprm",
|
||||
"extrafanart",
|
||||
"extrathumbs",
|
||||
".actors",
|
||||
".wd_tv"
|
||||
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Ensures DateCreated and DateModified have values
|
||||
/// </summary>
|
||||
/// <param name="fileSystem">The file system.</param>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="args">The args.</param>
|
||||
/// <param name="includeCreationTime">if set to <c>true</c> [include creation time].</param>
|
||||
public static void EnsureDates(IFileSystem fileSystem, BaseItem item, ItemResolveArgs args, bool includeCreationTime)
|
||||
{
|
||||
if (fileSystem == null)
|
||||
{
|
||||
throw new ArgumentNullException("fileSystem");
|
||||
}
|
||||
if (item == null)
|
||||
{
|
||||
throw new ArgumentNullException("item");
|
||||
}
|
||||
if (args == null)
|
||||
{
|
||||
throw new ArgumentNullException("args");
|
||||
}
|
||||
|
||||
// See if a different path came out of the resolver than what went in
|
||||
if (!string.Equals(args.Path, item.Path, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var childData = args.IsDirectory ? args.GetFileSystemEntryByPath(item.Path) : null;
|
||||
|
||||
if (childData != null)
|
||||
{
|
||||
if (includeCreationTime)
|
||||
{
|
||||
SetDateCreated(item, fileSystem, childData);
|
||||
}
|
||||
|
||||
item.DateModified = fileSystem.GetLastWriteTimeUtc(childData);
|
||||
}
|
||||
else
|
||||
{
|
||||
var fileData = fileSystem.GetFileSystemInfo(item.Path);
|
||||
|
||||
if (fileData.Exists)
|
||||
{
|
||||
if (includeCreationTime)
|
||||
{
|
||||
SetDateCreated(item, fileSystem, fileData);
|
||||
}
|
||||
item.DateModified = fileSystem.GetLastWriteTimeUtc(fileData);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (includeCreationTime)
|
||||
{
|
||||
SetDateCreated(item, fileSystem, args.FileInfo);
|
||||
}
|
||||
item.DateModified = fileSystem.GetLastWriteTimeUtc(args.FileInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetDateCreated(BaseItem item, IFileSystem fileSystem, FileSystemInfo info)
|
||||
{
|
||||
var config = BaseItem.ConfigurationManager.GetMetadataConfiguration();
|
||||
|
||||
if (config.UseFileCreationTimeForDateAdded)
|
||||
{
|
||||
item.DateCreated = fileSystem.GetCreationTimeUtc(info);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.DateCreated = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,10 @@ using MediaBrowser.Controller.Sorting;
|
||||
using MediaBrowser.Model.Configuration;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Naming.Audio;
|
||||
using MediaBrowser.Naming.IO;
|
||||
using MediaBrowser.Naming.Video;
|
||||
using MediaBrowser.Server.Implementations.Library.Resolvers.TV;
|
||||
using MediaBrowser.Server.Implementations.Library.Validators;
|
||||
using MediaBrowser.Server.Implementations.ScheduledTasks;
|
||||
using MoreLinq;
|
||||
@@ -1628,5 +1632,49 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public bool IsVideoFile(string path)
|
||||
{
|
||||
var parser = new VideoFileParser(new ExpandedVideoOptions(), new Naming.Logging.NullLogger());
|
||||
return parser.IsVideoFile(path);
|
||||
}
|
||||
|
||||
public bool IsAudioFile(string path)
|
||||
{
|
||||
var parser = new AudioFileParser(new AudioOptions());
|
||||
return parser.IsAudioFile(path);
|
||||
}
|
||||
|
||||
public bool IsMultiPartFile(string path)
|
||||
{
|
||||
var parser = new MultiPartParser(new ExpandedVideoOptions(), new Naming.Logging.NullLogger());
|
||||
return parser.Parse(path, FileInfoType.File).IsMultiPart;
|
||||
}
|
||||
|
||||
public bool IsMultiPartFolder(string path)
|
||||
{
|
||||
var parser = new MultiPartParser(new ExpandedVideoOptions(), new Naming.Logging.NullLogger());
|
||||
return parser.Parse(path, FileInfoType.Directory).IsMultiPart;
|
||||
}
|
||||
|
||||
public int? GetSeasonNumberFromPath(string path)
|
||||
{
|
||||
return SeriesResolver.GetSeasonNumberFromPath(path);
|
||||
}
|
||||
|
||||
public int? GetSeasonNumberFromEpisodeFile(string path)
|
||||
{
|
||||
return SeriesResolver.GetSeasonNumberFromEpisodeFile(path);
|
||||
}
|
||||
|
||||
public int? GetEndingEpisodeNumberFromFile(string path)
|
||||
{
|
||||
return SeriesResolver.GetEndingEpisodeNumberFromFile(path);
|
||||
}
|
||||
|
||||
public int? GetEpisodeNumberFromFile(string path, bool considerSeasonless)
|
||||
{
|
||||
return SeriesResolver.GetEpisodeNumberFromFile(path, considerSeasonless);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -63,14 +62,14 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
if (string.IsNullOrEmpty(item.Name) && !string.IsNullOrEmpty(item.Path))
|
||||
{
|
||||
//we use our resolve args name here to get the name of the containg folder, not actual video file
|
||||
item.Name = GetMBName(args.FileInfo.Name, (args.FileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory);
|
||||
item.Name = GetMbName(args.FileInfo.Name, (args.FileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The MB name regex
|
||||
/// </summary>
|
||||
private static readonly Regex MBNameRegex = new Regex(@"(\[.*?\])", RegexOptions.Compiled);
|
||||
private static readonly Regex MbNameRegex = new Regex(@"(\[.*?\])", RegexOptions.Compiled);
|
||||
|
||||
/// <summary>
|
||||
/// Strip out attribute items and return just the name we will use for items
|
||||
@@ -78,7 +77,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
/// <param name="path">Assumed to be a file or directory path</param>
|
||||
/// <param name="isDirectory">if set to <c>true</c> [is directory].</param>
|
||||
/// <returns>The cleaned name</returns>
|
||||
private static string GetMBName(string path, bool isDirectory)
|
||||
private static string GetMbName(string path, bool isDirectory)
|
||||
{
|
||||
//first just get the file or directory name
|
||||
var fn = isDirectory ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path);
|
||||
@@ -89,8 +88,9 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
return fn;
|
||||
}
|
||||
|
||||
public static string StripBrackets(string inputString) {
|
||||
var output = MBNameRegex.Replace(inputString, string.Empty).Trim();
|
||||
private static string StripBrackets(string inputString)
|
||||
{
|
||||
var output = MbNameRegex.Replace(inputString, string.Empty).Trim();
|
||||
return Regex.Replace(output, @"\s+", " ");
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
||||
/// </summary>
|
||||
public class AudioResolver : ItemResolver<Controller.Entities.Audio.Audio>
|
||||
{
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
public AudioResolver(ILibraryManager libraryManager)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
@@ -30,15 +37,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
||||
|
||||
if (!args.IsDirectory)
|
||||
{
|
||||
if (EntityResolutionHelper.IsAudioFile(args.Path))
|
||||
if (_libraryManager.IsAudioFile(args.Path))
|
||||
{
|
||||
var collectionType = args.GetCollectionType();
|
||||
|
||||
var isStandalone = args.Parent == null;
|
||||
|
||||
if (isStandalone ||
|
||||
string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.IsNullOrEmpty(collectionType))
|
||||
string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new Controller.Entities.Audio.Audio();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Naming.Audio;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -21,11 +22,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
public MusicAlbumResolver(ILogger logger, IFileSystem fileSystem)
|
||||
public MusicAlbumResolver(ILogger logger, IFileSystem fileSystem, ILibraryManager libraryManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_fileSystem = fileSystem;
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -68,7 +71,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
||||
return null;
|
||||
}
|
||||
|
||||
return IsMusicAlbum(args, isMusicMediaFolder) ? new MusicAlbum() : null;
|
||||
return IsMusicAlbum(args) ? new MusicAlbum() : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,29 +79,29 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
||||
/// Determine if the supplied file data points to a music album
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <param name="isMusicMediaFolder">if set to <c>true</c> [is music media folder].</param>
|
||||
/// <param name="directoryService">The directory service.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="fileSystem">The file system.</param>
|
||||
/// <param name="libraryManager">The library manager.</param>
|
||||
/// <returns><c>true</c> if [is music album] [the specified data]; otherwise, <c>false</c>.</returns>
|
||||
public static bool IsMusicAlbum(string path, bool isMusicMediaFolder, IDirectoryService directoryService, ILogger logger, IFileSystem fileSystem)
|
||||
public static bool IsMusicAlbum(string path, IDirectoryService directoryService, ILogger logger, IFileSystem fileSystem,
|
||||
ILibraryManager libraryManager)
|
||||
{
|
||||
return ContainsMusic(directoryService.GetFileSystemEntries(path), isMusicMediaFolder, true, directoryService, logger, fileSystem);
|
||||
return ContainsMusic(directoryService.GetFileSystemEntries(path), true, directoryService, logger, fileSystem, libraryManager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine if the supplied resolve args should be considered a music album
|
||||
/// </summary>
|
||||
/// <param name="args">The args.</param>
|
||||
/// <param name="isMusicMediaFolder">if set to <c>true</c> [is music media folder].</param>
|
||||
/// <returns><c>true</c> if [is music album] [the specified args]; otherwise, <c>false</c>.</returns>
|
||||
private bool IsMusicAlbum(ItemResolveArgs args, bool isMusicMediaFolder)
|
||||
private bool IsMusicAlbum(ItemResolveArgs args)
|
||||
{
|
||||
// Args points to an album if parent is an Artist folder or it directly contains music
|
||||
if (args.IsDirectory)
|
||||
{
|
||||
//if (args.Parent is MusicArtist) return true; //saves us from testing children twice
|
||||
if (ContainsMusic(args.FileSystemChildren, isMusicMediaFolder, true, args.DirectoryService, _logger, _fileSystem)) return true;
|
||||
if (ContainsMusic(args.FileSystemChildren, true, args.DirectoryService, _logger, _fileSystem, _libraryManager)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -108,41 +111,34 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
||||
/// Determine if the supplied list contains what we should consider music
|
||||
/// </summary>
|
||||
/// <param name="list">The list.</param>
|
||||
/// <param name="isMusicMediaFolder">if set to <c>true</c> [is music media folder].</param>
|
||||
/// <param name="allowSubfolders">if set to <c>true</c> [allow subfolders].</param>
|
||||
/// <param name="directoryService">The directory service.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="fileSystem">The file system.</param>
|
||||
/// <param name="libraryManager">The library manager.</param>
|
||||
/// <returns><c>true</c> if the specified list contains music; otherwise, <c>false</c>.</returns>
|
||||
private static bool ContainsMusic(IEnumerable<FileSystemInfo> list,
|
||||
bool isMusicMediaFolder,
|
||||
bool allowSubfolders,
|
||||
IDirectoryService directoryService,
|
||||
ILogger logger,
|
||||
IFileSystem fileSystem)
|
||||
IFileSystem fileSystem,
|
||||
ILibraryManager libraryManager)
|
||||
{
|
||||
// If list contains at least 2 audio files or at least one and no video files consider it to contain music
|
||||
var foundAudio = 0;
|
||||
|
||||
var discSubfolderCount = 0;
|
||||
|
||||
foreach (var fileSystemInfo in list)
|
||||
{
|
||||
if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
||||
{
|
||||
if (isMusicMediaFolder && allowSubfolders && IsAlbumSubfolder(fileSystemInfo, true, directoryService, logger, fileSystem))
|
||||
if (allowSubfolders && IsAlbumSubfolder(fileSystemInfo, directoryService, logger, fileSystem, libraryManager))
|
||||
{
|
||||
discSubfolderCount++;
|
||||
}
|
||||
if (!IsAdditionalSubfolderAllowed(fileSystemInfo))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var fullName = fileSystemInfo.FullName;
|
||||
|
||||
if (EntityResolutionHelper.IsAudioFile(fullName))
|
||||
if (libraryManager.IsAudioFile(fullName))
|
||||
{
|
||||
// Don't resolve these into audio files
|
||||
if (string.Equals(fileSystem.GetFileNameWithoutExtension(fullName), BaseItem.ThemeSongFilename))
|
||||
@@ -150,22 +146,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
||||
continue;
|
||||
}
|
||||
|
||||
foundAudio++;
|
||||
}
|
||||
else if (EntityResolutionHelper.IsVideoFile(fullName)) return false;
|
||||
else if (EntityResolutionHelper.IsVideoPlaceHolder(fullName)) return false;
|
||||
|
||||
if (foundAudio >= 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// or a single audio file and no video files
|
||||
return foundAudio > 0 || discSubfolderCount > 0;
|
||||
return discSubfolderCount > 0;
|
||||
}
|
||||
|
||||
private static bool IsAlbumSubfolder(FileSystemInfo directory, bool isMusicMediaFolder, IDirectoryService directoryService, ILogger logger, IFileSystem fileSystem)
|
||||
private static bool IsAlbumSubfolder(FileSystemInfo directory, IDirectoryService directoryService, ILogger logger, IFileSystem fileSystem, ILibraryManager libraryManager)
|
||||
{
|
||||
var path = directory.FullName;
|
||||
|
||||
@@ -173,7 +161,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
||||
{
|
||||
logger.Debug("Found multi-disc folder: " + path);
|
||||
|
||||
return ContainsMusic(directoryService.GetFileSystemEntries(path), isMusicMediaFolder, false, directoryService, logger, fileSystem);
|
||||
return ContainsMusic(directoryService.GetFileSystemEntries(path), false, directoryService, logger, fileSystem, libraryManager);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -181,13 +169,20 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
||||
|
||||
public static bool IsMultiDiscFolder(string path)
|
||||
{
|
||||
return EntityResolutionHelper.IsMultiDiscAlbumFolder(path);
|
||||
return IsMultiDiscAlbumFolder(path);
|
||||
}
|
||||
|
||||
private static bool IsAdditionalSubfolderAllowed(FileSystemInfo directory)
|
||||
/// <summary>
|
||||
/// Determines whether [is multi disc album folder] [the specified path].
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns><c>true</c> if [is multi disc album folder] [the specified path]; otherwise, <c>false</c>.</returns>
|
||||
private static bool IsMultiDiscAlbumFolder(string path)
|
||||
{
|
||||
// Resolver will ignore them based on rules engine
|
||||
return true;
|
||||
var parser = new AlbumParser(new AudioOptions(), new Naming.Logging.NullLogger());
|
||||
var result = parser.ParseMultiPart(path);
|
||||
|
||||
return result.IsMultiPart;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
public MusicArtistResolver(ILogger logger, IFileSystem fileSystem)
|
||||
public MusicArtistResolver(ILogger logger, IFileSystem fileSystem, ILibraryManager libraryManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_fileSystem = fileSystem;
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -74,7 +76,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
||||
var directoryService = args.DirectoryService;
|
||||
|
||||
// If we contain an album assume we are an artist folder
|
||||
return args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => MusicAlbumResolver.IsMusicAlbum(i.FullName, isMusicMediaFolder, directoryService, _logger, _fileSystem)) ? new MusicArtist() : null;
|
||||
return args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => MusicAlbumResolver.IsMusicAlbum(i.FullName, directoryService, _logger, _fileSystem, _libraryManager)) ? new MusicArtist() : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Naming.Video;
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
||||
{
|
||||
/// <summary>
|
||||
/// Resolves a Path into a Video or Video subclass
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public abstract class BaseVideoResolver<T> : Controller.Resolvers.ItemResolver<T>
|
||||
where T : Video, new()
|
||||
{
|
||||
protected readonly ILibraryManager LibraryManager;
|
||||
|
||||
protected BaseVideoResolver(ILibraryManager libraryManager)
|
||||
{
|
||||
LibraryManager = libraryManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the specified args.
|
||||
/// </summary>
|
||||
/// <param name="args">The args.</param>
|
||||
/// <returns>`0.</returns>
|
||||
protected override T Resolve(ItemResolveArgs args)
|
||||
{
|
||||
return ResolveVideo<T>(args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the video.
|
||||
/// </summary>
|
||||
/// <typeparam name="TVideoType">The type of the T video type.</typeparam>
|
||||
/// <param name="args">The args.</param>
|
||||
/// <returns>``0.</returns>
|
||||
protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args)
|
||||
where TVideoType : Video, new()
|
||||
{
|
||||
// If the path is a file check for a matching extensions
|
||||
if (!args.IsDirectory)
|
||||
{
|
||||
var parser = new VideoFileParser(new ExpandedVideoOptions(), new Naming.Logging.NullLogger());
|
||||
var videoInfo = parser.ParseFile(args.Path);
|
||||
|
||||
if (videoInfo == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var isShortcut = string.Equals(videoInfo.Container, "strm", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub || isShortcut)
|
||||
{
|
||||
var type = string.Equals(videoInfo.Container, "iso", StringComparison.OrdinalIgnoreCase) || string.Equals(videoInfo.Container, "img", StringComparison.OrdinalIgnoreCase) ?
|
||||
VideoType.Iso :
|
||||
VideoType.VideoFile;
|
||||
|
||||
var path = args.Path;
|
||||
|
||||
var video = new TVideoType
|
||||
{
|
||||
VideoType = type,
|
||||
Path = path,
|
||||
IsInMixedFolder = true,
|
||||
IsPlaceHolder = videoInfo.IsStub,
|
||||
IsShortcut = isShortcut,
|
||||
Name = videoInfo.Name
|
||||
};
|
||||
|
||||
if (videoInfo.IsStub)
|
||||
{
|
||||
if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
video.VideoType = VideoType.Dvd;
|
||||
}
|
||||
else if (string.Equals(videoInfo.StubType, "hddvd", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
video.VideoType = VideoType.HdDvd;
|
||||
}
|
||||
else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
video.VideoType = VideoType.BluRay;
|
||||
}
|
||||
}
|
||||
|
||||
return video;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
public LocalTrailerResolver(IFileSystem fileSystem)
|
||||
public LocalTrailerResolver(ILibraryManager libraryManager, IFileSystem fileSystem) : base(libraryManager)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
|
||||
@@ -21,14 +21,12 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
||||
public class MovieResolver : BaseVideoResolver<Video>
|
||||
{
|
||||
private readonly IServerApplicationPaths _applicationPaths;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
public MovieResolver(IServerApplicationPaths appPaths, ILibraryManager libraryManager, ILogger logger, IFileSystem fileSystem)
|
||||
public MovieResolver(ILibraryManager libraryManager, IServerApplicationPaths applicationPaths, ILogger logger, IFileSystem fileSystem) : base(libraryManager)
|
||||
{
|
||||
_applicationPaths = appPaths;
|
||||
_libraryManager = libraryManager;
|
||||
_applicationPaths = applicationPaths;
|
||||
_logger = logger;
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
@@ -221,7 +219,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
||||
};
|
||||
}
|
||||
|
||||
if (EntityResolutionHelper.IsMultiPartFolder(filename))
|
||||
if (LibraryManager.IsMultiPartFolder(filename))
|
||||
{
|
||||
multiDiscFolders.Add(child);
|
||||
}
|
||||
@@ -235,7 +233,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
||||
continue;
|
||||
}
|
||||
|
||||
var childArgs = new ItemResolveArgs(_applicationPaths, _libraryManager, directoryService)
|
||||
var childArgs = new ItemResolveArgs(_applicationPaths, LibraryManager, directoryService)
|
||||
{
|
||||
FileInfo = child,
|
||||
Path = child.FullName,
|
||||
@@ -378,7 +376,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
||||
var firstMovie = sortedMovies[0];
|
||||
|
||||
// They must all be part of the sequence if we're going to consider it a multi-part movie
|
||||
if (sortedMovies.All(i => EntityResolutionHelper.IsMultiPartFile(i.Path)))
|
||||
if (sortedMovies.All(i => LibraryManager.IsMultiPartFile(i.Path)))
|
||||
{
|
||||
// Only support up to 8 (matches Plex), to help avoid incorrect detection
|
||||
if (sortedMovies.Count <= 8)
|
||||
|
||||
@@ -11,6 +11,10 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
|
||||
/// </summary>
|
||||
public class EpisodeResolver : BaseVideoResolver<Episode>
|
||||
{
|
||||
public EpisodeResolver(ILibraryManager libraryManager) : base(libraryManager)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the specified args.
|
||||
/// </summary>
|
||||
@@ -73,7 +77,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
|
||||
|
||||
if (episode.ParentIndexNumber == null)
|
||||
{
|
||||
episode.ParentIndexNumber = TVUtils.GetSeasonNumberFromEpisodeFile(args.Path);
|
||||
episode.ParentIndexNumber = SeriesResolver.GetSeasonNumberFromEpisodeFile(args.Path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
|
||||
{
|
||||
var season = new Season
|
||||
{
|
||||
IndexNumber = TVUtils.GetSeasonNumberFromPath(args.Path)
|
||||
IndexNumber = SeriesResolver.GetSeasonNumberFromPath(args.Path)
|
||||
};
|
||||
|
||||
|
||||
if (season.IndexNumber.HasValue && season.IndexNumber.Value == 0)
|
||||
{
|
||||
season.Name = _config.Configuration.SeasonZeroDisplayName;
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
|
||||
{
|
||||
@@ -18,11 +24,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
public SeriesResolver(IFileSystem fileSystem, ILogger logger)
|
||||
public SeriesResolver(IFileSystem fileSystem, ILogger logger, ILibraryManager libraryManager)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_logger = logger;
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -71,7 +79,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
|
||||
return null;
|
||||
}
|
||||
|
||||
if (TVUtils.IsSeriesFolder(args.Path, isTvShowsFolder, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger))
|
||||
if (IsSeriesFolder(args.Path, isTvShowsFolder, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager))
|
||||
{
|
||||
return new Series();
|
||||
}
|
||||
@@ -80,6 +88,454 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether [is series folder] [the specified path].
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <param name="considerSeasonlessEntries">if set to <c>true</c> [consider seasonless entries].</param>
|
||||
/// <param name="fileSystemChildren">The file system children.</param>
|
||||
/// <param name="directoryService">The directory service.</param>
|
||||
/// <param name="fileSystem">The file system.</param>
|
||||
/// <returns><c>true</c> if [is series folder] [the specified path]; otherwise, <c>false</c>.</returns>
|
||||
public static bool IsSeriesFolder(string path, bool considerSeasonlessEntries, IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService, IFileSystem fileSystem, ILogger logger, ILibraryManager libraryManager)
|
||||
{
|
||||
// A folder with more than 3 non-season folders in will not becounted as a series
|
||||
var nonSeriesFolders = 0;
|
||||
|
||||
foreach (var child in fileSystemChildren)
|
||||
{
|
||||
var attributes = child.Attributes;
|
||||
|
||||
if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
|
||||
{
|
||||
//logger.Debug("Igoring series file or folder marked hidden: {0}", child.FullName);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Can't enforce this because files saved by Bitcasa are always marked System
|
||||
//if ((attributes & FileAttributes.System) == FileAttributes.System)
|
||||
//{
|
||||
// logger.Debug("Igoring series subfolder marked system: {0}", child.FullName);
|
||||
// continue;
|
||||
//}
|
||||
|
||||
if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
||||
{
|
||||
if (IsSeasonFolder(child.FullName, directoryService, fileSystem))
|
||||
{
|
||||
//logger.Debug("{0} is a series because of season folder {1}.", path, child.FullName);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (IsBadFolder(child.Name))
|
||||
{
|
||||
logger.Debug("Invalid folder under series: {0}", child.FullName);
|
||||
|
||||
nonSeriesFolders++;
|
||||
}
|
||||
|
||||
if (nonSeriesFolders >= 3)
|
||||
{
|
||||
logger.Debug("{0} not a series due to 3 or more invalid folders.", path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var fullName = child.FullName;
|
||||
|
||||
if (libraryManager.IsVideoFile(fullName) || IsVideoPlaceHolder(fullName))
|
||||
{
|
||||
if (GetEpisodeNumberFromFile(fullName, considerSeasonlessEntries).HasValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.Debug("{0} is not a series folder.", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether [is place holder] [the specified path].
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns><c>true</c> if [is place holder] [the specified path]; otherwise, <c>false</c>.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">path</exception>
|
||||
private static bool IsVideoPlaceHolder(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new ArgumentNullException("path");
|
||||
}
|
||||
|
||||
var extension = Path.GetExtension(path);
|
||||
|
||||
return string.Equals(extension, ".disc", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static bool IsBadFolder(string name)
|
||||
{
|
||||
if (string.Equals(name, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (string.Equals(name, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (string.Equals(name, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !EntityResolutionHelper.IgnoreFolders.Contains(name, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether [is season folder] [the specified path].
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <param name="directoryService">The directory service.</param>
|
||||
/// <param name="fileSystem">The file system.</param>
|
||||
/// <returns><c>true</c> if [is season folder] [the specified path]; otherwise, <c>false</c>.</returns>
|
||||
private static bool IsSeasonFolder(string path, IDirectoryService directoryService, IFileSystem fileSystem)
|
||||
{
|
||||
var seasonNumber = GetSeasonNumberFromPath(path);
|
||||
var hasSeasonNumber = seasonNumber != null;
|
||||
|
||||
if (!hasSeasonNumber)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//// It's a season folder if it's named as such and does not contain any audio files, apart from theme.mp3
|
||||
//foreach (var fileSystemInfo in directoryService.GetFileSystemEntries(path))
|
||||
//{
|
||||
// var attributes = fileSystemInfo.Attributes;
|
||||
|
||||
// if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// // Can't enforce this because files saved by Bitcasa are always marked System
|
||||
// //if ((attributes & FileAttributes.System) == FileAttributes.System)
|
||||
// //{
|
||||
// // continue;
|
||||
// //}
|
||||
|
||||
// if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
||||
// {
|
||||
// //if (IsBadFolder(fileSystemInfo.Name))
|
||||
// //{
|
||||
// // return false;
|
||||
// //}
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (EntityResolutionHelper.IsAudioFile(fileSystemInfo.FullName) &&
|
||||
// !string.Equals(fileSystem.GetFileNameWithoutExtension(fileSystemInfo), BaseItem.ThemeSongFilename))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A season folder must contain one of these somewhere in the name
|
||||
/// </summary>
|
||||
private static readonly string[] SeasonFolderNames =
|
||||
{
|
||||
"season",
|
||||
"sæson",
|
||||
"temporada",
|
||||
"saison",
|
||||
"staffel",
|
||||
"series",
|
||||
"сезон"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Used to detect paths that represent episodes, need to make sure they don't also
|
||||
/// match movie titles like "2001 A Space..."
|
||||
/// Currently we limit the numbers here to 2 digits to try and avoid this
|
||||
/// </summary>
|
||||
private static readonly Regex[] EpisodeExpressions =
|
||||
{
|
||||
new Regex(
|
||||
@".*(\\|\/)[sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3})[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
new Regex(
|
||||
@".*(\\|\/)[sS](?<seasonnumber>\d{1,4})[x,X]?[eE](?<epnumber>\d{1,3})[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
new Regex(
|
||||
@".*(\\|\/)(?<seriesname>((?![sS]?\d{1,4}[xX]\d{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3}))[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
new Regex(
|
||||
@".*(\\|\/)(?<seriesname>[^\\\/]*)[sS](?<seasonnumber>\d{1,4})[xX\.]?[eE](?<epnumber>\d{1,3})[^\\\/]*$",
|
||||
RegexOptions.Compiled)
|
||||
};
|
||||
private static readonly Regex[] MultipleEpisodeExpressions =
|
||||
{
|
||||
new Regex(
|
||||
@".*(\\|\/)[sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3})((-| - )\d{1,4}[eExX](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
new Regex(
|
||||
@".*(\\|\/)[sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3})((-| - )\d{1,4}[xX][eE](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
new Regex(
|
||||
@".*(\\|\/)[sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3})((-| - )?[xXeE](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
new Regex(
|
||||
@".*(\\|\/)[sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3})(-[xE]?[eE]?(?<endingepnumber>\d{1,3}))+[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
new Regex(
|
||||
@".*(\\|\/)(?<seriesname>((?![sS]?\d{1,4}[xX]\d{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3}))((-| - )\d{1,4}[xXeE](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
new Regex(
|
||||
@".*(\\|\/)(?<seriesname>((?![sS]?\d{1,4}[xX]\d{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3}))((-| - )\d{1,4}[xX][eE](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
new Regex(
|
||||
@".*(\\|\/)(?<seriesname>((?![sS]?\d{1,4}[xX]\d{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3}))((-| - )?[xXeE](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
new Regex(
|
||||
@".*(\\|\/)(?<seriesname>((?![sS]?\d{1,4}[xX]\d{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3}))(-[xX]?[eE]?(?<endingepnumber>\d{1,3}))+[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
new Regex(
|
||||
@".*(\\|\/)(?<seriesname>[^\\\/]*)[sS](?<seasonnumber>\d{1,4})[xX\.]?[eE](?<epnumber>\d{1,3})((-| - )?[xXeE](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
new Regex(
|
||||
@".*(\\|\/)(?<seriesname>[^\\\/]*)[sS](?<seasonnumber>\d{1,4})[xX\.]?[eE](?<epnumber>\d{1,3})(-[xX]?[eE]?(?<endingepnumber>\d{1,3}))+[^\\\/]*$",
|
||||
RegexOptions.Compiled)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// To avoid the following matching movies they are only valid when contained in a folder which has been matched as a being season, or the media type is TV series
|
||||
/// </summary>
|
||||
private static readonly Regex[] EpisodeExpressionsWithoutSeason =
|
||||
{
|
||||
new Regex(
|
||||
@".*[\\\/](?<epnumber>\d{1,3})(-(?<endingepnumber>\d{2,3}))*\.\w+$",
|
||||
RegexOptions.Compiled),
|
||||
// "01.avi"
|
||||
new Regex(
|
||||
@".*(\\|\/)(?<epnumber>\d{1,3})(-(?<endingepnumber>\d{2,3}))*\s?-\s?[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
// "01 - blah.avi", "01-blah.avi"
|
||||
new Regex(
|
||||
@".*(\\|\/)(?<epnumber>\d{1,3})(-(?<endingepnumber>\d{2,3}))*\.[^\\\/]+$",
|
||||
RegexOptions.Compiled),
|
||||
// "01.blah.avi"
|
||||
new Regex(
|
||||
@".*[\\\/][^\\\/]* - (?<epnumber>\d{1,3})(-(?<endingepnumber>\d{2,3}))*[^\\\/]*$",
|
||||
RegexOptions.Compiled),
|
||||
// "blah - 01.avi", "blah 2 - 01.avi", "blah - 01 blah.avi", "blah 2 - 01 blah", "blah - 01 - blah.avi", "blah 2 - 01 - blah"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the season number from path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns>System.Nullable{System.Int32}.</returns>
|
||||
public static int? GetSeasonNumberFromPath(string path)
|
||||
{
|
||||
var filename = Path.GetFileName(path);
|
||||
|
||||
if (string.Equals(filename, "specials", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int val;
|
||||
if (int.TryParse(filename, NumberStyles.Integer, CultureInfo.InvariantCulture, out val))
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
if (filename.StartsWith("s", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var testFilename = filename.Substring(1);
|
||||
|
||||
if (int.TryParse(testFilename, NumberStyles.Integer, CultureInfo.InvariantCulture, out val))
|
||||
{
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
// Look for one of the season folder names
|
||||
foreach (var name in SeasonFolderNames)
|
||||
{
|
||||
var index = filename.IndexOf(name, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
return GetSeasonNumberFromPathSubstring(filename.Substring(index + name.Length));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the season number from the second half of the Season folder name (everything after "Season", or "Staffel")
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns>System.Nullable{System.Int32}.</returns>
|
||||
private static int? GetSeasonNumberFromPathSubstring(string path)
|
||||
{
|
||||
var numericStart = -1;
|
||||
var length = 0;
|
||||
|
||||
// Find out where the numbers start, and then keep going until they end
|
||||
for (var i = 0; i < path.Length; i++)
|
||||
{
|
||||
if (char.IsNumber(path, i))
|
||||
{
|
||||
if (numericStart == -1)
|
||||
{
|
||||
numericStart = i;
|
||||
}
|
||||
length++;
|
||||
}
|
||||
else if (numericStart != -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (numericStart == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return int.Parse(path.Substring(numericStart, length), CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Episodes the number from file.
|
||||
/// </summary>
|
||||
/// <param name="fullPath">The full path.</param>
|
||||
/// <param name="considerSeasonlessNames">if set to <c>true</c> [is in season].</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static int? GetEpisodeNumberFromFile(string fullPath, bool considerSeasonlessNames)
|
||||
{
|
||||
string fl = fullPath.ToLower();
|
||||
foreach (var r in EpisodeExpressions)
|
||||
{
|
||||
Match m = r.Match(fl);
|
||||
if (m.Success)
|
||||
return ParseEpisodeNumber(m.Groups["epnumber"].Value);
|
||||
}
|
||||
if (considerSeasonlessNames)
|
||||
{
|
||||
var match = EpisodeExpressionsWithoutSeason.Select(r => r.Match(fl))
|
||||
.FirstOrDefault(m => m.Success);
|
||||
|
||||
if (match != null)
|
||||
{
|
||||
return ParseEpisodeNumber(match.Groups["epnumber"].Value);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int? GetEndingEpisodeNumberFromFile(string fullPath)
|
||||
{
|
||||
var fl = fullPath.ToLower();
|
||||
foreach (var r in MultipleEpisodeExpressions)
|
||||
{
|
||||
var m = r.Match(fl);
|
||||
if (m.Success && !string.IsNullOrEmpty(m.Groups["endingepnumber"].Value))
|
||||
return ParseEpisodeNumber(m.Groups["endingepnumber"].Value);
|
||||
}
|
||||
foreach (var r in EpisodeExpressionsWithoutSeason)
|
||||
{
|
||||
var m = r.Match(fl);
|
||||
if (m.Success && !string.IsNullOrEmpty(m.Groups["endingepnumber"].Value))
|
||||
return ParseEpisodeNumber(m.Groups["endingepnumber"].Value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seasons the number from episode file.
|
||||
/// </summary>
|
||||
/// <param name="fullPath">The full path.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static int? GetSeasonNumberFromEpisodeFile(string fullPath)
|
||||
{
|
||||
string fl = fullPath.ToLower();
|
||||
foreach (var r in EpisodeExpressions)
|
||||
{
|
||||
Match m = r.Match(fl);
|
||||
if (m.Success)
|
||||
{
|
||||
Group g = m.Groups["seasonnumber"];
|
||||
if (g != null)
|
||||
{
|
||||
var val = g.Value;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(val))
|
||||
{
|
||||
int num;
|
||||
|
||||
if (int.TryParse(val, NumberStyles.Integer, UsCulture, out num))
|
||||
{
|
||||
return num;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetSeriesNameFromEpisodeFile(string fullPath)
|
||||
{
|
||||
var fl = fullPath.ToLower();
|
||||
foreach (var r in EpisodeExpressions)
|
||||
{
|
||||
var m = r.Match(fl);
|
||||
if (m.Success)
|
||||
{
|
||||
var g = m.Groups["seriesname"];
|
||||
if (g != null)
|
||||
{
|
||||
var val = g.Value;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(val))
|
||||
{
|
||||
return val;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
||||
|
||||
private static int? ParseEpisodeNumber(string val)
|
||||
{
|
||||
int num;
|
||||
|
||||
if (!string.IsNullOrEmpty(val) && int.TryParse(val, NumberStyles.Integer, UsCulture, out num))
|
||||
{
|
||||
return num;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the initial item values.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
||||
{
|
||||
@@ -8,6 +12,31 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
||||
/// </summary>
|
||||
public class VideoResolver : BaseVideoResolver<Video>
|
||||
{
|
||||
public VideoResolver(ILibraryManager libraryManager)
|
||||
: base(libraryManager)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Video Resolve(ItemResolveArgs args)
|
||||
{
|
||||
if (args.Parent != null)
|
||||
{
|
||||
var collectionType = args.GetCollectionType() ?? string.Empty;
|
||||
var accepted = new[]
|
||||
{
|
||||
string.Empty,
|
||||
CollectionType.HomeVideos
|
||||
};
|
||||
|
||||
if (!accepted.Contains(collectionType, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return base.Resolve(args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
|
||||
@@ -19,7 +19,6 @@ using MediaBrowser.Model.Events;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Model.Users;
|
||||
using MediaBrowser.Server.Implementations.Security;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
@@ -49,6 +49,10 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\ThirdParty\libwebp\Imazen.WebP.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MediaBrowser.Naming, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Naming.1.0.0.1\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Mono.Nat, Version=1.2.21.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Mono.Nat.1.2.21.0\lib\net40\Mono.Nat.dll</HintPath>
|
||||
@@ -174,8 +178,10 @@
|
||||
<Compile Include="Intros\DefaultIntroProvider.cs" />
|
||||
<Compile Include="IO\LibraryMonitor.cs" />
|
||||
<Compile Include="Library\CoreResolutionIgnoreRule.cs" />
|
||||
<Compile Include="Library\EntityResolutionHelper.cs" />
|
||||
<Compile Include="Library\LibraryManager.cs" />
|
||||
<Compile Include="Library\MusicManager.cs" />
|
||||
<Compile Include="Library\Resolvers\BaseVideoResolver.cs" />
|
||||
<Compile Include="Library\Resolvers\PhotoAlbumResolver.cs" />
|
||||
<Compile Include="Library\Resolvers\PhotoResolver.cs" />
|
||||
<Compile Include="Library\Resolvers\PlaylistResolver.cs" />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MediaBrowser.Naming" version="1.0.0.1" targetFramework="net45" />
|
||||
<package id="Mono.Nat" version="1.2.21.0" targetFramework="net45" />
|
||||
<package id="morelinq" version="1.1.0" targetFramework="net45" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user