2021-05-20 21:28:18 +02:00
|
|
|
#nullable disable
|
|
|
|
|
2019-01-13 20:21:32 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2019-04-18 23:47:19 +02:00
|
|
|
using System.Text.RegularExpressions;
|
2021-11-15 15:56:02 +01:00
|
|
|
using Emby.Naming.Common;
|
2019-01-13 20:21:32 +01:00
|
|
|
using Emby.Naming.Video;
|
2021-06-19 18:02:33 +02:00
|
|
|
using Jellyfin.Extensions;
|
2019-01-13 20:21:32 +01:00
|
|
|
using MediaBrowser.Controller.Drawing;
|
2019-01-06 21:50:43 +01:00
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-02-21 02:33:05 +01:00
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
2015-01-10 06:53:35 +01:00
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-02-21 02:33:05 +01:00
|
|
|
using MediaBrowser.Controller.Library;
|
2014-02-13 06:11:54 +01:00
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-03-03 17:53:58 +01:00
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2013-02-21 02:33:05 +01:00
|
|
|
using MediaBrowser.Model.Entities;
|
2016-10-25 21:02:04 +02:00
|
|
|
using MediaBrowser.Model.IO;
|
2022-01-04 22:52:52 +01:00
|
|
|
using Microsoft.Extensions.Logging;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
2016-11-03 07:37:52 +01:00
|
|
|
namespace Emby.Server.Implementations.Library.Resolvers.Movies
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
|
|
|
/// <summary>
|
2019-11-01 18:38:54 +01:00
|
|
|
/// Class MovieResolver.
|
2013-02-21 02:33:05 +01:00
|
|
|
/// </summary>
|
2014-12-04 06:24:41 +01:00
|
|
|
public class MovieResolver : BaseVideoResolver<Video>, IMultiItemResolver
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2021-10-02 19:59:58 +02:00
|
|
|
private readonly IImageProcessor _imageProcessor;
|
|
|
|
|
2020-01-22 22:18:56 +01:00
|
|
|
private string[] _validCollectionTypes = new[]
|
|
|
|
{
|
|
|
|
CollectionType.Movies,
|
|
|
|
CollectionType.HomeVideos,
|
|
|
|
CollectionType.MusicVideos,
|
2022-02-04 20:44:38 +01:00
|
|
|
CollectionType.TvShows,
|
2020-01-22 22:18:56 +01:00
|
|
|
CollectionType.Photos
|
|
|
|
};
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="MovieResolver"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="imageProcessor">The image processor.</param>
|
2022-01-04 22:52:52 +01:00
|
|
|
/// <param name="logger">The logger.</param>
|
2021-11-15 15:56:02 +01:00
|
|
|
/// <param name="namingOptions">The naming options.</param>
|
2022-01-04 22:52:52 +01:00
|
|
|
public MovieResolver(IImageProcessor imageProcessor, ILogger<MovieResolver> logger, NamingOptions namingOptions)
|
|
|
|
: base(logger, namingOptions)
|
2020-01-22 22:18:56 +01:00
|
|
|
{
|
|
|
|
_imageProcessor = imageProcessor;
|
|
|
|
}
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the priority.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The priority.</value>
|
2021-01-06 19:26:40 +01:00
|
|
|
public override ResolverPriority Priority => ResolverPriority.Fourth;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
2019-11-01 18:38:54 +01:00
|
|
|
/// <inheritdoc />
|
2019-07-06 16:15:38 +02:00
|
|
|
public MultiItemResolverResult ResolveMultiple(
|
|
|
|
Folder parent,
|
2015-10-04 05:38:46 +02:00
|
|
|
List<FileSystemMetadata> files,
|
2014-12-04 06:24:41 +01:00
|
|
|
string collectionType,
|
|
|
|
IDirectoryService directoryService)
|
2015-07-23 07:26:21 +02:00
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
var result = ResolveMultipleInternal(parent, files, collectionType);
|
2015-07-23 07:26:21 +02:00
|
|
|
|
|
|
|
if (result != null)
|
|
|
|
{
|
|
|
|
foreach (var item in result.Items)
|
|
|
|
{
|
|
|
|
SetInitialItemValues((Video)item, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-03-14 19:56:45 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Resolves the specified args.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
/// <returns>Video.</returns>
|
|
|
|
public override Video Resolve(ItemResolveArgs args)
|
|
|
|
{
|
|
|
|
var collectionType = args.GetCollectionType();
|
|
|
|
|
|
|
|
// Find movies with their own folders
|
|
|
|
if (args.IsDirectory)
|
|
|
|
{
|
|
|
|
if (IsInvalid(args.Parent, collectionType))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
Video movie = null;
|
2021-11-15 15:56:02 +01:00
|
|
|
var files = args.GetActualFileSystemChildren().ToList();
|
2021-03-14 19:56:45 +01:00
|
|
|
|
|
|
|
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
movie = FindMovie<MusicVideo>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, false);
|
2021-03-14 19:56:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
movie = FindMovie<Video>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, false);
|
2021-03-14 19:56:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(collectionType))
|
|
|
|
{
|
2021-12-22 22:37:49 +01:00
|
|
|
// Owned items will be caught by the video extra resolver
|
2021-03-14 19:56:45 +01:00
|
|
|
if (args.Parent == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.HasParent<Series>())
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
movie = FindMovie<Movie>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, true);
|
2021-03-14 19:56:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
movie = FindMovie<Movie>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, true);
|
2021-03-14 19:56:45 +01:00
|
|
|
}
|
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
// ignore extras
|
|
|
|
return movie?.ExtraType == null ? movie : null;
|
2021-03-14 19:56:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (args.Parent == null)
|
|
|
|
{
|
2022-01-16 22:59:14 +01:00
|
|
|
return base.Resolve(args);
|
2021-03-14 19:56:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsInvalid(args.Parent, collectionType))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Video item = null;
|
|
|
|
|
|
|
|
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
item = ResolveVideo<MusicVideo>(args, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// To find a movie file, the collection type must be movies or boxsets
|
|
|
|
else if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
item = ResolveVideo<Movie>(args, true);
|
|
|
|
}
|
|
|
|
else if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
item = ResolveVideo<Video>(args, false);
|
|
|
|
}
|
|
|
|
else if (string.IsNullOrEmpty(collectionType))
|
|
|
|
{
|
|
|
|
if (args.HasParent<Series>())
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = ResolveVideo<Video>(args, false);
|
|
|
|
}
|
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
// Ignore extras
|
|
|
|
if (item?.ExtraType != null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-03-14 19:56:45 +01:00
|
|
|
if (item != null)
|
|
|
|
{
|
|
|
|
item.IsInMixedFolder = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2019-07-06 16:15:38 +02:00
|
|
|
private MultiItemResolverResult ResolveMultipleInternal(
|
|
|
|
Folder parent,
|
2015-10-04 05:38:46 +02:00
|
|
|
List<FileSystemMetadata> files,
|
2021-12-07 15:18:17 +01:00
|
|
|
string collectionType)
|
2014-12-04 06:24:41 +01:00
|
|
|
{
|
2015-11-05 00:49:06 +01:00
|
|
|
if (IsInvalid(parent, collectionType))
|
2014-12-04 06:24:41 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
return ResolveVideos<MusicVideo>(parent, files, true, collectionType, false);
|
2014-12-04 06:24:41 +01:00
|
|
|
}
|
|
|
|
|
2016-01-26 19:36:56 +01:00
|
|
|
if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) ||
|
2016-02-25 16:12:22 +01:00
|
|
|
string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase))
|
2014-12-04 06:24:41 +01:00
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
return ResolveVideos<Video>(parent, files, false, collectionType, false);
|
2014-12-04 06:24:41 +01:00
|
|
|
}
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
if (string.IsNullOrEmpty(collectionType))
|
2014-12-04 06:24:41 +01:00
|
|
|
{
|
|
|
|
// Owned items should just use the plain video type
|
|
|
|
if (parent == null)
|
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
return ResolveVideos<Video>(parent, files, false, collectionType, false);
|
2014-12-04 06:24:41 +01:00
|
|
|
}
|
|
|
|
|
2015-11-11 15:56:31 +01:00
|
|
|
if (parent is Series || parent.GetParents().OfType<Series>().Any())
|
2015-01-10 06:53:35 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
return ResolveVideos<Movie>(parent, files, false, collectionType, true);
|
2014-12-04 06:24:41 +01:00
|
|
|
}
|
|
|
|
|
2014-12-19 05:20:07 +01:00
|
|
|
if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
2014-12-04 06:24:41 +01:00
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
return ResolveVideos<Movie>(parent, files, true, collectionType, true);
|
2014-12-04 06:24:41 +01:00
|
|
|
}
|
|
|
|
|
2022-02-04 20:44:38 +01:00
|
|
|
if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
2022-06-12 15:54:32 +02:00
|
|
|
return ResolveVideos<Episode>(parent, files, false, collectionType, true);
|
2022-02-04 20:44:38 +01:00
|
|
|
}
|
|
|
|
|
2014-12-04 06:24:41 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-07-06 16:15:38 +02:00
|
|
|
private MultiItemResolverResult ResolveVideos<T>(
|
|
|
|
Folder parent,
|
|
|
|
IEnumerable<FileSystemMetadata> fileSystemEntries,
|
2021-12-07 15:18:17 +01:00
|
|
|
bool supportMultiEditions,
|
2019-07-06 16:15:38 +02:00
|
|
|
string collectionType,
|
|
|
|
bool parseName)
|
2014-12-04 06:24:41 +01:00
|
|
|
where T : Video, new()
|
|
|
|
{
|
2015-10-04 05:38:46 +02:00
|
|
|
var files = new List<FileSystemMetadata>();
|
|
|
|
var leftOver = new List<FileSystemMetadata>();
|
2021-12-07 15:18:17 +01:00
|
|
|
var hasCollectionType = !string.IsNullOrEmpty(collectionType);
|
2014-12-04 06:24:41 +01:00
|
|
|
|
|
|
|
// Loop through each child file/folder and see if we find a video
|
|
|
|
foreach (var child in fileSystemEntries)
|
|
|
|
{
|
2016-12-23 00:53:57 +01:00
|
|
|
// This is a hack but currently no better way to resolve a sometimes ambiguous situation
|
2021-12-07 15:18:17 +01:00
|
|
|
if (!hasCollectionType)
|
2016-12-23 00:53:57 +01:00
|
|
|
{
|
2019-07-06 16:15:38 +02:00
|
|
|
if (string.Equals(child.Name, "tvshow.nfo", StringComparison.OrdinalIgnoreCase)
|
|
|
|
|| string.Equals(child.Name, "season.nfo", StringComparison.OrdinalIgnoreCase))
|
2016-12-23 00:53:57 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-25 21:02:04 +02:00
|
|
|
if (child.IsDirectory)
|
2014-12-04 06:24:41 +01:00
|
|
|
{
|
|
|
|
leftOver.Add(child);
|
2018-09-12 19:26:21 +02:00
|
|
|
}
|
2019-07-06 16:15:38 +02:00
|
|
|
else if (!IsIgnored(child.Name))
|
2014-12-04 06:24:41 +01:00
|
|
|
{
|
|
|
|
files.Add(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 12:15:20 +01:00
|
|
|
var videoInfos = files
|
|
|
|
.Select(i => VideoResolver.Resolve(i.FullName, i.IsDirectory, NamingOptions, parseName))
|
|
|
|
.Where(f => f != null)
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
var resolverResult = VideoListResolver.Resolve(videoInfos, NamingOptions, supportMultiEditions, parseName);
|
2014-12-04 06:24:41 +01:00
|
|
|
|
|
|
|
var result = new MultiItemResolverResult
|
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
ExtraFiles = leftOver
|
2014-12-04 06:24:41 +01:00
|
|
|
};
|
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
var isInMixedFolder = resolverResult.Count > 1 || parent?.IsTopParent == true;
|
2014-12-09 05:57:18 +01:00
|
|
|
|
2014-12-04 06:24:41 +01:00
|
|
|
foreach (var video in resolverResult)
|
|
|
|
{
|
2020-01-22 22:18:56 +01:00
|
|
|
var firstVideo = video.Files[0];
|
2021-12-07 15:18:17 +01:00
|
|
|
var path = firstVideo.Path;
|
|
|
|
if (video.ExtraType != null)
|
|
|
|
{
|
2021-12-07 19:23:30 +01:00
|
|
|
result.ExtraFiles.Add(files.Find(f => string.Equals(f.FullName, path, StringComparison.OrdinalIgnoreCase)));
|
2021-12-07 15:18:17 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var additionalParts = video.Files.Count > 1 ? video.Files.Skip(1).Select(i => i.Path).ToArray() : Array.Empty<string>();
|
2014-12-04 06:24:41 +01:00
|
|
|
|
|
|
|
var videoItem = new T
|
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
Path = path,
|
2014-12-09 05:57:18 +01:00
|
|
|
IsInMixedFolder = isInMixedFolder,
|
2014-12-04 06:24:41 +01:00
|
|
|
ProductionYear = video.Year,
|
2021-12-07 15:18:17 +01:00
|
|
|
Name = parseName ? video.Name : firstVideo.Name,
|
|
|
|
AdditionalParts = additionalParts,
|
2017-08-10 20:01:31 +02:00
|
|
|
LocalAlternateVersions = video.AlternateVersions.Select(i => i.Path).ToArray()
|
2014-12-04 06:24:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
SetVideoType(videoItem, firstVideo);
|
|
|
|
Set3DFormat(videoItem, firstVideo);
|
|
|
|
|
|
|
|
result.Items.Add(videoItem);
|
|
|
|
}
|
|
|
|
|
2016-02-25 16:12:22 +01:00
|
|
|
result.ExtraFiles.AddRange(files.Where(i => !ContainsFile(resolverResult, i)));
|
|
|
|
|
2014-12-04 06:24:41 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-01-06 21:50:43 +01:00
|
|
|
private static bool IsIgnored(string filename)
|
2018-09-12 19:26:21 +02:00
|
|
|
{
|
|
|
|
// Ignore samples
|
2021-12-07 15:18:17 +01:00
|
|
|
Match m = Regex.Match(filename, @"\bsample\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
2018-09-12 19:26:21 +02:00
|
|
|
|
2019-04-18 23:47:19 +02:00
|
|
|
return m.Success;
|
2018-09-12 19:26:21 +02:00
|
|
|
}
|
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
private static bool ContainsFile(IReadOnlyList<VideoInfo> result, FileSystemMetadata file)
|
2016-02-25 16:12:22 +01:00
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
for (var i = 0; i < result.Count; i++)
|
|
|
|
{
|
|
|
|
var current = result[i];
|
|
|
|
for (var j = 0; j < current.Files.Count; j++)
|
|
|
|
{
|
|
|
|
if (ContainsFile(current.Files[j], file))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-02-25 16:12:22 +01:00
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
for (var j = 0; j < current.AlternateVersions.Count; j++)
|
|
|
|
{
|
|
|
|
if (ContainsFile(current.AlternateVersions[j], file))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-02-25 16:12:22 +01:00
|
|
|
}
|
|
|
|
|
2019-01-06 21:50:43 +01:00
|
|
|
private static bool ContainsFile(VideoFileInfo result, FileSystemMetadata file)
|
2016-02-25 16:12:22 +01:00
|
|
|
{
|
|
|
|
return string.Equals(result.Path, file.FullName, StringComparison.OrdinalIgnoreCase);
|
|
|
|
}
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Sets the initial item values.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
/// <param name="args">The args.</param>
|
2013-05-28 03:59:26 +02:00
|
|
|
protected override void SetInitialItemValues(Video item, ItemResolveArgs args)
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
|
|
|
base.SetInitialItemValues(item, args);
|
|
|
|
|
2015-01-02 15:29:20 +01:00
|
|
|
SetProviderIdsFromPath(item);
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Sets the provider id from path.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The item.</param>
|
2019-01-06 21:50:43 +01:00
|
|
|
private static void SetProviderIdsFromPath(Video item)
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2015-01-04 15:34:15 +01:00
|
|
|
if (item is Movie || item is MusicVideo)
|
|
|
|
{
|
2020-01-22 22:18:56 +01:00
|
|
|
// We need to only look at the name of this actual item (not parents)
|
2021-11-28 00:10:43 +01:00
|
|
|
var justName = item.IsInMixedFolder ? Path.GetFileName(item.Path.AsSpan()) : Path.GetFileName(item.ContainingFolderPath.AsSpan());
|
2013-02-21 02:33:05 +01:00
|
|
|
|
2021-11-28 00:10:43 +01:00
|
|
|
if (!justName.IsEmpty)
|
2015-01-04 15:34:15 +01:00
|
|
|
{
|
2015-09-10 05:22:52 +02:00
|
|
|
// check for tmdb id
|
|
|
|
var tmdbid = justName.GetAttributeValue("tmdbid");
|
2015-01-02 15:29:20 +01:00
|
|
|
|
2015-09-10 05:22:52 +02:00
|
|
|
if (!string.IsNullOrWhiteSpace(tmdbid))
|
|
|
|
{
|
2020-06-06 21:17:49 +02:00
|
|
|
item.SetProviderId(MetadataProvider.Tmdb, tmdbid);
|
2015-09-10 05:22:52 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-02 15:29:20 +01:00
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
if (!string.IsNullOrEmpty(item.Path))
|
2015-01-04 15:34:15 +01:00
|
|
|
{
|
2015-09-10 05:22:52 +02:00
|
|
|
// check for imdb id - we use full media path, as we can assume, that this will match in any use case (wither id in parent dir or in file name)
|
2021-11-28 00:10:43 +01:00
|
|
|
var imdbid = item.Path.AsSpan().GetAttributeValue("imdbid");
|
2015-09-10 05:22:52 +02:00
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(imdbid))
|
|
|
|
{
|
2020-06-06 21:17:49 +02:00
|
|
|
item.SetProviderId(MetadataProvider.Imdb, imdbid);
|
2015-09-10 05:22:52 +02:00
|
|
|
}
|
2015-01-04 15:34:15 +01:00
|
|
|
}
|
2015-01-02 15:29:20 +01:00
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-01-22 22:18:56 +01:00
|
|
|
/// Finds a movie based on a child file system entries.
|
2013-02-21 02:33:05 +01:00
|
|
|
/// </summary>
|
|
|
|
/// <returns>Movie.</returns>
|
2017-10-21 18:39:52 +02:00
|
|
|
private T FindMovie<T>(ItemResolveArgs args, string path, Folder parent, List<FileSystemMetadata> fileSystemEntries, IDirectoryService directoryService, string collectionType, bool parseName)
|
2013-06-16 21:02:57 +02:00
|
|
|
where T : Video, new()
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2015-10-04 05:38:46 +02:00
|
|
|
var multiDiscFolders = new List<FileSystemMetadata>();
|
2015-01-04 15:34:15 +01:00
|
|
|
|
2021-05-05 15:30:32 +02:00
|
|
|
var libraryOptions = args.LibraryOptions;
|
2017-10-21 18:39:52 +02:00
|
|
|
var supportPhotos = string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && libraryOptions.EnablePhotos;
|
|
|
|
var photos = new List<FileSystemMetadata>();
|
|
|
|
|
2014-12-04 06:24:41 +01:00
|
|
|
// Search for a folder rip
|
2013-06-16 21:02:57 +02:00
|
|
|
foreach (var child in fileSystemEntries)
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2013-06-20 04:23:07 +02:00
|
|
|
var filename = child.Name;
|
|
|
|
|
2016-10-25 21:02:04 +02:00
|
|
|
if (child.IsDirectory)
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2016-12-03 22:46:06 +01:00
|
|
|
if (IsDvdDirectory(child.FullName, filename, directoryService))
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2014-12-04 06:24:41 +01:00
|
|
|
var movie = new T
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2013-06-16 21:02:57 +02:00
|
|
|
Path = path,
|
2013-02-21 02:33:05 +01:00
|
|
|
VideoType = VideoType.Dvd
|
|
|
|
};
|
2014-12-04 06:24:41 +01:00
|
|
|
Set3DFormat(movie);
|
|
|
|
return movie;
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
2020-01-22 22:18:56 +01:00
|
|
|
|
2021-08-29 00:32:50 +02:00
|
|
|
if (IsBluRayDirectory(filename))
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2014-12-04 06:24:41 +01:00
|
|
|
var movie = new T
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2013-06-16 21:02:57 +02:00
|
|
|
Path = path,
|
2013-02-21 02:33:05 +01:00
|
|
|
VideoType = VideoType.BluRay
|
|
|
|
};
|
2014-12-04 06:24:41 +01:00
|
|
|
Set3DFormat(movie);
|
|
|
|
return movie;
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
2013-06-16 21:02:57 +02:00
|
|
|
|
2014-11-18 03:48:22 +01:00
|
|
|
multiDiscFolders.Add(child);
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
2014-12-09 05:57:18 +01:00
|
|
|
else if (IsDvdFile(filename))
|
|
|
|
{
|
|
|
|
var movie = new T
|
|
|
|
{
|
|
|
|
Path = path,
|
|
|
|
VideoType = VideoType.Dvd
|
|
|
|
};
|
|
|
|
Set3DFormat(movie);
|
|
|
|
return movie;
|
|
|
|
}
|
2018-09-12 19:26:21 +02:00
|
|
|
else if (supportPhotos && PhotoResolver.IsImageFile(child.FullName, _imageProcessor))
|
2017-10-21 18:39:52 +02:00
|
|
|
{
|
|
|
|
photos.Add(child);
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
|
|
|
|
2017-10-21 18:39:52 +02:00
|
|
|
// TODO: Allow GetMultiDiscMovie in here
|
2020-01-22 22:18:56 +01:00
|
|
|
const bool SupportsMultiVersion = true;
|
2017-10-21 18:39:52 +02:00
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
var result = ResolveVideos<T>(parent, fileSystemEntries, SupportsMultiVersion, collectionType, parseName) ??
|
2017-10-21 18:39:52 +02:00
|
|
|
new MultiItemResolverResult();
|
2014-03-15 23:52:43 +01:00
|
|
|
|
2017-10-21 18:39:52 +02:00
|
|
|
if (result.Items.Count == 1)
|
|
|
|
{
|
|
|
|
var videoPath = result.Items[0].Path;
|
2021-11-15 15:56:02 +01:00
|
|
|
var hasPhotos = photos.Any(i => !PhotoResolver.IsOwnedByResolvedMedia(videoPath, i.Name));
|
2013-06-12 23:46:50 +02:00
|
|
|
|
2017-10-21 18:39:52 +02:00
|
|
|
if (!hasPhotos)
|
2016-10-17 18:40:43 +02:00
|
|
|
{
|
|
|
|
var movie = (T)result.Items[0];
|
|
|
|
movie.IsInMixedFolder = false;
|
|
|
|
movie.Name = Path.GetFileName(movie.ContainingFolderPath);
|
|
|
|
return movie;
|
|
|
|
}
|
2017-10-21 18:39:52 +02:00
|
|
|
}
|
2020-02-19 21:56:35 +01:00
|
|
|
else if (result.Items.Count == 0 && multiDiscFolders.Count > 0)
|
2017-10-21 18:39:52 +02:00
|
|
|
{
|
|
|
|
return GetMultiDiscMovie<T>(multiDiscFolders, directoryService);
|
2013-06-16 21:02:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
|
|
|
|
2013-06-16 21:02:57 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the multi disc movie.
|
|
|
|
/// </summary>
|
2013-12-20 04:21:37 +01:00
|
|
|
/// <param name="multiDiscFolders">The folders.</param>
|
2014-11-18 03:48:22 +01:00
|
|
|
/// <param name="directoryService">The directory service.</param>
|
2013-06-16 21:02:57 +02:00
|
|
|
/// <returns>``0.</returns>
|
2015-10-04 05:38:46 +02:00
|
|
|
private T GetMultiDiscMovie<T>(List<FileSystemMetadata> multiDiscFolders, IDirectoryService directoryService)
|
2013-06-16 21:02:57 +02:00
|
|
|
where T : Video, new()
|
|
|
|
{
|
2013-12-20 04:21:37 +01:00
|
|
|
var videoTypes = new List<VideoType>();
|
2013-06-16 21:02:57 +02:00
|
|
|
|
2013-12-20 04:21:37 +01:00
|
|
|
var folderPaths = multiDiscFolders.Select(i => i.FullName).Where(i =>
|
2013-06-16 21:02:57 +02:00
|
|
|
{
|
2017-08-09 21:56:38 +02:00
|
|
|
var subFileEntries = directoryService.GetFileSystemEntries(i);
|
2014-12-09 05:57:18 +01:00
|
|
|
|
|
|
|
var subfolders = subFileEntries
|
2020-01-22 22:18:56 +01:00
|
|
|
.Where(e => e.IsDirectory)
|
2014-11-18 03:48:22 +01:00
|
|
|
.ToList();
|
2013-06-16 21:02:57 +02:00
|
|
|
|
2016-12-03 22:46:06 +01:00
|
|
|
if (subfolders.Any(s => IsDvdDirectory(s.FullName, s.Name, directoryService)))
|
2013-06-16 21:02:57 +02:00
|
|
|
{
|
2013-12-20 04:21:37 +01:00
|
|
|
videoTypes.Add(VideoType.Dvd);
|
2013-06-16 21:02:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
2020-01-22 22:18:56 +01:00
|
|
|
|
2021-08-29 00:32:50 +02:00
|
|
|
if (subfolders.Any(s => IsBluRayDirectory(s.Name)))
|
2013-06-16 21:02:57 +02:00
|
|
|
{
|
2013-12-20 04:21:37 +01:00
|
|
|
videoTypes.Add(VideoType.BluRay);
|
2013-06-16 21:02:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-09 05:57:18 +01:00
|
|
|
var subFiles = subFileEntries
|
2016-10-25 21:02:04 +02:00
|
|
|
.Where(e => !e.IsDirectory)
|
2014-12-09 05:57:18 +01:00
|
|
|
.Select(d => d.Name);
|
|
|
|
|
|
|
|
if (subFiles.Any(IsDvdFile))
|
|
|
|
{
|
|
|
|
videoTypes.Add(VideoType.Dvd);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-16 21:02:57 +02:00
|
|
|
return false;
|
2013-06-20 04:23:07 +02:00
|
|
|
}).OrderBy(i => i).ToList();
|
2013-06-16 21:02:57 +02:00
|
|
|
|
2013-12-20 04:21:37 +01:00
|
|
|
// If different video types were found, don't allow this
|
2014-11-18 03:48:22 +01:00
|
|
|
if (videoTypes.Distinct().Count() > 1)
|
2013-12-20 04:21:37 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-06-20 04:23:07 +02:00
|
|
|
if (folderPaths.Count == 0)
|
2013-06-16 21:02:57 +02:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
var result = StackResolver.ResolveDirectories(folderPaths, NamingOptions).ToList();
|
2013-12-20 04:21:37 +01:00
|
|
|
|
2020-01-22 22:18:56 +01:00
|
|
|
if (result.Count != 1)
|
2013-12-20 04:21:37 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2014-12-04 06:24:41 +01:00
|
|
|
|
2020-02-19 21:56:35 +01:00
|
|
|
int additionalPartsLen = folderPaths.Count - 1;
|
|
|
|
var additionalParts = new string[additionalPartsLen];
|
|
|
|
folderPaths.CopyTo(1, additionalParts, 0, additionalPartsLen);
|
|
|
|
|
2016-02-09 05:09:29 +01:00
|
|
|
var returnVideo = new T
|
2013-06-16 21:02:57 +02:00
|
|
|
{
|
2013-06-20 04:23:07 +02:00
|
|
|
Path = folderPaths[0],
|
2020-02-19 21:56:35 +01:00
|
|
|
AdditionalParts = additionalParts,
|
2014-11-18 03:48:22 +01:00
|
|
|
VideoType = videoTypes[0],
|
2020-01-22 22:18:56 +01:00
|
|
|
Name = result[0].Name
|
2013-06-16 21:02:57 +02:00
|
|
|
};
|
2016-02-09 05:09:29 +01:00
|
|
|
|
|
|
|
SetIsoType(returnVideo);
|
|
|
|
|
|
|
|
return returnVideo;
|
2013-06-16 21:02:57 +02:00
|
|
|
}
|
2013-06-12 23:46:50 +02:00
|
|
|
|
2021-05-24 00:30:41 +02:00
|
|
|
private bool IsInvalid(Folder parent, ReadOnlySpan<char> collectionType)
|
2014-03-15 23:52:43 +01:00
|
|
|
{
|
2014-12-04 06:24:41 +01:00
|
|
|
if (parent != null)
|
2014-03-15 23:52:43 +01:00
|
|
|
{
|
2014-12-04 06:24:41 +01:00
|
|
|
if (parent.IsRoot)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2014-03-15 23:52:43 +01:00
|
|
|
}
|
|
|
|
|
2021-05-24 00:30:41 +02:00
|
|
|
if (collectionType.IsEmpty)
|
2015-10-18 19:35:36 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-24 00:30:41 +02:00
|
|
|
return !_validCollectionTypes.Contains(collectionType, StringComparison.OrdinalIgnoreCase);
|
2017-08-09 21:56:38 +02:00
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
2015-09-20 19:36:09 +02:00
|
|
|
}
|