2013-10-31 07:03:23 -07:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-07-20 07:57:48 -07:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-03-02 23:58:04 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2013-07-20 07:57:48 -07:00
|
|
|
|
using System.Text.RegularExpressions;
|
2013-03-02 23:58:04 -07:00
|
|
|
|
|
2013-03-03 09:53:58 -07:00
|
|
|
|
namespace MediaBrowser.Controller.Resolvers
|
2013-03-02 23:58:04 -07: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 07:18:17 -07:00
|
|
|
|
{
|
2013-03-02 23:58:04 -07:00
|
|
|
|
".mkv",
|
|
|
|
|
".m2t",
|
|
|
|
|
".m2ts",
|
|
|
|
|
".img",
|
|
|
|
|
".iso",
|
2013-07-25 12:17:44 -07:00
|
|
|
|
".mk3d",
|
2013-03-02 23:58:04 -07:00
|
|
|
|
".ts",
|
|
|
|
|
".rmvb",
|
|
|
|
|
".mov",
|
|
|
|
|
".avi",
|
|
|
|
|
".mpg",
|
|
|
|
|
".mpeg",
|
|
|
|
|
".wmv",
|
|
|
|
|
".mp4",
|
|
|
|
|
".divx",
|
|
|
|
|
".dvr-ms",
|
|
|
|
|
".wtv",
|
|
|
|
|
".ogm",
|
|
|
|
|
".ogv",
|
|
|
|
|
".asf",
|
|
|
|
|
".m4v",
|
|
|
|
|
".flv",
|
|
|
|
|
".f4v",
|
|
|
|
|
".3gp",
|
2013-06-10 11:37:52 -07:00
|
|
|
|
".webm",
|
2013-10-27 14:09:22 -07:00
|
|
|
|
".mts",
|
2013-12-05 20:39:44 -07:00
|
|
|
|
".m2v",
|
2013-10-27 14:09:22 -07:00
|
|
|
|
".rec"
|
2013-03-02 23:58:04 -07:00
|
|
|
|
};
|
|
|
|
|
|
2013-07-20 07:57:48 -07:00
|
|
|
|
private static readonly Dictionary<string, string> VideoFileExtensionsDictionary = VideoFileExtensions.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
2013-06-12 14:46:50 -07:00
|
|
|
|
private static readonly Regex MultiFileRegex = new Regex(
|
|
|
|
|
@"(.*?)([ _.-]*(?:cd|dvd|p(?:ar)?t|dis[ck]|d)[ _.-]*[0-9]+)(.*?)(\.[^.]+)$",
|
2013-06-16 12:02:57 -07: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 14:46:50 -07: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)
|
|
|
|
|
{
|
2014-01-02 14:21:47 -07:00
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("path");
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 12:02:57 -07:00
|
|
|
|
return MultiFileRegex.Match(path).Success || MultiFolderRegex.Match(path).Success;
|
2013-06-12 14:46:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-28 07:18:17 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The audio file extensions
|
|
|
|
|
/// </summary>
|
2014-02-12 22:11:54 -07:00
|
|
|
|
public static readonly string[] AudioFileExtensions =
|
|
|
|
|
{
|
|
|
|
|
".mp3",
|
|
|
|
|
".flac",
|
|
|
|
|
".wma",
|
|
|
|
|
".aac",
|
|
|
|
|
".acc",
|
|
|
|
|
".m4a",
|
|
|
|
|
".m4b",
|
|
|
|
|
".wav",
|
|
|
|
|
".ape",
|
|
|
|
|
".ogg",
|
|
|
|
|
".oga"
|
2013-08-07 08:59:13 -07:00
|
|
|
|
|
2014-02-12 22:11:54 -07:00
|
|
|
|
};
|
2013-07-20 07:57:48 -07:00
|
|
|
|
|
2013-08-07 08:59:13 -07:00
|
|
|
|
private static readonly Dictionary<string, string> AudioFileExtensionsDictionary = AudioFileExtensions.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
2013-04-28 07:18:17 -07:00
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2014-01-02 14:21:47 -07:00
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("path");
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-20 07:57:48 -07:00
|
|
|
|
var extension = Path.GetExtension(path);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(extension))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 08:59:13 -07:00
|
|
|
|
return AudioFileExtensionsDictionary.ContainsKey(extension);
|
2013-04-28 07:18:17 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-02 23:58:04 -07: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)
|
|
|
|
|
{
|
2014-01-02 14:21:47 -07:00
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("path");
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-20 07:57:48 -07:00
|
|
|
|
var extension = Path.GetExtension(path);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(extension))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return VideoFileExtensionsDictionary.ContainsKey(extension);
|
2013-03-02 23:58:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ensures DateCreated and DateModified have values
|
|
|
|
|
/// </summary>
|
2013-10-30 07:40:14 -07:00
|
|
|
|
/// <param name="fileSystem">The file system.</param>
|
2013-03-02 23:58:04 -07:00
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="args">The args.</param>
|
2013-08-14 05:17:45 -07:00
|
|
|
|
/// <param name="includeCreationTime">if set to <c>true</c> [include creation time].</param>
|
2013-10-30 07:40:14 -07:00
|
|
|
|
public static void EnsureDates(IFileSystem fileSystem, BaseItem item, ItemResolveArgs args, bool includeCreationTime)
|
2013-03-02 23:58:04 -07:00
|
|
|
|
{
|
2013-12-20 13:17:54 -07:00
|
|
|
|
if (fileSystem == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("fileSystem");
|
|
|
|
|
}
|
|
|
|
|
if (item == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("item");
|
|
|
|
|
}
|
|
|
|
|
if (args == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("args");
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-02 23:58:04 -07:00
|
|
|
|
// See if a different path came out of the resolver than what went in
|
2013-06-11 13:35:54 -07:00
|
|
|
|
if (!string.Equals(args.Path, item.Path, StringComparison.OrdinalIgnoreCase))
|
2013-03-02 23:58:04 -07:00
|
|
|
|
{
|
|
|
|
|
var childData = args.IsDirectory ? args.GetFileSystemEntryByPath(item.Path) : null;
|
|
|
|
|
|
2013-04-27 22:29:27 -07:00
|
|
|
|
if (childData != null)
|
2013-03-02 23:58:04 -07:00
|
|
|
|
{
|
2013-08-14 05:17:45 -07:00
|
|
|
|
if (includeCreationTime)
|
|
|
|
|
{
|
2013-10-30 16:15:58 -07:00
|
|
|
|
item.DateCreated = fileSystem.GetCreationTimeUtc(childData);
|
2013-08-14 05:17:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-31 07:03:23 -07:00
|
|
|
|
item.DateModified = fileSystem.GetLastWriteTimeUtc(childData);
|
2013-03-02 23:58:04 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-10-30 07:40:14 -07:00
|
|
|
|
var fileData = fileSystem.GetFileSystemInfo(item.Path);
|
2013-03-02 23:58:04 -07:00
|
|
|
|
|
2013-04-27 22:29:27 -07:00
|
|
|
|
if (fileData.Exists)
|
2013-03-02 23:58:04 -07:00
|
|
|
|
{
|
2013-08-14 05:17:45 -07:00
|
|
|
|
if (includeCreationTime)
|
|
|
|
|
{
|
2013-10-30 16:15:58 -07:00
|
|
|
|
item.DateCreated = fileSystem.GetCreationTimeUtc(fileData);
|
2013-08-14 05:17:45 -07:00
|
|
|
|
}
|
2013-10-31 07:03:23 -07:00
|
|
|
|
item.DateModified = fileSystem.GetLastWriteTimeUtc(fileData);
|
2013-03-02 23:58:04 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-08-14 05:17:45 -07:00
|
|
|
|
if (includeCreationTime)
|
|
|
|
|
{
|
2013-10-30 16:15:58 -07:00
|
|
|
|
item.DateCreated = fileSystem.GetCreationTimeUtc(args.FileInfo);
|
2013-08-14 05:17:45 -07:00
|
|
|
|
}
|
2013-10-31 07:03:23 -07:00
|
|
|
|
item.DateModified = fileSystem.GetLastWriteTimeUtc(args.FileInfo);
|
2013-03-02 23:58:04 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|