2019-11-01 18:38:54 +01:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 20:54:44 +01:00
|
|
|
using System;
|
2014-11-29 20:51:30 +01:00
|
|
|
using System.IO;
|
2016-12-03 22:46:06 +01:00
|
|
|
using System.Linq;
|
2019-01-13 20:21:32 +01:00
|
|
|
using Emby.Naming.Video;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Library;
|
2016-12-03 22:46:06 +01:00
|
|
|
using MediaBrowser.Controller.Providers;
|
2019-01-13 20:21:32 +01:00
|
|
|
using MediaBrowser.Model.Entities;
|
2014-11-16 21:44:08 +01:00
|
|
|
|
2016-11-03 07:37:52 +01:00
|
|
|
namespace Emby.Server.Implementations.Library.Resolvers
|
2014-11-16 21:44:08 +01:00
|
|
|
{
|
|
|
|
/// <summary>
|
2019-11-01 18:38:54 +01:00
|
|
|
/// Resolves a Path into a Video or Video subclass.
|
2014-11-16 21:44:08 +01:00
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T"></typeparam>
|
2016-11-03 07:37:52 +01:00
|
|
|
public abstract class BaseVideoResolver<T> : MediaBrowser.Controller.Resolvers.ItemResolver<T>
|
2014-11-16 21:44:08 +01:00
|
|
|
where T : Video, new()
|
|
|
|
{
|
|
|
|
protected readonly ILibraryManager LibraryManager;
|
|
|
|
|
2019-02-06 20:38:42 +01:00
|
|
|
protected BaseVideoResolver(ILibraryManager libraryManager)
|
2014-11-16 21:44:08 +01:00
|
|
|
{
|
|
|
|
LibraryManager = libraryManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Resolves the specified args.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
/// <returns>`0.</returns>
|
2021-03-14 19:56:45 +01:00
|
|
|
public override T Resolve(ItemResolveArgs args)
|
2014-11-16 21:44:08 +01:00
|
|
|
{
|
2014-12-04 06:24:41 +01:00
|
|
|
return ResolveVideo<T>(args, false);
|
2014-11-16 21:44:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Resolves the video.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TVideoType">The type of the T video type.</typeparam>
|
|
|
|
/// <param name="args">The args.</param>
|
2014-11-29 20:51:30 +01:00
|
|
|
/// <param name="parseName">if set to <c>true</c> [parse name].</param>
|
2014-11-16 21:44:08 +01:00
|
|
|
/// <returns>``0.</returns>
|
2014-11-29 20:51:30 +01:00
|
|
|
protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args, bool parseName)
|
2014-11-16 21:44:08 +01:00
|
|
|
where TVideoType : Video, new()
|
|
|
|
{
|
2015-01-10 06:53:35 +01:00
|
|
|
var namingOptions = ((LibraryManager)LibraryManager).GetNamingOptions();
|
2019-01-08 00:27:46 +01:00
|
|
|
|
2014-11-16 21:44:08 +01:00
|
|
|
// If the path is a file check for a matching extensions
|
2019-01-13 21:37:13 +01:00
|
|
|
var parser = new VideoResolver(namingOptions);
|
2014-12-03 04:13:03 +01:00
|
|
|
|
|
|
|
if (args.IsDirectory)
|
|
|
|
{
|
|
|
|
TVideoType video = null;
|
|
|
|
VideoFileInfo videoInfo = null;
|
|
|
|
|
|
|
|
// Loop through each child file/folder and see if we find a video
|
|
|
|
foreach (var child in args.FileSystemChildren)
|
|
|
|
{
|
|
|
|
var filename = child.Name;
|
|
|
|
|
2016-10-25 21:02:04 +02:00
|
|
|
if (child.IsDirectory)
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
2016-12-03 22:46:06 +01:00
|
|
|
if (IsDvdDirectory(child.FullName, filename, args.DirectoryService))
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
|
|
|
videoInfo = parser.ResolveDirectory(args.Path);
|
|
|
|
|
|
|
|
if (videoInfo == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
video = new TVideoType
|
|
|
|
{
|
|
|
|
Path = args.Path,
|
|
|
|
VideoType = VideoType.Dvd,
|
|
|
|
ProductionYear = videoInfo.Year
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
2020-02-19 21:56:35 +01:00
|
|
|
|
2016-12-03 22:46:06 +01:00
|
|
|
if (IsBluRayDirectory(child.FullName, filename, args.DirectoryService))
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
|
|
|
videoInfo = parser.ResolveDirectory(args.Path);
|
|
|
|
|
|
|
|
if (videoInfo == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
video = new TVideoType
|
|
|
|
{
|
|
|
|
Path = args.Path,
|
|
|
|
VideoType = VideoType.BluRay,
|
|
|
|
ProductionYear = videoInfo.Year
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-12-09 05:57:18 +01:00
|
|
|
else if (IsDvdFile(filename))
|
|
|
|
{
|
|
|
|
videoInfo = parser.ResolveDirectory(args.Path);
|
|
|
|
|
|
|
|
if (videoInfo == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
video = new TVideoType
|
|
|
|
{
|
|
|
|
Path = args.Path,
|
|
|
|
VideoType = VideoType.Dvd,
|
|
|
|
ProductionYear = videoInfo.Year
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
2014-12-03 04:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (video != null)
|
|
|
|
{
|
2019-01-08 00:27:46 +01:00
|
|
|
video.Name = parseName ?
|
2014-12-04 06:24:41 +01:00
|
|
|
videoInfo.Name :
|
|
|
|
Path.GetFileName(args.Path);
|
2014-12-03 04:13:03 +01:00
|
|
|
|
|
|
|
Set3DFormat(video, videoInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return video;
|
|
|
|
}
|
|
|
|
else
|
2014-11-16 21:44:08 +01:00
|
|
|
{
|
2016-06-17 15:06:13 +02:00
|
|
|
var videoInfo = parser.Resolve(args.Path, false, false);
|
2014-11-16 21:44:08 +01:00
|
|
|
|
|
|
|
if (videoInfo == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-02-19 21:56:35 +01:00
|
|
|
if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub)
|
2014-11-16 21:44:08 +01:00
|
|
|
{
|
|
|
|
var path = args.Path;
|
|
|
|
|
|
|
|
var video = new TVideoType
|
|
|
|
{
|
|
|
|
Path = path,
|
|
|
|
IsInMixedFolder = true,
|
2014-11-16 23:46:01 +01:00
|
|
|
ProductionYear = videoInfo.Year
|
2014-11-16 21:44:08 +01:00
|
|
|
};
|
|
|
|
|
2014-12-04 06:24:41 +01:00
|
|
|
SetVideoType(video, videoInfo);
|
2019-01-08 00:27:46 +01:00
|
|
|
|
2014-12-04 06:24:41 +01:00
|
|
|
video.Name = parseName ?
|
|
|
|
videoInfo.Name :
|
|
|
|
Path.GetFileNameWithoutExtension(args.Path);
|
2014-11-16 21:44:08 +01:00
|
|
|
|
2014-12-03 04:13:03 +01:00
|
|
|
Set3DFormat(video, videoInfo);
|
2014-11-29 20:51:30 +01:00
|
|
|
|
2014-11-16 21:44:08 +01:00
|
|
|
return video;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2014-12-03 04:13:03 +01:00
|
|
|
|
2014-12-04 06:24:41 +01:00
|
|
|
protected void SetVideoType(Video video, VideoFileInfo videoInfo)
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
2014-12-04 06:24:41 +01:00
|
|
|
var extension = Path.GetExtension(video.Path);
|
|
|
|
video.VideoType = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ?
|
|
|
|
VideoType.Iso :
|
|
|
|
VideoType.VideoFile;
|
|
|
|
|
|
|
|
video.IsShortcut = string.Equals(extension, ".strm", StringComparison.OrdinalIgnoreCase);
|
|
|
|
video.IsPlaceHolder = videoInfo.IsStub;
|
|
|
|
|
|
|
|
if (videoInfo.IsStub)
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
2014-12-04 06:24:41 +01:00
|
|
|
if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
video.VideoType = VideoType.Dvd;
|
|
|
|
}
|
|
|
|
else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
video.VideoType = VideoType.BluRay;
|
|
|
|
}
|
|
|
|
}
|
2016-02-09 05:09:29 +01:00
|
|
|
|
|
|
|
SetIsoType(video);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void SetIsoType(Video video)
|
|
|
|
{
|
|
|
|
if (video.VideoType == VideoType.Iso)
|
|
|
|
{
|
|
|
|
if (video.Path.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
{
|
|
|
|
video.IsoType = IsoType.Dvd;
|
|
|
|
}
|
|
|
|
else if (video.Path.IndexOf("bluray", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
{
|
|
|
|
video.IsoType = IsoType.BluRay;
|
|
|
|
}
|
|
|
|
}
|
2014-12-04 06:24:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void Set3DFormat(Video video, bool is3D, string format3D)
|
|
|
|
{
|
|
|
|
if (is3D)
|
|
|
|
{
|
|
|
|
if (string.Equals(format3D, "fsbs", StringComparison.OrdinalIgnoreCase))
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.FullSideBySide;
|
|
|
|
}
|
2014-12-04 06:24:41 +01:00
|
|
|
else if (string.Equals(format3D, "ftab", StringComparison.OrdinalIgnoreCase))
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.FullTopAndBottom;
|
|
|
|
}
|
2014-12-04 06:24:41 +01:00
|
|
|
else if (string.Equals(format3D, "hsbs", StringComparison.OrdinalIgnoreCase))
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfSideBySide;
|
|
|
|
}
|
2014-12-04 06:24:41 +01:00
|
|
|
else if (string.Equals(format3D, "htab", StringComparison.OrdinalIgnoreCase))
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
|
|
|
|
}
|
2014-12-04 06:24:41 +01:00
|
|
|
else if (string.Equals(format3D, "sbs", StringComparison.OrdinalIgnoreCase))
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfSideBySide;
|
|
|
|
}
|
2014-12-04 06:24:41 +01:00
|
|
|
else if (string.Equals(format3D, "sbs3d", StringComparison.OrdinalIgnoreCase))
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfSideBySide;
|
|
|
|
}
|
2014-12-04 06:24:41 +01:00
|
|
|
else if (string.Equals(format3D, "tab", StringComparison.OrdinalIgnoreCase))
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
|
|
|
|
}
|
2016-02-11 20:11:28 +01:00
|
|
|
else if (string.Equals(format3D, "mvc", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.MVC;
|
|
|
|
}
|
2014-12-03 04:13:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-04 06:24:41 +01:00
|
|
|
protected void Set3DFormat(Video video, VideoFileInfo videoInfo)
|
|
|
|
{
|
|
|
|
Set3DFormat(video, videoInfo.Is3D, videoInfo.Format3D);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void Set3DFormat(Video video)
|
|
|
|
{
|
2015-01-10 06:53:35 +01:00
|
|
|
var namingOptions = ((LibraryManager)LibraryManager).GetNamingOptions();
|
|
|
|
|
2017-09-10 22:40:31 +02:00
|
|
|
var resolver = new Format3DParser(namingOptions);
|
2014-12-04 06:24:41 +01:00
|
|
|
var result = resolver.Parse(video.Path);
|
|
|
|
|
|
|
|
Set3DFormat(video, result.Is3D, result.Format3D);
|
|
|
|
}
|
|
|
|
|
2014-12-03 04:13:03 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Determines whether [is DVD directory] [the specified directory name].
|
|
|
|
/// </summary>
|
2016-12-03 22:46:06 +01:00
|
|
|
protected bool IsDvdDirectory(string fullPath, string directoryName, IDirectoryService directoryService)
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
2016-12-03 22:46:06 +01:00
|
|
|
if (!string.Equals(directoryName, "video_ts", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-05 22:51:23 +01:00
|
|
|
return directoryService.GetFilePaths(fullPath).Any(i => string.Equals(Path.GetExtension(i), ".vob", StringComparison.OrdinalIgnoreCase));
|
2014-12-03 04:13:03 +01:00
|
|
|
}
|
|
|
|
|
2014-12-09 05:57:18 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Determines whether [is DVD file] [the specified name].
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">The name.</param>
|
|
|
|
/// <returns><c>true</c> if [is DVD file] [the specified name]; otherwise, <c>false</c>.</returns>
|
|
|
|
protected bool IsDvdFile(string name)
|
|
|
|
{
|
|
|
|
return string.Equals(name, "video_ts.ifo", StringComparison.OrdinalIgnoreCase);
|
|
|
|
}
|
2019-01-08 00:27:46 +01:00
|
|
|
|
2014-12-03 04:13:03 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Determines whether [is blu ray directory] [the specified directory name].
|
|
|
|
/// </summary>
|
2016-12-03 22:46:06 +01:00
|
|
|
protected bool IsBluRayDirectory(string fullPath, string directoryName, IDirectoryService directoryService)
|
2014-12-03 04:13:03 +01:00
|
|
|
{
|
2016-12-03 22:46:06 +01:00
|
|
|
if (!string.Equals(directoryName, "bdmv", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-05 19:53:35 +01:00
|
|
|
return true;
|
2020-06-14 11:11:11 +02:00
|
|
|
// var blurayExtensions = new[]
|
2016-12-05 19:53:35 +01:00
|
|
|
//{
|
|
|
|
// ".mts",
|
|
|
|
// ".m2ts",
|
|
|
|
// ".bdmv",
|
|
|
|
// ".mpls"
|
|
|
|
//};
|
|
|
|
|
2020-06-14 11:11:11 +02:00
|
|
|
// return directoryService.GetFiles(fullPath).Any(i => blurayExtensions.Contains(i.Extension ?? string.Empty, StringComparer.OrdinalIgnoreCase));
|
2014-12-03 04:13:03 +01:00
|
|
|
}
|
2014-11-16 21:44:08 +01:00
|
|
|
}
|
|
|
|
}
|