jellyfin/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs

140 lines
5.6 KiB
C#
Raw Normal View History

2014-11-16 21:44:08 +01:00
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
2014-11-28 18:41:47 +01:00
using MediaBrowser.Naming.Common;
2014-11-16 21:44:08 +01:00
using System;
2014-11-29 20:51:30 +01:00
using System.IO;
2014-11-16 21:44:08 +01:00
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)
{
2014-11-29 20:51:30 +01:00
return ResolveVideo<T>(args, true);
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()
{
// If the path is a file check for a matching extensions
if (!args.IsDirectory)
{
2014-11-28 18:41:47 +01:00
var parser = new Naming.Video.VideoResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger());
2014-11-16 23:46:01 +01:00
var videoInfo = parser.ResolveFile(args.Path);
2014-11-16 21:44:08 +01:00
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,
2014-11-16 23:46:01 +01:00
ProductionYear = videoInfo.Year
2014-11-16 21:44:08 +01:00
};
2014-11-29 20:51:30 +01:00
if (parseName)
{
video.Name = videoInfo.Name;
}
else
{
video.Name = Path.GetFileNameWithoutExtension(path);
}
2014-11-16 21:44:08 +01:00
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;
}
}
2014-11-29 20:51:30 +01:00
if (videoInfo.Is3D)
{
if (string.Equals(videoInfo.Format3D, "fsbs", StringComparison.OrdinalIgnoreCase))
{
video.Video3DFormat = Video3DFormat.FullSideBySide;
}
else if (string.Equals(videoInfo.Format3D, "ftab", StringComparison.OrdinalIgnoreCase))
{
video.Video3DFormat = Video3DFormat.FullTopAndBottom;
}
else if (string.Equals(videoInfo.Format3D, "hsbs", StringComparison.OrdinalIgnoreCase))
{
video.Video3DFormat = Video3DFormat.HalfSideBySide;
}
else if (string.Equals(videoInfo.Format3D, "htab", StringComparison.OrdinalIgnoreCase))
{
video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
}
else if (string.Equals(videoInfo.Format3D, "sbs", StringComparison.OrdinalIgnoreCase))
{
video.Video3DFormat = Video3DFormat.HalfSideBySide;
}
else if (string.Equals(videoInfo.Format3D, "sbs3d", StringComparison.OrdinalIgnoreCase))
{
video.Video3DFormat = Video3DFormat.HalfSideBySide;
}
else if (string.Equals(videoInfo.Format3D, "tab", StringComparison.OrdinalIgnoreCase))
{
video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
}
}
2014-11-16 21:44:08 +01:00
return video;
}
}
return null;
}
}
}