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