add new naming project

This commit is contained in:
Luke Pulverenti
2014-11-16 15:44:08 -05:00
parent 4edcab9c11
commit 5fdd7ec672
40 changed files with 1128 additions and 1311 deletions

View File

@@ -1,137 +0,0 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
using System;
using System.IO;
namespace MediaBrowser.Controller.Resolvers
{
/// <summary>
/// Resolves a Path into a Video or Video subclass
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class BaseVideoResolver<T> : ItemResolver<T>
where T : Video, new()
{
/// <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)
{
// http://wiki.xbmc.org/index.php?title=Media_stubs
var isPlaceHolder = EntityResolutionHelper.IsVideoPlaceHolder(args.Path);
var extension = Path.GetExtension(args.Path);
var isShortcut = string.Equals(extension, ".strm", StringComparison.OrdinalIgnoreCase);
if (EntityResolutionHelper.IsVideoFile(args.Path) || isPlaceHolder || isShortcut)
{
var type = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ?
VideoType.Iso : VideoType.VideoFile;
var path = args.Path;
var video = new TVideoType
{
VideoType = type,
Path = args.Path,
IsInMixedFolder = true,
IsPlaceHolder = isPlaceHolder,
IsShortcut = isShortcut
};
if (isPlaceHolder)
{
if (args.Path.EndsWith("dvd.disc", StringComparison.OrdinalIgnoreCase))
{
video.VideoType = VideoType.Dvd;
}
else if (args.Path.EndsWith("hddvd.disc", StringComparison.OrdinalIgnoreCase))
{
video.VideoType = VideoType.HdDvd;
}
else if (args.Path.EndsWith("bluray.disc", StringComparison.OrdinalIgnoreCase) ||
args.Path.EndsWith("brrip.disc", StringComparison.OrdinalIgnoreCase) ||
args.Path.EndsWith("bd25.disc", StringComparison.OrdinalIgnoreCase) ||
args.Path.EndsWith("bd50.disc", StringComparison.OrdinalIgnoreCase))
{
video.VideoType = VideoType.BluRay;
}
}
return video;
}
}
return null;
}
/// <summary>
/// Sets the initial item values.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="args">The args.</param>
protected override void SetInitialItemValues(T item, ItemResolveArgs args)
{
base.SetInitialItemValues(item, args);
if (item.Path.IndexOf("[3d]", StringComparison.OrdinalIgnoreCase) != -1 || item.Path.IndexOf("[sbs3d]", StringComparison.OrdinalIgnoreCase) != -1)
{
item.Video3DFormat = Video3DFormat.HalfSideBySide;
}
else if (item.Path.IndexOf("[hsbs]", StringComparison.OrdinalIgnoreCase) != -1)
{
item.Video3DFormat = Video3DFormat.HalfSideBySide;
}
else if (item.Path.IndexOf("[fsbs]", StringComparison.OrdinalIgnoreCase) != -1)
{
item.Video3DFormat = Video3DFormat.FullSideBySide;
}
else if (item.Path.IndexOf("[ftab]", StringComparison.OrdinalIgnoreCase) != -1)
{
item.Video3DFormat = Video3DFormat.FullTopAndBottom;
}
else if (item.Path.IndexOf("[htab]", StringComparison.OrdinalIgnoreCase) != -1)
{
item.Video3DFormat = Video3DFormat.HalfTopAndBottom;
}
else
{
// Support Xbmc conventions:
// http://wiki.xbmc.org/index.php?title=3D
var name = Path.GetFileName(item.Path);
name = name.Replace('.', ' ').Replace('_', ' ').Replace('-', ' ');
if (name.IndexOf(" 3d hsbs ", StringComparison.OrdinalIgnoreCase) != -1 ||
name.IndexOf(" 3d sbs ", StringComparison.OrdinalIgnoreCase) != -1)
{
item.Video3DFormat = Video3DFormat.HalfSideBySide;
}
else if (name.IndexOf(" 3d htab ", StringComparison.OrdinalIgnoreCase) != -1 ||
name.IndexOf(" 3d tab ", StringComparison.OrdinalIgnoreCase) != -1)
{
item.Video3DFormat = Video3DFormat.HalfTopAndBottom;
}
}
}
}
}

View File

@@ -1,263 +0,0 @@
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace MediaBrowser.Controller.Resolvers
{
/// <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"
};
private static readonly Regex MultiFileRegex = new Regex(
@"(.*?)([ _.-]*(?:cd|dvd|p(?:ar)?t|dis[ck]|d)[ _.-]*[0-9]+)(.*?)(\.[^.]+)$",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex MultiFolderRegex = new Regex(
@"(.*?)([ _.-]*(?:cd|dvd|p(?:ar)?t|dis[ck]|d)[ _.-]*[0-9]+)$",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
/// <summary>
/// Determines whether [is multi part file] [the specified path].
/// </summary>
/// <param name="path">The path.</param>
/// <returns><c>true</c> if [is multi part file] [the specified path]; otherwise, <c>false</c>.</returns>
public static bool IsMultiPartFile(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}
path = Path.GetFileName(path);
return MultiFileRegex.Match(path).Success;
}
public static bool IsMultiPartFolder(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}
path = Path.GetFileName(path);
return MultiFolderRegex.Match(path).Success;
}
/// <summary>
/// The audio file extensions
/// </summary>
public static readonly string[] AudioFileExtensions =
{
".mp3",
".flac",
".wma",
".aac",
".acc",
".m4a",
".m4b",
".wav",
".ape",
".ogg",
".oga"
//".asf",
//".mp4"
};
private static readonly Dictionary<string, string> AudioFileExtensionsDictionary = AudioFileExtensions.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Determines whether [is audio file] [the specified args].
/// </summary>
/// <param name="path">The path.</param>
/// <returns><c>true</c> if [is audio file] [the specified args]; otherwise, <c>false</c>.</returns>
public static bool IsAudioFile(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}
var extension = Path.GetExtension(path);
if (string.IsNullOrEmpty(extension))
{
return false;
}
return AudioFileExtensionsDictionary.ContainsKey(extension);
}
/// <summary>
/// Determines whether [is video file] [the specified path].
/// </summary>
/// <param name="path">The path.</param>
/// <returns><c>true</c> if [is video file] [the specified path]; otherwise, <c>false</c>.</returns>
public static bool IsVideoFile(string path)
{
return MimeTypes.IsVideoFile(path);
}
/// <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>
public 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);
}
/// <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>
public static bool IsMultiDiscAlbumFolder(string path)
{
var filename = Path.GetFileName(path);
if (string.IsNullOrWhiteSpace(filename))
{
return false;
}
// Normalize
// Remove whitespace
filename = filename.Replace("-", " ");
filename = filename.Replace(".", " ");
filename = filename.Replace("(", " ");
filename = filename.Replace(")", " ");
filename = Regex.Replace(filename, @"\s+", " ");
var prefixes = new[] { "disc", "cd", "disk", "vol", "volume" };
filename = filename.TrimStart();
foreach (var prefix in prefixes)
{
if (filename.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) == 0)
{
var tmp = filename.Substring(prefix.Length);
tmp = tmp.Trim().Split(' ').FirstOrDefault() ?? string.Empty;
int val;
if (int.TryParse(tmp, NumberStyles.Any, CultureInfo.InvariantCulture, out val))
{
return true;
}
}
}
return false;
}
/// <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;
}
}
}
}