| | | 1 | | #nullable disable |
| | | 2 | | |
| | | 3 | | using System; |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | using System.IO; |
| | | 6 | | using System.Linq; |
| | | 7 | | using System.Text.RegularExpressions; |
| | | 8 | | using Emby.Naming.Common; |
| | | 9 | | using Emby.Naming.Video; |
| | | 10 | | using Jellyfin.Data.Enums; |
| | | 11 | | using Jellyfin.Extensions; |
| | | 12 | | using MediaBrowser.Controller.Drawing; |
| | | 13 | | using MediaBrowser.Controller.Entities; |
| | | 14 | | using MediaBrowser.Controller.Entities.Movies; |
| | | 15 | | using MediaBrowser.Controller.Entities.TV; |
| | | 16 | | using MediaBrowser.Controller.Library; |
| | | 17 | | using MediaBrowser.Controller.Providers; |
| | | 18 | | using MediaBrowser.Controller.Resolvers; |
| | | 19 | | using MediaBrowser.Model.Entities; |
| | | 20 | | using MediaBrowser.Model.IO; |
| | | 21 | | using Microsoft.Extensions.Logging; |
| | | 22 | | |
| | | 23 | | namespace Emby.Server.Implementations.Library.Resolvers.Movies |
| | | 24 | | { |
| | | 25 | | /// <summary> |
| | | 26 | | /// Class MovieResolver. |
| | | 27 | | /// </summary> |
| | | 28 | | public partial class MovieResolver : BaseVideoResolver<Video>, IMultiItemResolver |
| | | 29 | | { |
| | | 30 | | private readonly IImageProcessor _imageProcessor; |
| | | 31 | | private readonly VideoListResolver _videoListResolver; |
| | | 32 | | |
| | 1 | 33 | | private static readonly CollectionType[] _validCollectionTypes = |
| | 1 | 34 | | [ |
| | 1 | 35 | | CollectionType.movies, |
| | 1 | 36 | | CollectionType.homevideos, |
| | 1 | 37 | | CollectionType.musicvideos, |
| | 1 | 38 | | CollectionType.tvshows, |
| | 1 | 39 | | CollectionType.photos |
| | 1 | 40 | | ]; |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Initializes a new instance of the <see cref="MovieResolver"/> class. |
| | | 44 | | /// </summary> |
| | | 45 | | /// <param name="imageProcessor">The image processor.</param> |
| | | 46 | | /// <param name="logger">The logger.</param> |
| | | 47 | | /// <param name="namingOptions">The naming options.</param> |
| | | 48 | | /// <param name="directoryService">The directory service.</param> |
| | | 49 | | /// <param name="videoListResolver">The video list resolver.</param> |
| | | 50 | | public MovieResolver(IImageProcessor imageProcessor, ILogger<MovieResolver> logger, NamingOptions namingOptions, |
| | 24 | 51 | | : base(logger, namingOptions, directoryService) |
| | | 52 | | { |
| | 24 | 53 | | _imageProcessor = imageProcessor; |
| | 24 | 54 | | _videoListResolver = videoListResolver; |
| | 24 | 55 | | } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Gets the priority. |
| | | 59 | | /// </summary> |
| | | 60 | | /// <value>The priority.</value> |
| | 21 | 61 | | public override ResolverPriority Priority => ResolverPriority.Fourth; |
| | | 62 | | |
| | | 63 | | [GeneratedRegex(@"\bsample\b", RegexOptions.IgnoreCase)] |
| | | 64 | | private static partial Regex IsIgnoredRegex(); |
| | | 65 | | |
| | | 66 | | /// <inheritdoc /> |
| | | 67 | | public MultiItemResolverResult ResolveMultiple( |
| | | 68 | | Folder parent, |
| | | 69 | | List<FileSystemMetadata> files, |
| | | 70 | | CollectionType? collectionType, |
| | | 71 | | IDirectoryService directoryService) |
| | | 72 | | { |
| | 60 | 73 | | var result = ResolveMultipleInternal(parent, files, collectionType); |
| | | 74 | | |
| | 60 | 75 | | if (result is not null) |
| | | 76 | | { |
| | 10 | 77 | | foreach (var item in result.Items) |
| | | 78 | | { |
| | 3 | 79 | | SetInitialItemValues((Video)item, null); |
| | | 80 | | } |
| | | 81 | | } |
| | | 82 | | |
| | 60 | 83 | | return result; |
| | | 84 | | } |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// Resolves the specified args. |
| | | 88 | | /// </summary> |
| | | 89 | | /// <param name="args">The args.</param> |
| | | 90 | | /// <returns>Video.</returns> |
| | | 91 | | protected override Video Resolve(ItemResolveArgs args) |
| | | 92 | | { |
| | 12 | 93 | | var collectionType = args.GetCollectionType(); |
| | | 94 | | |
| | | 95 | | // Find movies with their own folders |
| | 12 | 96 | | if (args.IsDirectory) |
| | | 97 | | { |
| | 0 | 98 | | if (IsInvalid(args.Parent, collectionType)) |
| | | 99 | | { |
| | 0 | 100 | | return null; |
| | | 101 | | } |
| | | 102 | | |
| | 0 | 103 | | Video movie = null; |
| | 0 | 104 | | var files = args.GetActualFileSystemChildren().ToList(); |
| | | 105 | | |
| | 0 | 106 | | if (collectionType == CollectionType.musicvideos) |
| | | 107 | | { |
| | 0 | 108 | | movie = FindMovie<MusicVideo>(args, args.Path, args.Parent, files, DirectoryService, collectionType, |
| | | 109 | | } |
| | | 110 | | |
| | 0 | 111 | | if (collectionType == CollectionType.homevideos) |
| | | 112 | | { |
| | 0 | 113 | | movie = FindMovie<Video>(args, args.Path, args.Parent, files, DirectoryService, collectionType, fals |
| | | 114 | | } |
| | | 115 | | |
| | 0 | 116 | | if (collectionType is null) |
| | | 117 | | { |
| | | 118 | | // Owned items will be caught by the video extra resolver |
| | 0 | 119 | | if (args.Parent is null) |
| | | 120 | | { |
| | 0 | 121 | | return null; |
| | | 122 | | } |
| | | 123 | | |
| | 0 | 124 | | if (args.HasParent<Series>()) |
| | | 125 | | { |
| | 0 | 126 | | return null; |
| | | 127 | | } |
| | | 128 | | |
| | 0 | 129 | | movie = FindMovie<Movie>(args, args.Path, args.Parent, files, DirectoryService, collectionType, true |
| | | 130 | | } |
| | | 131 | | |
| | 0 | 132 | | if (collectionType == CollectionType.movies) |
| | | 133 | | { |
| | 0 | 134 | | movie = FindMovie<Movie>(args, args.Path, args.Parent, files, DirectoryService, collectionType, true |
| | | 135 | | } |
| | | 136 | | |
| | | 137 | | // ignore extras |
| | 0 | 138 | | return movie?.ExtraType is null ? movie : null; |
| | | 139 | | } |
| | | 140 | | |
| | 12 | 141 | | if (args.Parent is null) |
| | | 142 | | { |
| | 1 | 143 | | return base.Resolve(args); |
| | | 144 | | } |
| | | 145 | | |
| | 11 | 146 | | if (IsInvalid(args.Parent, collectionType)) |
| | | 147 | | { |
| | 11 | 148 | | return null; |
| | | 149 | | } |
| | | 150 | | |
| | 0 | 151 | | Video item = null; |
| | | 152 | | |
| | 0 | 153 | | if (collectionType == CollectionType.musicvideos) |
| | | 154 | | { |
| | 0 | 155 | | item = ResolveVideo<MusicVideo>(args, false); |
| | | 156 | | } |
| | | 157 | | |
| | | 158 | | // To find a movie file, the collection type must be movies or boxsets |
| | 0 | 159 | | else if (collectionType == CollectionType.movies) |
| | | 160 | | { |
| | 0 | 161 | | item = ResolveVideo<Movie>(args, true); |
| | | 162 | | } |
| | 0 | 163 | | else if (collectionType == CollectionType.homevideos || collectionType == CollectionType.photos) |
| | | 164 | | { |
| | 0 | 165 | | item = ResolveVideo<Video>(args, false); |
| | | 166 | | } |
| | 0 | 167 | | else if (collectionType is null) |
| | | 168 | | { |
| | 0 | 169 | | if (args.HasParent<Series>()) |
| | | 170 | | { |
| | 0 | 171 | | return null; |
| | | 172 | | } |
| | | 173 | | |
| | 0 | 174 | | item = ResolveVideo<Video>(args, false); |
| | | 175 | | } |
| | | 176 | | |
| | | 177 | | // Ignore extras |
| | 0 | 178 | | if (item?.ExtraType is not null) |
| | | 179 | | { |
| | 0 | 180 | | return null; |
| | | 181 | | } |
| | | 182 | | |
| | 0 | 183 | | if (item is not null) |
| | | 184 | | { |
| | 0 | 185 | | item.IsInMixedFolder = true; |
| | | 186 | | } |
| | | 187 | | |
| | 0 | 188 | | return item; |
| | | 189 | | } |
| | | 190 | | |
| | | 191 | | private MultiItemResolverResult ResolveMultipleInternal( |
| | | 192 | | Folder parent, |
| | | 193 | | List<FileSystemMetadata> files, |
| | | 194 | | CollectionType? collectionType) |
| | | 195 | | { |
| | 60 | 196 | | if (IsInvalid(parent, collectionType)) |
| | | 197 | | { |
| | 58 | 198 | | return null; |
| | | 199 | | } |
| | | 200 | | |
| | 2 | 201 | | if (collectionType is CollectionType.musicvideos) |
| | | 202 | | { |
| | 0 | 203 | | return ResolveVideos<MusicVideo>(parent, files, true, collectionType, false); |
| | | 204 | | } |
| | | 205 | | |
| | 2 | 206 | | if (collectionType == CollectionType.homevideos || collectionType == CollectionType.photos) |
| | | 207 | | { |
| | 0 | 208 | | return ResolveVideos<Video>(parent, files, false, collectionType, false); |
| | | 209 | | } |
| | | 210 | | |
| | 2 | 211 | | if (collectionType is null) |
| | | 212 | | { |
| | | 213 | | // Owned items should just use the plain video type |
| | 0 | 214 | | if (parent is null) |
| | | 215 | | { |
| | 0 | 216 | | return ResolveVideos<Video>(parent, files, false, collectionType, false); |
| | | 217 | | } |
| | | 218 | | |
| | 0 | 219 | | if (parent is Series || parent.GetParents().OfType<Series>().Any()) |
| | | 220 | | { |
| | 0 | 221 | | return null; |
| | | 222 | | } |
| | | 223 | | |
| | 0 | 224 | | return ResolveVideos<Movie>(parent, files, false, collectionType, true); |
| | | 225 | | } |
| | | 226 | | |
| | 2 | 227 | | if (collectionType == CollectionType.movies) |
| | | 228 | | { |
| | 1 | 229 | | return ResolveVideos<Movie>(parent, files, true, collectionType, true); |
| | | 230 | | } |
| | | 231 | | |
| | 1 | 232 | | if (collectionType == CollectionType.tvshows) |
| | | 233 | | { |
| | 1 | 234 | | return ResolveVideos<Episode>(parent, files, true, collectionType, true); |
| | | 235 | | } |
| | | 236 | | |
| | 0 | 237 | | return null; |
| | | 238 | | } |
| | | 239 | | |
| | | 240 | | private MultiItemResolverResult ResolveVideos<T>( |
| | | 241 | | Folder parent, |
| | | 242 | | IEnumerable<FileSystemMetadata> fileSystemEntries, |
| | | 243 | | bool supportMultiEditions, |
| | | 244 | | CollectionType? collectionType, |
| | | 245 | | bool parseName) |
| | | 246 | | where T : Video, new() |
| | | 247 | | { |
| | 2 | 248 | | var files = new List<FileSystemMetadata>(); |
| | 2 | 249 | | var leftOver = new List<FileSystemMetadata>(); |
| | 2 | 250 | | var hasCollectionType = collectionType is not null; |
| | | 251 | | |
| | | 252 | | // Loop through each child file/folder and see if we find a video |
| | 14 | 253 | | foreach (var child in fileSystemEntries) |
| | | 254 | | { |
| | | 255 | | // This is a hack but currently no better way to resolve a sometimes ambiguous situation |
| | 5 | 256 | | if (!hasCollectionType) |
| | | 257 | | { |
| | 0 | 258 | | if (string.Equals(child.Name, "tvshow.nfo", StringComparison.OrdinalIgnoreCase) |
| | 0 | 259 | | || string.Equals(child.Name, "season.nfo", StringComparison.OrdinalIgnoreCase)) |
| | | 260 | | { |
| | 0 | 261 | | return null; |
| | | 262 | | } |
| | | 263 | | } |
| | | 264 | | |
| | 5 | 265 | | if (child.IsDirectory) |
| | | 266 | | { |
| | 0 | 267 | | leftOver.Add(child); |
| | | 268 | | } |
| | 5 | 269 | | else if (!IsIgnoredRegex().IsMatch(child.Name)) |
| | | 270 | | { |
| | 5 | 271 | | files.Add(child); |
| | | 272 | | } |
| | | 273 | | } |
| | | 274 | | |
| | 2 | 275 | | var videoInfos = files |
| | 2 | 276 | | .Select(i => VideoResolver.Resolve(i.FullName, i.IsDirectory, NamingOptions, parseName, parent.Containin |
| | 2 | 277 | | .Where(f => f is not null) |
| | 2 | 278 | | .ToList(); |
| | | 279 | | |
| | 2 | 280 | | var resolverResult = _videoListResolver.Resolve(videoInfos, supportMultiEditions, parseName, parent.Containi |
| | | 281 | | |
| | 2 | 282 | | var result = new MultiItemResolverResult |
| | 2 | 283 | | { |
| | 2 | 284 | | ExtraFiles = leftOver |
| | 2 | 285 | | }; |
| | | 286 | | |
| | 2 | 287 | | var isInMixedFolder = resolverResult.Count > 1 || parent?.IsTopParent == true; |
| | | 288 | | |
| | 10 | 289 | | foreach (var video in resolverResult) |
| | | 290 | | { |
| | 3 | 291 | | var firstVideo = video.Files[0]; |
| | 3 | 292 | | var path = firstVideo.Path; |
| | 3 | 293 | | if (video.ExtraType is not null) |
| | | 294 | | { |
| | 0 | 295 | | result.ExtraFiles.Add(files.Find(f => string.Equals(f.FullName, path, StringComparison.OrdinalIgnore |
| | 0 | 296 | | continue; |
| | | 297 | | } |
| | | 298 | | |
| | 3 | 299 | | var additionalParts = video.Files.Count > 1 ? video.Files.Skip(1).Select(i => i.Path).ToArray() : Array. |
| | | 300 | | |
| | 3 | 301 | | var videoItem = new T |
| | 3 | 302 | | { |
| | 3 | 303 | | Path = path, |
| | 3 | 304 | | IsInMixedFolder = isInMixedFolder, |
| | 3 | 305 | | ProductionYear = video.Year, |
| | 3 | 306 | | Name = parseName ? video.Name : firstVideo.Name, |
| | 3 | 307 | | AdditionalParts = additionalParts, |
| | 3 | 308 | | LocalAlternateVersions = video.AlternateVersions.Select(av => av.Files[0].Path).ToArray() |
| | 3 | 309 | | }; |
| | | 310 | | |
| | 3 | 311 | | SetVideoType(videoItem, firstVideo); |
| | 3 | 312 | | Set3DFormat(videoItem, firstVideo); |
| | | 313 | | |
| | 3 | 314 | | result.Items.Add(videoItem); |
| | | 315 | | } |
| | | 316 | | |
| | 2 | 317 | | result.ExtraFiles.AddRange(files.Where(i => !ContainsFile(resolverResult, i))); |
| | | 318 | | |
| | 2 | 319 | | return result; |
| | 0 | 320 | | } |
| | | 321 | | |
| | | 322 | | private static bool ContainsFile(IReadOnlyList<VideoInfo> result, FileSystemMetadata file) |
| | | 323 | | { |
| | 12 | 324 | | for (var i = 0; i < result.Count; i++) |
| | | 325 | | { |
| | 6 | 326 | | var current = result[i]; |
| | 18 | 327 | | for (var j = 0; j < current.Files.Count; j++) |
| | | 328 | | { |
| | 6 | 329 | | if (ContainsFile(current.Files[j], file)) |
| | | 330 | | { |
| | 3 | 331 | | return true; |
| | | 332 | | } |
| | | 333 | | } |
| | | 334 | | |
| | 8 | 335 | | for (var j = 0; j < current.AlternateVersions.Count; j++) |
| | | 336 | | { |
| | 3 | 337 | | var alternate = current.AlternateVersions[j]; |
| | 8 | 338 | | for (var k = 0; k < alternate.Files.Count; k++) |
| | | 339 | | { |
| | 3 | 340 | | if (ContainsFile(alternate.Files[k], file)) |
| | | 341 | | { |
| | 2 | 342 | | return true; |
| | | 343 | | } |
| | | 344 | | } |
| | | 345 | | } |
| | | 346 | | } |
| | | 347 | | |
| | 0 | 348 | | return false; |
| | | 349 | | } |
| | | 350 | | |
| | | 351 | | private static bool ContainsFile(VideoFileInfo result, FileSystemMetadata file) |
| | | 352 | | { |
| | 9 | 353 | | return string.Equals(result.Path, file.FullName, StringComparison.OrdinalIgnoreCase); |
| | | 354 | | } |
| | | 355 | | |
| | | 356 | | /// <summary> |
| | | 357 | | /// Sets the initial item values. |
| | | 358 | | /// </summary> |
| | | 359 | | /// <param name="item">The item.</param> |
| | | 360 | | /// <param name="args">The args.</param> |
| | | 361 | | protected override void SetInitialItemValues(Video item, ItemResolveArgs args) |
| | | 362 | | { |
| | 3 | 363 | | base.SetInitialItemValues(item, args); |
| | | 364 | | |
| | 3 | 365 | | SetProviderIdsFromPath(item); |
| | 3 | 366 | | } |
| | | 367 | | |
| | | 368 | | /// <summary> |
| | | 369 | | /// Sets the provider id from path. |
| | | 370 | | /// </summary> |
| | | 371 | | /// <param name="item">The item.</param> |
| | | 372 | | private static void SetProviderIdsFromPath(Video item) |
| | | 373 | | { |
| | 3 | 374 | | if (item is Movie || item is MusicVideo) |
| | | 375 | | { |
| | | 376 | | // We need to only look at the name of this actual item (not parents) |
| | 1 | 377 | | var justName = item.IsInMixedFolder ? Path.GetFileName(item.Path.AsSpan()) : Path.GetFileName(item.Conta |
| | | 378 | | |
| | 1 | 379 | | var tmdbid = justName.GetAttributeValue("tmdbid"); |
| | | 380 | | |
| | | 381 | | // If not in a mixed folder and ID not found in folder path, check filename |
| | 1 | 382 | | if (string.IsNullOrEmpty(tmdbid) && !item.IsInMixedFolder) |
| | | 383 | | { |
| | 1 | 384 | | tmdbid = Path.GetFileName(item.Path.AsSpan()).GetAttributeValue("tmdbid"); |
| | | 385 | | } |
| | | 386 | | |
| | 1 | 387 | | item.TrySetProviderId(MetadataProvider.Tmdb, tmdbid); |
| | | 388 | | |
| | 1 | 389 | | if (!string.IsNullOrEmpty(item.Path)) |
| | | 390 | | { |
| | | 391 | | // Check for IMDb id - we use full media path, as we can assume that this will match in any use case |
| | 1 | 392 | | var imdbid = item.Path.AsSpan().GetAttributeValue("imdbid"); |
| | 1 | 393 | | item.TrySetProviderId(MetadataProvider.Imdb, imdbid); |
| | | 394 | | } |
| | | 395 | | } |
| | 3 | 396 | | } |
| | | 397 | | |
| | | 398 | | /// <summary> |
| | | 399 | | /// Finds a movie based on a child file system entries. |
| | | 400 | | /// </summary> |
| | | 401 | | /// <returns>Movie.</returns> |
| | | 402 | | private T FindMovie<T>(ItemResolveArgs args, string path, Folder parent, List<FileSystemMetadata> fileSystemEntr |
| | | 403 | | where T : Video, new() |
| | | 404 | | { |
| | 0 | 405 | | var multiDiscFolders = new List<FileSystemMetadata>(); |
| | | 406 | | |
| | 0 | 407 | | var libraryOptions = args.LibraryOptions; |
| | 0 | 408 | | var supportPhotos = collectionType == CollectionType.homevideos && libraryOptions.EnablePhotos; |
| | 0 | 409 | | var photos = new List<FileSystemMetadata>(); |
| | | 410 | | |
| | | 411 | | // Search for a folder rip |
| | 0 | 412 | | foreach (var child in fileSystemEntries) |
| | | 413 | | { |
| | 0 | 414 | | var filename = child.Name; |
| | | 415 | | |
| | 0 | 416 | | if (child.IsDirectory) |
| | | 417 | | { |
| | 0 | 418 | | if (NamingOptions.AllExtrasTypesFolderNames.ContainsKey(filename)) |
| | | 419 | | { |
| | | 420 | | continue; |
| | | 421 | | } |
| | | 422 | | |
| | 0 | 423 | | if (IsDvdDirectory(child.FullName, filename, directoryService)) |
| | | 424 | | { |
| | 0 | 425 | | var movie = new T |
| | 0 | 426 | | { |
| | 0 | 427 | | Path = path, |
| | 0 | 428 | | VideoType = VideoType.Dvd |
| | 0 | 429 | | }; |
| | 0 | 430 | | Set3DFormat(movie); |
| | 0 | 431 | | return movie; |
| | | 432 | | } |
| | | 433 | | |
| | 0 | 434 | | if (IsBluRayDirectory(filename)) |
| | | 435 | | { |
| | 0 | 436 | | var movie = new T |
| | 0 | 437 | | { |
| | 0 | 438 | | Path = path, |
| | 0 | 439 | | VideoType = VideoType.BluRay |
| | 0 | 440 | | }; |
| | 0 | 441 | | Set3DFormat(movie); |
| | 0 | 442 | | return movie; |
| | | 443 | | } |
| | | 444 | | |
| | 0 | 445 | | multiDiscFolders.Add(child); |
| | | 446 | | } |
| | 0 | 447 | | else if (IsDvdFile(filename)) |
| | | 448 | | { |
| | 0 | 449 | | var movie = new T |
| | 0 | 450 | | { |
| | 0 | 451 | | Path = path, |
| | 0 | 452 | | VideoType = VideoType.Dvd |
| | 0 | 453 | | }; |
| | 0 | 454 | | Set3DFormat(movie); |
| | 0 | 455 | | return movie; |
| | | 456 | | } |
| | 0 | 457 | | else if (supportPhotos && PhotoResolver.IsImageFile(child.FullName, _imageProcessor)) |
| | | 458 | | { |
| | 0 | 459 | | photos.Add(child); |
| | | 460 | | } |
| | | 461 | | } |
| | | 462 | | |
| | | 463 | | // TODO: Allow GetMultiDiscMovie in here |
| | | 464 | | const bool SupportsMultiVersion = true; |
| | | 465 | | |
| | 0 | 466 | | var result = ResolveVideos<T>(parent, fileSystemEntries, SupportsMultiVersion, collectionType, parseName) ?? |
| | 0 | 467 | | new MultiItemResolverResult(); |
| | | 468 | | |
| | 0 | 469 | | var isPhotosCollection = collectionType == CollectionType.homevideos || collectionType == CollectionType.pho |
| | 0 | 470 | | if (!isPhotosCollection && result.Items.Count == 1) |
| | | 471 | | { |
| | 0 | 472 | | var videoPath = result.Items[0].Path; |
| | 0 | 473 | | var hasPhotos = photos.Any(i => !PhotoResolver.IsOwnedByResolvedMedia(videoPath, i.Name)); |
| | 0 | 474 | | var hasOtherSubfolders = multiDiscFolders.Count > 0; |
| | | 475 | | |
| | 0 | 476 | | if (!hasPhotos && !hasOtherSubfolders) |
| | | 477 | | { |
| | 0 | 478 | | var movie = (T)result.Items[0]; |
| | 0 | 479 | | movie.IsInMixedFolder = false; |
| | 0 | 480 | | if (collectionType == CollectionType.movies || collectionType is null) |
| | | 481 | | { |
| | 0 | 482 | | movie.Name = Path.GetFileName(movie.ContainingFolderPath); |
| | | 483 | | } |
| | | 484 | | |
| | 0 | 485 | | return movie; |
| | | 486 | | } |
| | | 487 | | } |
| | 0 | 488 | | else if (result.Items.Count == 0 && multiDiscFolders.Count > 0) |
| | | 489 | | { |
| | 0 | 490 | | return GetMultiDiscMovie<T>(multiDiscFolders, directoryService); |
| | | 491 | | } |
| | | 492 | | |
| | 0 | 493 | | return null; |
| | 0 | 494 | | } |
| | | 495 | | |
| | | 496 | | /// <summary> |
| | | 497 | | /// Gets the multi disc movie. |
| | | 498 | | /// </summary> |
| | | 499 | | /// <param name="multiDiscFolders">The folders.</param> |
| | | 500 | | /// <param name="directoryService">The directory service.</param> |
| | | 501 | | /// <returns>``0.</returns> |
| | | 502 | | private T GetMultiDiscMovie<T>(List<FileSystemMetadata> multiDiscFolders, IDirectoryService directoryService) |
| | | 503 | | where T : Video, new() |
| | | 504 | | { |
| | 0 | 505 | | var videoTypes = new List<VideoType>(); |
| | | 506 | | |
| | 0 | 507 | | var folderPaths = multiDiscFolders.Select(i => i.FullName).Where(i => |
| | 0 | 508 | | { |
| | 0 | 509 | | var subFileEntries = directoryService.GetFileSystemEntries(i); |
| | 0 | 510 | | |
| | 0 | 511 | | var subfolders = subFileEntries |
| | 0 | 512 | | .Where(e => e.IsDirectory) |
| | 0 | 513 | | .ToList(); |
| | 0 | 514 | | |
| | 0 | 515 | | if (subfolders.Any(s => IsDvdDirectory(s.FullName, s.Name, directoryService))) |
| | 0 | 516 | | { |
| | 0 | 517 | | videoTypes.Add(VideoType.Dvd); |
| | 0 | 518 | | return true; |
| | 0 | 519 | | } |
| | 0 | 520 | | |
| | 0 | 521 | | if (subfolders.Any(s => IsBluRayDirectory(s.Name))) |
| | 0 | 522 | | { |
| | 0 | 523 | | videoTypes.Add(VideoType.BluRay); |
| | 0 | 524 | | return true; |
| | 0 | 525 | | } |
| | 0 | 526 | | |
| | 0 | 527 | | var subFiles = subFileEntries |
| | 0 | 528 | | .Where(e => !e.IsDirectory) |
| | 0 | 529 | | .Select(d => d.Name); |
| | 0 | 530 | | |
| | 0 | 531 | | if (subFiles.Any(IsDvdFile)) |
| | 0 | 532 | | { |
| | 0 | 533 | | videoTypes.Add(VideoType.Dvd); |
| | 0 | 534 | | return true; |
| | 0 | 535 | | } |
| | 0 | 536 | | |
| | 0 | 537 | | return false; |
| | 0 | 538 | | }).Order().ToList(); |
| | | 539 | | |
| | | 540 | | // If different video types were found, don't allow this |
| | 0 | 541 | | if (videoTypes.Distinct().Count() > 1) |
| | | 542 | | { |
| | 0 | 543 | | return null; |
| | | 544 | | } |
| | | 545 | | |
| | 0 | 546 | | if (folderPaths.Count == 0) |
| | | 547 | | { |
| | 0 | 548 | | return null; |
| | | 549 | | } |
| | | 550 | | |
| | 0 | 551 | | var result = StackResolver.ResolveDirectories(folderPaths, NamingOptions).ToList(); |
| | | 552 | | |
| | 0 | 553 | | if (result.Count != 1) |
| | | 554 | | { |
| | 0 | 555 | | return null; |
| | | 556 | | } |
| | | 557 | | |
| | 0 | 558 | | int additionalPartsLen = folderPaths.Count - 1; |
| | 0 | 559 | | var additionalParts = new string[additionalPartsLen]; |
| | 0 | 560 | | folderPaths.CopyTo(1, additionalParts, 0, additionalPartsLen); |
| | | 561 | | |
| | 0 | 562 | | var returnVideo = new T |
| | 0 | 563 | | { |
| | 0 | 564 | | Path = folderPaths[0], |
| | 0 | 565 | | AdditionalParts = additionalParts, |
| | 0 | 566 | | VideoType = videoTypes[0], |
| | 0 | 567 | | Name = result[0].Name |
| | 0 | 568 | | }; |
| | | 569 | | |
| | 0 | 570 | | SetIsoType(returnVideo); |
| | | 571 | | |
| | 0 | 572 | | return returnVideo; |
| | | 573 | | } |
| | | 574 | | |
| | | 575 | | private bool IsInvalid(Folder parent, CollectionType? collectionType) |
| | | 576 | | { |
| | 71 | 577 | | if (parent is not null) |
| | | 578 | | { |
| | 71 | 579 | | if (parent.IsRoot) |
| | | 580 | | { |
| | 69 | 581 | | return true; |
| | | 582 | | } |
| | | 583 | | } |
| | | 584 | | |
| | 2 | 585 | | if (collectionType is null) |
| | | 586 | | { |
| | 0 | 587 | | return false; |
| | | 588 | | } |
| | | 589 | | |
| | 2 | 590 | | return !_validCollectionTypes.Contains(collectionType.Value); |
| | | 591 | | } |
| | | 592 | | } |
| | | 593 | | } |