Exemplo n.º 1
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Episode.</returns>
        protected override Episode Resolve(ItemResolveArgs args)
        {
            // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something
            if (args.Parent is Season || args.Parent is Series)
            {
                if (args.IsDirectory)
                {
                    if (args.ContainsFileSystemEntryByName("video_ts"))
                    {
                        return(new Episode
                        {
                            Path = args.Path,
                            VideoType = VideoType.Dvd
                        });
                    }
                    if (args.ContainsFileSystemEntryByName("bdmv"))
                    {
                        return(new Episode
                        {
                            Path = args.Path,
                            VideoType = VideoType.BluRay
                        });
                    }
                }

                return(base.Resolve(args));
            }

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

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

                if (args.IsDirectory)
                {
                    if (args.ContainsFileSystemEntryByName("video_ts"))
                    {
                        episode = new Episode
                        {
                            Path      = args.Path,
                            VideoType = VideoType.Dvd
                        };
                    }
                    if (args.ContainsFileSystemEntryByName("bdmv"))
                    {
                        episode = new Episode
                        {
                            Path      = args.Path,
                            VideoType = VideoType.BluRay
                        };
                    }
                }

                if (episode == null)
                {
                    episode = base.Resolve(args);
                }

                if (episode != null)
                {
                    if (season != null)
                    {
                        episode.ParentIndexNumber = season.IndexNumber;
                    }

                    if (episode.ParentIndexNumber == null)
                    {
                        episode.ParentIndexNumber = TVUtils.GetSeasonNumberFromEpisodeFile(args.Path);
                    }
                }

                return(episode);
            }

            return(null);
        }
Exemplo n.º 3
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.º 4
0
        /// <summary>
        /// Populates the backdrops from extra fanart.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <param name="backdrops">The backdrops.</param>
        private void PopulateBackdropsFromExtraFanart(ItemResolveArgs args, List <string> backdrops)
        {
            if (!args.IsDirectory)
            {
                return;
            }

            if (args.ContainsFileSystemEntryByName("extrafanart"))
            {
                var path = Path.Combine(args.Path, "extrafanart");

                var imageFiles = Directory.EnumerateFiles(path, "*", SearchOption.TopDirectoryOnly)
                                 .Where(i =>
                {
                    var extension = Path.GetExtension(i);

                    if (string.IsNullOrEmpty(extension))
                    {
                        return(false);
                    }

                    return(BaseItem.SupportedImageExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase));
                })
                                 .ToList();

                backdrops.AddRange(imageFiles);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>BoxSet.</returns>
        protected override BoxSet Resolve(ItemResolveArgs args)
        {
            // It's a boxset if all of the following conditions are met:
            // Is a Directory
            // Contains [boxset] in the path
            if (args.IsDirectory)
            {
                var filename = Path.GetFileName(args.Path);

                if (string.IsNullOrEmpty(filename))
                {
                    return(null);
                }

                if (filename.IndexOf("[boxset]", StringComparison.OrdinalIgnoreCase) != -1 ||
                    args.ContainsFileSystemEntryByName("collection.xml"))
                {
                    return(new BoxSet
                    {
                        Path = args.Path,
                        Name = ResolverHelper.StripBrackets(Path.GetFileName(args.Path))
                    });
                }
            }

            return(null);
        }
Exemplo n.º 6
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.º 7
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.º 8
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.º 9
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.Parents.OfType <Season>().FirstOrDefault();
            }

            // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something
            if (season != null || parent is Series || parent.Parents.OfType <Series>().Any())
            {
                Episode episode = null;

                if (args.IsDirectory)
                {
                    if (args.ContainsFileSystemEntryByName("video_ts"))
                    {
                        episode = new Episode
                        {
                            Path      = args.Path,
                            VideoType = VideoType.Dvd
                        };
                    }
                    if (args.ContainsFileSystemEntryByName("bdmv"))
                    {
                        episode = new Episode
                        {
                            Path      = args.Path,
                            VideoType = VideoType.BluRay
                        };
                    }
                }

                if (episode == null)
                {
                    episode = base.Resolve(args);
                }

                if (episode != null)
                {
                    if (season != null)
                    {
                        episode.ParentIndexNumber = season.IndexNumber;
                    }

                    if (episode.ParentIndexNumber == null)
                    {
                        episode.ParentIndexNumber = TVUtils.GetSeasonNumberFromEpisodeFile(args.Path);
                    }
                }

                return(episode);
            }

            return(null);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>BoxSet.</returns>
        protected override BoxSet Resolve(ItemResolveArgs args)
        {
            // It's a boxset if all of the following conditions are met:
            // Is a Directory
            // Contains [boxset] in the path
            if (args.IsDirectory)
            {
                var filename = Path.GetFileName(args.Path);

                if (string.IsNullOrEmpty(filename))
                {
                    return(null);
                }

                // This is a bit of a one-off but it's here to combat MCM's over-aggressive placement of collection.xml files where they don't belong, including in series folders.
                if (args.ContainsMetaFileByName("series.xml"))
                {
                    return(null);
                }

                if (filename.IndexOf("[boxset]", StringComparison.OrdinalIgnoreCase) != -1 || args.ContainsFileSystemEntryByName("collection.xml"))
                {
                    return(new BoxSet {
                        Path = args.Path
                    });
                }
            }

            return(null);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Determines whether a path should be ignored based on its contents - called after the contents have been read
 /// </summary>
 /// <param name="args">The args.</param>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
 private static bool ShouldResolvePathContents(ItemResolveArgs args)
 {
     // Ignore any folders containing a file called .ignore
     return(!args.ContainsFileSystemEntryByName(".ignore"));
 }