2013-03-03 06:58:04 +00:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-10-30 14:40:14 +00:00
|
|
|
|
using MediaBrowser.Controller.IO;
|
2013-03-03 06:58:04 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-06-09 13:31:23 +00:00
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
|
|
|
|
using System;
|
2013-03-03 06:58:04 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Library
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class ResolverHelper
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class ResolverHelper
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the initial item values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="args">The args.</param>
|
2013-10-30 14:40:14 +00:00
|
|
|
|
/// <param name="fileSystem">The file system.</param>
|
|
|
|
|
public static void SetInitialItemValues(BaseItem item, ItemResolveArgs args, IFileSystem fileSystem)
|
2013-03-03 06:58:04 +00:00
|
|
|
|
{
|
2013-09-25 18:05:21 +00:00
|
|
|
|
item.ResetResolveArgs(args);
|
2013-03-03 06:58:04 +00:00
|
|
|
|
|
|
|
|
|
// If the resolver didn't specify this
|
|
|
|
|
if (string.IsNullOrEmpty(item.Path))
|
|
|
|
|
{
|
|
|
|
|
item.Path = args.Path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the resolver didn't specify this
|
|
|
|
|
if (args.Parent != null)
|
|
|
|
|
{
|
|
|
|
|
item.Parent = args.Parent;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-18 15:23:28 +00:00
|
|
|
|
item.Id = item.Path.GetMBId(item.GetType());
|
2013-06-25 18:10:39 +00:00
|
|
|
|
|
|
|
|
|
// If the resolver didn't specify this
|
|
|
|
|
if (string.IsNullOrEmpty(item.DisplayMediaType))
|
|
|
|
|
{
|
|
|
|
|
item.DisplayMediaType = item.GetType().Name;
|
|
|
|
|
}
|
2013-03-03 06:58:04 +00:00
|
|
|
|
|
|
|
|
|
// Make sure the item has a name
|
|
|
|
|
EnsureName(item);
|
|
|
|
|
|
2013-06-09 13:31:23 +00:00
|
|
|
|
item.DontFetchMeta = item.Path.IndexOf("[dontfetchmeta]", StringComparison.OrdinalIgnoreCase) != -1;
|
|
|
|
|
|
2013-03-03 06:58:04 +00:00
|
|
|
|
// Make sure DateCreated and DateModified have values
|
2013-10-30 14:40:14 +00:00
|
|
|
|
EntityResolutionHelper.EnsureDates(fileSystem, item, args, true);
|
2013-03-03 06:58:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ensures the name.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
private static void EnsureName(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
// If the subclass didn't supply a name, add it here
|
|
|
|
|
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
|
2013-06-11 20:35:54 +00:00
|
|
|
|
item.Name = GetMBName(item.ResolveArgs.FileInfo.Name, (item.ResolveArgs.FileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory);
|
2013-03-03 06:58:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The MB name regex
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static readonly Regex MBNameRegex = new Regex("(\\[.*\\])", RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Strip out attribute items and return just the name we will use for items
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
|
|
|
|
//first just get the file or directory name
|
|
|
|
|
var fn = isDirectory ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path);
|
|
|
|
|
|
|
|
|
|
//now - strip out anything inside brackets
|
|
|
|
|
fn = MBNameRegex.Replace(fn, string.Empty);
|
|
|
|
|
|
|
|
|
|
return fn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|