use new naming project

This commit is contained in:
Luke Pulverenti
2014-11-17 21:48:22 -05:00
parent 049ef9b4ec
commit 124754a04f
25 changed files with 167 additions and 149 deletions

View File

@@ -4,7 +4,6 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.HttpServer
{
@@ -91,7 +90,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
ThrottleCallback = ThrottleCallback
};
}
WriteToAsync(responseStream);
WriteToInternal(responseStream);
}
/// <summary>
@@ -99,7 +98,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// </summary>
/// <param name="responseStream">The response stream.</param>
/// <returns>Task.</returns>
private void WriteToAsync(Stream responseStream)
private void WriteToInternal(Stream responseStream)
{
try
{

View File

@@ -1644,18 +1644,6 @@ namespace MediaBrowser.Server.Implementations.Library
return parser.IsAudioFile(path);
}
public bool IsMultiPartFile(string path)
{
var parser = new MultiPartParser(new ExpandedVideoOptions(), new AudioOptions(), new Naming.Logging.NullLogger());
return parser.Parse(path, FileInfoType.File).IsMultiPart;
}
public bool IsMultiPartFolder(string path)
{
var parser = new MultiPartParser(new ExpandedVideoOptions(), new AudioOptions(), new Naming.Logging.NullLogger());
return parser.Parse(path, FileInfoType.Directory).IsMultiPart;
}
public int? GetSeasonNumberFromPath(string path)
{
return SeriesResolver.GetSeasonNumberFromPath(path);
@@ -1688,5 +1676,42 @@ namespace MediaBrowser.Server.Implementations.Library
Year = result.Year
};
}
public IEnumerable<FileSystemInfo> GetAdditionalParts(string file,
VideoType type,
IEnumerable<FileSystemInfo> files)
{
var resolver = new StackResolver(new ExpandedVideoOptions(), new AudioOptions(), new Naming.Logging.NullLogger());
StackResult result;
List<FileSystemInfo> filteredFiles;
if (type == VideoType.BluRay || type == VideoType.Dvd)
{
filteredFiles = files.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
.ToList();
result = resolver.ResolveDirectories(filteredFiles.Select(i => i.FullName));
}
else
{
filteredFiles = files.Where(i => (i.Attributes & FileAttributes.Directory) != FileAttributes.Directory)
.ToList();
result = resolver.ResolveFiles(filteredFiles.Select(i => i.FullName));
}
var stack = result.Stacks
.FirstOrDefault(i => i.Files.Contains(file, StringComparer.OrdinalIgnoreCase));
if (stack != null)
{
return stack.Files.Where(i => !string.Equals(i, file, StringComparison.OrdinalIgnoreCase))
.Select(i => filteredFiles.FirstOrDefault(f => string.Equals(i, f.FullName, StringComparison.OrdinalIgnoreCase)))
.Where(i => i != null);
}
return new List<FileSystemInfo>();
}
}
}

View File

@@ -12,6 +12,8 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MediaBrowser.Naming.Audio;
using MediaBrowser.Naming.Video;
namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
{
@@ -88,11 +90,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, false, collectionType);
}
if (string.Equals(collectionType, CollectionType.AdultVideos, StringComparison.OrdinalIgnoreCase))
{
return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, true, false, collectionType);
}
if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
{
return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, true, false, collectionType);
@@ -128,11 +125,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
item = ResolveVideo<MusicVideo>(args);
}
if (string.Equals(collectionType, CollectionType.AdultVideos, StringComparison.OrdinalIgnoreCase))
{
item = ResolveVideo<Video>(args);
}
// To find a movie file, the collection type must be movies or boxsets
// Otherwise we'll consider it a plain video and let the video resolver handle it
if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) ||
@@ -219,10 +211,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
};
}
if (LibraryManager.IsMultiPartFolder(filename))
{
multiDiscFolders.Add(child);
}
multiDiscFolders.Add(child);
continue;
}
@@ -280,9 +269,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
if (multiDiscFolders.Count > 0)
{
var folders = fileSystemEntries.Where(child => (child.Attributes & FileAttributes.Directory) == FileAttributes.Directory);
return GetMultiDiscMovie<T>(multiDiscFolders, folders);
return GetMultiDiscMovie<T>(multiDiscFolders, directoryService);
}
return null;
@@ -293,16 +280,18 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="multiDiscFolders">The folders.</param>
/// <param name="allFolders">All folders.</param>
/// <param name="directoryService">The directory service.</param>
/// <returns>``0.</returns>
private T GetMultiDiscMovie<T>(List<FileSystemInfo> multiDiscFolders, IEnumerable<FileSystemInfo> allFolders)
private T GetMultiDiscMovie<T>(List<FileSystemInfo> multiDiscFolders, IDirectoryService directoryService)
where T : Video, new()
{
var videoTypes = new List<VideoType>();
var folderPaths = multiDiscFolders.Select(i => i.FullName).Where(i =>
{
var subfolders = Directory.GetDirectories(i).Select(Path.GetFileName).ToList();
var subfolders = directoryService.GetDirectories(i)
.Select(d => d.Name)
.ToList();
if (subfolders.Any(IsDvdDirectory))
{
@@ -320,7 +309,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
}).OrderBy(i => i).ToList();
// If different video types were found, don't allow this
if (videoTypes.Count > 0 && videoTypes.Any(i => i != videoTypes[0]))
if (videoTypes.Distinct().Count() > 1)
{
return null;
}
@@ -330,35 +319,24 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
return null;
}
// If there are other folders side by side that are folder rips, don't allow it
// TODO: Improve this to return null if any folder is present aside from our regularly ignored folders
if (allFolders.Except(multiDiscFolders).Any(i =>
{
var subfolders = Directory.GetDirectories(i.FullName).Select(Path.GetFileName).ToList();
var resolver = new StackResolver(new ExpandedVideoOptions(), new AudioOptions(), new Naming.Logging.NullLogger());
if (subfolders.Any(IsDvdDirectory))
{
return true;
}
if (subfolders.Any(IsBluRayDirectory))
{
return true;
}
var result = resolver.ResolveDirectories(folderPaths);
return false;
}))
if (result.Stacks.Count != 1)
{
return null;
}
return new T
{
Path = folderPaths[0],
IsMultiPart = true,
VideoType = videoTypes[0]
VideoType = videoTypes[0],
Name = result.Stacks[0].Name
};
}
@@ -375,21 +353,22 @@ 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 => LibraryManager.IsMultiPartFile(i.Path)))
var paths = sortedMovies.Select(i => i.Path).ToList();
var resolver = new StackResolver(new ExpandedVideoOptions(), new AudioOptions(), new Naming.Logging.NullLogger());
var result = resolver.ResolveFiles(paths);
if (result.Stacks.Count != 1)
{
// Only support up to 8 (matches Plex), to help avoid incorrect detection
if (sortedMovies.Count <= 8)
{
firstMovie.IsMultiPart = true;
_logger.Debug("Multi-part video found: " + firstMovie.Path);
return firstMovie;
}
return null;
}
return null;
firstMovie.IsMultiPart = true;
firstMovie.Name = result.Stacks[0].Name;
// They must all be part of the sequence if we're going to consider it a multi-part movie
return firstMovie;
}
private T GetMovieWithMultipleSources<T>(IEnumerable<T> movies)

View File

@@ -51,7 +51,7 @@
</Reference>
<Reference Include="MediaBrowser.Naming, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\MediaBrowser.Naming.1.0.0.2\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll</HintPath>
<HintPath>..\packages\MediaBrowser.Naming.1.0.0.6\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>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MediaBrowser.Naming" version="1.0.0.2" targetFramework="net45" />
<package id="MediaBrowser.Naming" version="1.0.0.6" targetFramework="net45" />
<package id="Mono.Nat" version="1.2.21.0" targetFramework="net45" />
<package id="morelinq" version="1.1.0" targetFramework="net45" />
</packages>