Exemplo n.º 1
0
        protected override Series Resolve(ItemResolveArgs args)
        {
            if (args.IsDirectory)
            {
                if (args.HasParent <Series>() || args.HasParent <Season>())
                {
                    return(null);
                }

                var seriesInfo = Naming.TV.SeriesResolver.Resolve(_namingOptions, args.Path);

                var collectionType = args.GetCollectionType();
                if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
                {
                    // TODO refactor into separate class or something, this is copied from LibraryManager.GetConfiguredContentType
                    var configuredContentType = args.GetConfiguredContentType();
                    if (!string.Equals(configuredContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
                    {
                        return(new Series
                        {
                            Path = args.Path,
                            Name = seriesInfo.Name
                        });
                    }
                }
                else if (string.IsNullOrEmpty(collectionType))
                {
                    if (args.ContainsFileSystemEntryByName("tvshow.nfo"))
                    {
                        if (args.Parent != null && args.Parent.IsRoot)
                        {
                            // For now, return null, but if we want to allow this in the future then add some additional checks to guard against a misplaced tvshow.nfo
                            return(null);
                        }

                        return(new Series
                        {
                            Path = args.Path,
                            Name = seriesInfo.Name
                        });
                    }

                    if (args.Parent != null && args.Parent.IsRoot)
                    {
                        return(null);
                    }

                    if (IsSeriesFolder(args.Path, args.FileSystemChildren, false))
                    {
                        return(new Series
                        {
                            Path = args.Path,
                            Name = seriesInfo.Name
                        });
                    }
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        protected override Series Resolve(ItemResolveArgs args)
        {
            if (args.IsDirectory)
            {
                if (args.HasParent <Series>() || args.HasParent <Season>())
                {
                    return(null);
                }

                var collectionType = args.GetCollectionType();
                if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
                {
                    var configuredContentType = _libraryManager.GetConfiguredContentType(args.Path);
                    if (!string.Equals(configuredContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
                    {
                        return(new Series
                        {
                            Path = args.Path,
                            Name = Path.GetFileName(args.Path)
                        });
                    }
                }
                else if (string.IsNullOrEmpty(collectionType))
                {
                    if (args.ContainsFileSystemEntryByName("tvshow.nfo"))
                    {
                        if (args.Parent != null && args.Parent.IsRoot)
                        {
                            // For now, return null, but if we want to allow this in the future then add some additional checks to guard against a misplaced tvshow.nfo
                            return(null);
                        }

                        return(new Series
                        {
                            Path = args.Path,
                            Name = Path.GetFileName(args.Path)
                        });
                    }

                    if (args.Parent != null && args.Parent.IsRoot)
                    {
                        return(null);
                    }

                    if (IsSeriesFolder(args.Path, args.FileSystemChildren, _logger, _libraryManager, false))
                    {
                        return(new Series
                        {
                            Path = args.Path,
                            Name = Path.GetFileName(args.Path)
                        });
                    }
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>MusicArtist.</returns>
        protected override MusicArtist Resolve(ItemResolveArgs args)
        {
            if (!args.IsDirectory)
            {
                return(null);
            }

            // Don't allow nested artists
            if (args.HasParent <MusicArtist>() || args.HasParent <MusicAlbum>())
            {
                return(null);
            }

            var collectionType = args.GetCollectionType();

            var isMusicMediaFolder = string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase);

            // If there's a collection type and it's not music, it can't be a series
            if (!isMusicMediaFolder)
            {
                return(null);
            }

            if (args.ContainsFileSystemEntryByName("artist.nfo"))
            {
                return(new MusicArtist());
            }

            if (_config.Configuration.EnableSimpleArtistDetection)
            {
                return(null);
            }

            // Avoid mis-identifying top folders
            if (args.Parent.IsRoot)
            {
                return(null);
            }

            var directoryService = args.DirectoryService;

            var albumResolver = new MusicAlbumResolver(_logger, _fileSystem, _libraryManager);

            // If we contain an album assume we are an artist folder
            var directories = args.FileSystemChildren.Where(i => i.IsDirectory);

            var result = Parallel.ForEach(directories, (fileSystemInfo, state) =>
            {
                if (albumResolver.IsMusicAlbum(fileSystemInfo.FullName, directoryService))
                {
                    // stop once we see a music album
                    state.Stop();
                }
            });

            return(!result.IsCompleted ? new MusicArtist() : null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Series.</returns>
        protected override Series Resolve(ItemResolveArgs args)
        {
            if (args.IsDirectory)
            {
                var collectionType = args.GetCollectionType();
                if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
                {
                    if (args.HasParent <Series>())
                    {
                        return(null);
                    }

                    var configuredContentType = _libraryManager.GetConfiguredContentType(args.Path);
                    if (!string.Equals(configuredContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
                    {
                        return(new Series
                        {
                            Path = args.Path,
                            Name = Path.GetFileName(args.Path)
                        });
                    }
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(collectionType))
                    {
                        if (args.HasParent <Series>())
                        {
                            return(null);
                        }

                        if (args.Parent.IsRoot)
                        {
                            return(null);
                        }
                        if (IsSeriesFolder(args.Path, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager, false))
                        {
                            return(new Series
                            {
                                Path = args.Path,
                                Name = Path.GetFileName(args.Path)
                            });
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>MusicAlbum.</returns>
        protected override MusicAlbum Resolve(ItemResolveArgs args)
        {
            var collectionType = args.GetCollectionType();
            var isMusicMediaFolder = string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase);

            // If there's a collection type and it's not music, don't allow it.
            if (!isMusicMediaFolder)
            {
                return null;
            }

            if (!args.IsDirectory)
            {
                return null;
            }

            // Avoid mis-identifying top folders
            if (args.HasParent<MusicAlbum>())
            {
                return null;
            }

            if (args.Parent.IsRoot)
            {
                return null;
            }

            return IsMusicAlbum(args) ? new MusicAlbum() : null;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Episode.</returns>
        protected override Episode Resolve(ItemResolveArgs args)
        {
            var parent = args.Parent;

            if (parent == null)
            {
                return(null);
            }

            var season = parent as Season;

            // Just in case the user decided to nest episodes.
            // Not officially supported but in some cases we can handle it.
            if (season == null)
            {
                season = parent.GetParents().OfType <Season>().FirstOrDefault();
            }

            // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something
            // Also handle flat tv folders
            if (season != null || args.HasParent <Series>() || string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
            {
                var episode = ResolveVideo <Episode>(args, false);

                return(episode);
            }

            return(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Episode.</returns>
        protected override Episode Resolve(ItemResolveArgs args)
        {
            var parent = args.Parent;

            if (parent == null)
            {
                return(null);
            }

            var season = parent as Season;

            // Just in case the user decided to nest episodes.
            // Not officially supported but in some cases we can handle it.
            if (season == null)
            {
                season = parent.GetParents().OfType <Season>().FirstOrDefault();
            }

            // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something
            if (season != null || args.HasParent <Series>())
            {
                var episode = ResolveVideo <Episode>(args, false);

                return(episode);
            }

            return(null);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Episode.</returns>
        public override Episode Resolve(ItemResolveArgs args)
        {
            var parent = args.Parent;

            if (parent == null)
            {
                return(null);
            }

            var season = parent as Season;

            // Just in case the user decided to nest episodes.
            // Not officially supported but in some cases we can handle it.
            if (season == null)
            {
                season = parent.GetParents().OfType <Season>().FirstOrDefault();
            }

            // If the parent is a Season or Series and the parent is not an extras folder, then this is an Episode if the VideoResolver returns something
            // Also handle flat tv folders
            if ((season != null ||
                 string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) ||
                 args.HasParent <Series>()) &&
                (parent is Series || !BaseItem.AllExtrasTypesFolderNames.Contains(parent.Name, StringComparer.OrdinalIgnoreCase)))
            {
                var episode = ResolveVideo <Episode>(args, false);

                if (episode != null)
                {
                    var series = parent as Series;
                    if (series == null)
                    {
                        series = parent.GetParents().OfType <Series>().FirstOrDefault();
                    }

                    if (series != null)
                    {
                        episode.SeriesId   = series.Id;
                        episode.SeriesName = series.Name;
                    }

                    if (season != null)
                    {
                        episode.SeasonId   = season.Id;
                        episode.SeasonName = season.Name;
                    }

                    // Assume season 1 if there's no season folder and a season number could not be determined
                    if (season == null && !episode.ParentIndexNumber.HasValue && (episode.IndexNumber.HasValue || episode.PremiereDate.HasValue))
                    {
                        episode.ParentIndexNumber = 1;
                    }
                }

                return(episode);
            }

            return(null);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>MusicArtist.</returns>
        protected override MusicArtist Resolve(ItemResolveArgs args)
        {
            if (!args.IsDirectory)
            {
                return(null);
            }

            // Don't allow nested artists
            if (args.HasParent <MusicArtist>() || args.HasParent <MusicAlbum>())
            {
                return(null);
            }

            var collectionType = args.GetCollectionType();

            var isMusicMediaFolder = string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase);

            // If there's a collection type and it's not music, it can't be a series
            if (!isMusicMediaFolder)
            {
                return(null);
            }

            if (args.ContainsFileSystemEntryByName("artist.nfo"))
            {
                return(new MusicArtist());
            }

            if (_config.Configuration.EnableSimpleArtistDetection)
            {
                return(null);
            }

            // Avoid mis-identifying top folders
            if (args.Parent.IsRoot)
            {
                return(null);
            }

            var directoryService = args.DirectoryService;

            var albumResolver = new MusicAlbumResolver(_logger, _fileSystem, _libraryManager);

            // If we contain an album assume we are an artist folder
            return(args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => albumResolver.IsMusicAlbum(i.FullName, directoryService, args.GetLibraryOptions())) ? new MusicArtist() : null);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Video.</returns>
        protected override Video Resolve(ItemResolveArgs args)
        {
            var collectionType = args.GetCollectionType();

            if (IsInvalid(args.Parent, collectionType))
            {
                return(null);
            }

            // Find movies with their own folders
            if (args.IsDirectory)
            {
                var files = args.FileSystemChildren
                            .Where(i => !LibraryManager.IgnoreFile(i, args.Parent))
                            .ToList();

                if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
                {
                    return(FindMovie <MusicVideo>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, false));
                }

                if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
                {
                    return(FindMovie <Video>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, false));
                }

                if (string.IsNullOrEmpty(collectionType))
                {
                    // Owned items will be caught by the plain video resolver
                    if (args.Parent == null)
                    {
                        //return FindMovie<Video>(args.Path, args.Parent, files, args.DirectoryService, collectionType);
                        return(null);
                    }

                    if (args.HasParent <Series>())
                    {
                        return(null);
                    }

                    {
                        return(FindMovie <Movie>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, true));
                    }
                }

                if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
                {
                    return(FindMovie <Movie>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, true));
                }

                return(null);
            }

            // Owned items will be caught by the plain video resolver
            if (args.Parent == null)
            {
                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);
            }

            if (item != null)
            {
                item.IsInMixedFolder = true;
            }

            return(item);
        }
Exemplo n.º 11
0
        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);
                }

                Video movie = null;
                var   files = args.GetActualFileSystemChildren().ToList();

                if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
                {
                    movie = FindMovie <MusicVideo>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, false);
                }

                if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
                {
                    movie = FindMovie <Video>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, false);
                }

                if (string.IsNullOrEmpty(collectionType))
                {
                    // Owned items will be caught by the plain video resolver
                    if (args.Parent == null)
                    {
                        // return FindMovie<Video>(args.Path, args.Parent, files, args.DirectoryService, collectionType);
                        return(null);
                    }

                    if (args.HasParent <Series>())
                    {
                        return(null);
                    }

                    movie = FindMovie <Movie>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, true);
                }

                if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
                {
                    movie = FindMovie <Movie>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, true);
                }

                // ignore extras
                return(movie?.ExtraType == null ? movie : null);
            }

            // Handle owned items
            if (args.Parent == null)
            {
                return(base.Resolve(args));
            }

            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);
            }

            // Ignore extras
            if (item?.ExtraType != null)
            {
                return(null);
            }

            if (item != null)
            {
                item.IsInMixedFolder = true;
            }

            return(item);
        }