2013-06-12 21:46:50 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-03-03 06:58:04 +00:00
|
|
|
|
using MediaBrowser.Controller.IO;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2013-03-03 16:53:58 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-03-03 06:58:04 +00:00
|
|
|
|
|
2013-03-03 16:53:58 +00:00
|
|
|
|
namespace MediaBrowser.Controller.Resolvers
|
2013-03-03 06:58:04 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class EntityResolutionHelper
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class EntityResolutionHelper
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Any extension in this list is considered a video file - can be added to at runtime for extensibility
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<string> VideoFileExtensions = new List<string>
|
2013-04-28 14:18:17 +00:00
|
|
|
|
{
|
2013-03-03 06:58:04 +00:00
|
|
|
|
".mkv",
|
|
|
|
|
".m2t",
|
|
|
|
|
".m2ts",
|
|
|
|
|
".img",
|
|
|
|
|
".iso",
|
|
|
|
|
".ts",
|
|
|
|
|
".rmvb",
|
|
|
|
|
".mov",
|
|
|
|
|
".avi",
|
|
|
|
|
".mpg",
|
|
|
|
|
".mpeg",
|
|
|
|
|
".wmv",
|
|
|
|
|
".mp4",
|
|
|
|
|
".divx",
|
|
|
|
|
".dvr-ms",
|
|
|
|
|
".wtv",
|
|
|
|
|
".ogm",
|
|
|
|
|
".ogv",
|
|
|
|
|
".asf",
|
|
|
|
|
".m4v",
|
|
|
|
|
".flv",
|
|
|
|
|
".f4v",
|
|
|
|
|
".3gp",
|
2013-06-10 18:37:52 +00:00
|
|
|
|
".webm",
|
|
|
|
|
".mts"
|
2013-03-03 06:58:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-06-12 21:46:50 +00:00
|
|
|
|
private static readonly Regex MultiFileRegex = new Regex(
|
|
|
|
|
@"(.*?)([ _.-]*(?:cd|dvd|p(?:ar)?t|dis[ck]|d)[ _.-]*[0-9]+)(.*?)(\.[^.]+)$",
|
2013-06-16 19:02:57 +00:00
|
|
|
|
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);
|
2013-06-12 21:46:50 +00:00
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2013-06-16 19:02:57 +00:00
|
|
|
|
return MultiFileRegex.Match(path).Success || MultiFolderRegex.Match(path).Success;
|
2013-06-12 21:46:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-28 14:18:17 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The audio file extensions
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static readonly string[] AudioFileExtensions = new[] {
|
|
|
|
|
".mp3",
|
|
|
|
|
".flac",
|
|
|
|
|
".wma",
|
|
|
|
|
".aac",
|
|
|
|
|
".acc",
|
|
|
|
|
".m4a",
|
|
|
|
|
".m4b",
|
|
|
|
|
".wav",
|
|
|
|
|
".ape",
|
|
|
|
|
".ogg",
|
|
|
|
|
".oga"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
|
|
|
|
return AudioFileExtensions.Contains(Path.GetExtension(path), StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-03 06:58:04 +00:00
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2013-04-28 14:18:17 +00:00
|
|
|
|
var extension = Path.GetExtension(path) ?? String.Empty;
|
2013-03-03 06:58:04 +00:00
|
|
|
|
return VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ensures DateCreated and DateModified have values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
|
public static void EnsureDates(BaseItem item, ItemResolveArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (!Path.IsPathRooted(item.Path))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// See if a different path came out of the resolver than what went in
|
2013-06-11 20:35:54 +00:00
|
|
|
|
if (!string.Equals(args.Path, item.Path, StringComparison.OrdinalIgnoreCase))
|
2013-03-03 06:58:04 +00:00
|
|
|
|
{
|
|
|
|
|
var childData = args.IsDirectory ? args.GetFileSystemEntryByPath(item.Path) : null;
|
|
|
|
|
|
2013-04-28 05:29:27 +00:00
|
|
|
|
if (childData != null)
|
2013-03-03 06:58:04 +00:00
|
|
|
|
{
|
2013-04-28 05:29:27 +00:00
|
|
|
|
item.DateCreated = childData.CreationTimeUtc;
|
|
|
|
|
item.DateModified = childData.LastWriteTimeUtc;
|
2013-03-03 06:58:04 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-04-28 05:29:27 +00:00
|
|
|
|
var fileData = FileSystem.GetFileSystemInfo(item.Path);
|
2013-03-03 06:58:04 +00:00
|
|
|
|
|
2013-04-28 05:29:27 +00:00
|
|
|
|
if (fileData.Exists)
|
2013-03-03 06:58:04 +00:00
|
|
|
|
{
|
2013-04-28 05:29:27 +00:00
|
|
|
|
item.DateCreated = fileData.CreationTimeUtc;
|
|
|
|
|
item.DateModified = fileData.LastWriteTimeUtc;
|
2013-03-03 06:58:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
item.DateCreated = args.FileInfo.CreationTimeUtc;
|
|
|
|
|
item.DateModified = args.FileInfo.LastWriteTimeUtc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|