예제 #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);
        }
예제 #2
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>ConsoleFolder.</returns>
        protected override GameSystem Resolve(ItemResolveArgs args)
        {
            if (args.IsDirectory)
            {
                var collectionType = args.GetCollectionType();

                if (!collectionType.AsSpan().Equals(CollectionType.Games.Span, StringComparison.OrdinalIgnoreCase))
                {
                    return(null);
                }

                var configuredSystems = Plugin.Instance.Configuration.GameSystems;

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

                var system =
                    configuredSystems.FirstOrDefault(
                        s => string.Equals(args.Path, s.Path, StringComparison.OrdinalIgnoreCase));

                if (system != null)
                {
                    return(new GameSystem());
                }
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        protected override Book Resolve(ItemResolveArgs args)
        {
            var collectionType = args.GetCollectionType();

            // Only process items that are in a collection folder containing books
            if (!string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            if (args.IsDirectory)
            {
                return(GetBook(args));
            }

            var extension = Path.GetExtension(args.Path);

            if (extension != null && _validExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
            {
                // It's a book
                return(new Book
                {
                    Path = args.Path,
                    IsInMixedFolder = true
                });
            }

            return(null);
        }
예제 #4
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);
        }
예제 #5
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>MusicAlbum.</returns>
        protected override MusicAlbum Resolve(ItemResolveArgs args)
        {
            if (!args.IsDirectory)
            {
                return(null);
            }

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

            var collectionType = args.GetCollectionType();

            // If there's a collection type and it's not music, it can't be a series
            if (!string.IsNullOrEmpty(collectionType) &&
                !string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            return(IsMusicAlbum(args) ? new MusicAlbum
            {
                DisplayMediaType = "Album"
            } : null);
        }
예제 #6
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Entities.Audio.Audio.</returns>
        protected override Controller.Entities.Audio.Audio Resolve(ItemResolveArgs args)
        {
            // Return audio if the path is a file and has a matching extension

            if (!args.IsDirectory)
            {
                if (_libraryManager.IsAudioFile(args.Path))
                {
                    var collectionType = args.GetCollectionType();

                    var isMixed = string.IsNullOrWhiteSpace(collectionType);

                    // For conflicting extensions, give priority to videos
                    if (isMixed && _libraryManager.IsVideoFile(args.Path))
                    {
                        return(null);
                    }

                    var isStandalone = args.Parent == null;

                    if (isStandalone ||
                        string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase) ||
                        isMixed)
                    {
                        return(new Controller.Entities.Audio.Audio());
                    }
                }
            }

            return(null);
        }
예제 #7
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;
        }
예제 #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);
            }

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

            // Don't allow nested artists
            if (args.Parent is MusicArtist)
            {
                return(null);
            }

            var collectionType = args.GetCollectionType();

            // If there's a collection type and it's not music, it can't be a series
            if (!string.IsNullOrEmpty(collectionType) &&
                !string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            // If we contain an album assume we are an artist folder
            return(args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => MusicAlbumResolver.IsMusicAlbum(i.FullName)) ? new MusicArtist() : null);
        }
예제 #9
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Trailer.</returns>
        protected override Photo Resolve(ItemResolveArgs args)
        {
            if (!args.IsDirectory)
            {
                // Must be an image file within a photo collection
                var collectionType = args.GetCollectionType();

                if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
                {
                    if (IsImageFile(args.Path, _imageProcessor))
                    {
                        var filename = Path.GetFileNameWithoutExtension(args.Path);

                        // Make sure the image doesn't belong to a video file
                        if (args.DirectoryService.GetFiles(Path.GetDirectoryName(args.Path)).Any(i => IsOwnedByMedia(i, filename)))
                        {
                            return(null);
                        }

                        return(new Photo
                        {
                            Path = args.Path
                        });
                    }
                }
            }

            return(null);
        }
예제 #10
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);
        }
예제 #11
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);
        }
예제 #12
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);
        }
예제 #13
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Trailer.</returns>
        protected override Photo Resolve(ItemResolveArgs args)
        {
            // Must be an image file within a photo collection
            if (!args.IsDirectory && IsImageFile(args.Path) && string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase))
            {
                return(new Photo
                {
                    Path = args.Path
                });
            }

            return(null);
        }
예제 #14
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)
            {
                // Avoid expensive tests against VF's and all their children by not allowing this
                if (args.Parent == null || args.Parent.IsRoot)
                {
                    return(null);
                }

                // Optimization to avoid running these tests against Seasons
                if (args.Parent is Series || args.Parent is Season || args.Parent is MusicArtist || args.Parent is MusicAlbum)
                {
                    return(null);
                }

                var collectionType = args.GetCollectionType();

                // If there's a collection type and it's not tv, it can't be a series
                if (!string.IsNullOrEmpty(collectionType) &&
                    !string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
                {
                    return(null);
                }

                // It's a Series if any of the following conditions are met:
                // series.xml exists
                // [tvdbid= is present in the path
                // TVUtils.IsSeriesFolder returns true
                var filename = Path.GetFileName(args.Path);

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

                // Without these movies that have the name season in them could cause the parent folder to be resolved as a series
                if (filename.IndexOf("[tmdbid=", StringComparison.OrdinalIgnoreCase) != -1)
                {
                    return(null);
                }

                if (args.ContainsMetaFileByName("series.xml") || filename.IndexOf("[tvdbid=", StringComparison.OrdinalIgnoreCase) != -1 || TVUtils.IsSeriesFolder(args.Path, args.FileSystemChildren, args.DirectoryService))
                {
                    return(new Series());
                }
            }

            return(null);
        }
예제 #15
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);
        }
예제 #16
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Game.</returns>
        protected override Game Resolve(ItemResolveArgs args)
        {
            var collectionType = args.GetCollectionType();

            if (!string.Equals(collectionType, CollectionType.Games, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            var platform = ResolverHelper.AttemptGetGamePlatformTypeFromPath(_fileSystem, args.Path);

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

            if (args.IsDirectory)
            {
                return(GetGame(args, platform));
            }

            // For MAME we will allow all games in the same dir
            if (string.Equals(platform, "Arcade"))
            {
                var extension = Path.GetExtension(args.Path);

                if (string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase))
                {
                    // ignore zips that are bios roms.
                    if (MameUtils.IsBiosRom(args.Path))
                    {
                        return(null);
                    }

                    var game = new Game
                    {
                        Name             = MameUtils.GetFullNameFromPath(args.Path, _logger),
                        Path             = args.Path,
                        GameSystem       = "Arcade",
                        DisplayMediaType = "Arcade",
                        IsInMixedFolder  = true
                    };
                    return(game);
                }
            }

            return(null);
        }
예제 #17
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);
        }
예제 #18
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);
            }

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

            // Don't allow nested artists
            if (args.Parent is MusicArtist)
            {
                return(null);
            }

            // Optimization
            if (args.Parent is BoxSet || args.Parent is Series || args.Parent is Season)
            {
                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);
            }

            var directoryService = args.DirectoryService;

            // If we contain an album assume we are an artist folder
            return(args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => MusicAlbumResolver.IsMusicAlbum(i.FullName, directoryService, _logger, _fileSystem, _libraryManager)) ? new MusicArtist() : null);
        }
예제 #19
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Entities.Audio.Audio.</returns>
        protected override MediaBrowser.Controller.Entities.Audio.Audio Resolve(ItemResolveArgs args)
        {
            // Return audio if the path is a file and has a matching extension

            if (!args.IsDirectory)
            {
                var libraryOptions = args.GetLibraryOptions();

                if (_libraryManager.IsAudioFile(args.Path, libraryOptions))
                {
                    if (string.Equals(Path.GetExtension(args.Path), ".cue", StringComparison.OrdinalIgnoreCase))
                    {
                        // if audio file exists of same name, return null

                        return(null);
                    }

                    var collectionType = args.GetCollectionType();

                    var isMixed = string.IsNullOrWhiteSpace(collectionType);

                    // For conflicting extensions, give priority to videos
                    if (isMixed && _libraryManager.IsVideoFile(args.Path, libraryOptions))
                    {
                        return(null);
                    }

                    var isStandalone = args.Parent == null;

                    if (isStandalone ||
                        string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase) ||
                        isMixed)
                    {
                        return(new MediaBrowser.Controller.Entities.Audio.Audio());
                    }

                    if (string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
                    {
                        return(new AudioBook());
                    }
                }
            }

            return(null);
        }
예제 #20
0
        protected override Video Resolve(ItemResolveArgs args)
        {
            if (args.Parent != null)
            {
                var collectionType = args.GetCollectionType() ?? string.Empty;
                var accepted       = new[]
                {
                    string.Empty,
                    CollectionType.HomeVideos
                };

                if (!accepted.Contains(collectionType, StringComparer.OrdinalIgnoreCase))
                {
                    return(null);
                }
            }

            return(base.Resolve(args));
        }
예제 #21
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Entities.Audio.Audio.</returns>
        protected override Controller.Entities.Audio.Audio Resolve(ItemResolveArgs args)
        {
            // Return audio if the path is a file and has a matching extension

            if (!args.IsDirectory)
            {
                if (EntityResolutionHelper.IsAudioFile(args.Path))
                {
                    var collectionType = args.GetCollectionType();

                    if (string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase) ||
                        string.IsNullOrEmpty(collectionType))
                    {
                        return(new Controller.Entities.Audio.Audio());
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>ConsoleFolder.</returns>
        protected override GameSystem Resolve(ItemResolveArgs args)
        {
            if (args.IsDirectory)
            {
                if (args.Parent != null)
                {
                    var collectionType = args.GetCollectionType();

                    if (!string.Equals(collectionType, CollectionType.Games, StringComparison.OrdinalIgnoreCase))
                    {
                        return(null);
                    }

                    // Optimization to avoid running all these tests against VF's
                    if (args.Parent.IsRoot)
                    {
                        return(null);
                    }

                    var configuredSystems = Plugin.Instance.Configuration.GameSystems;

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

                    var system =
                        configuredSystems.FirstOrDefault(
                            s => string.Equals(args.Path, s.Path, StringComparison.OrdinalIgnoreCase));

                    if (system != null)
                    {
                        return(new GameSystem {
                            GameSystemName = system.ConsoleType
                        });
                    }
                }
            }

            return(null);
        }
예제 #23
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>MusicAlbum.</returns>
        protected override MusicAlbum Resolve(ItemResolveArgs args)
        {
            if (!args.IsDirectory)
            {
                return(null);
            }

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

            // Optimization
            if (args.Parent is BoxSet || args.Parent is Series || args.Parent is Season)
            {
                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, don't allow it.
            if (!isMusicMediaFolder)
            {
                return(null);
            }

            return(IsMusicAlbum(args, isMusicMediaFolder) ? new MusicAlbum() : null);
        }
예제 #24
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Entities.Audio.Audio.</returns>
        protected override Controller.Entities.Audio.Audio Resolve(ItemResolveArgs args)
        {
            // Return audio if the path is a file and has a matching extension

            if (!args.IsDirectory)
            {
                if (_libraryManager.IsAudioFile(args.Path))
                {
                    var collectionType = args.GetCollectionType();

                    var isStandalone = args.Parent == null;

                    if (isStandalone ||
                        string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase))
                    {
                        return(new Controller.Entities.Audio.Audio());
                    }
                }
            }

            return(null);
        }
예제 #25
0
        protected override PhotoAlbum Resolve(ItemResolveArgs args)
        {
            // Must be an image file within a photo collection
            if (args.IsDirectory)
            {
                // Must be an image file within a photo collection
                var collectionType = args.GetCollectionType();

                if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) ||
                    (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.LibraryOptions.EnablePhotos))
                {
                    if (HasPhotos(args))
                    {
                        return(new PhotoAlbum
                        {
                            Path = args.Path
                        });
                    }
                }
            }

            return(null);
        }
예제 #26
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)
            {
                // Avoid expensive tests against VF's and all their children by not allowing this
                if (args.Parent == null || args.Parent.IsRoot)
                {
                    return(null);
                }

                // Optimization to avoid running these tests against Seasons
                if (args.Parent is Series || args.Parent is Season || args.Parent is MusicArtist || args.Parent is MusicAlbum)
                {
                    return(null);
                }

                var collectionType = args.GetCollectionType();

                var isTvShowsFolder = string.Equals(collectionType, CollectionType.TvShows,
                                                    StringComparison.OrdinalIgnoreCase);

                // If there's a collection type and it's not tv, it can't be a series
                if (!string.IsNullOrEmpty(collectionType) &&
                    !isTvShowsFolder &&
                    !string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
                {
                    return(null);
                }

                if (TVUtils.IsSeriesFolder(args.Path, isTvShowsFolder, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger))
                {
                    return(new Series());
                }
            }

            return(null);
        }
예제 #27
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Trailer.</returns>
        protected override Photo Resolve(ItemResolveArgs args)
        {
            if (!args.IsDirectory)
            {
                // Must be an image file within a photo collection
                var collectionType = args.GetCollectionType();

                if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) ||
                    (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.GetLibraryOptions().EnablePhotos))
                {
                    if (IsImageFile(args.Path, _imageProcessor))
                    {
                        var filename = Path.GetFileNameWithoutExtension(args.Path);

                        // Make sure the image doesn't belong to a video file
                        var files          = args.DirectoryService.GetFiles(Path.GetDirectoryName(args.Path));
                        var libraryOptions = args.GetLibraryOptions();

                        foreach (var file in files)
                        {
                            if (IsOwnedByMedia(_libraryManager, libraryOptions, file.FullName, filename))
                            {
                                return(null);
                            }
                        }

                        return(new Photo
                        {
                            Path = args.Path
                        });
                    }
                }
            }

            return(null);
        }
예제 #28
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);
        }
예제 #29
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Video.</returns>
        protected override Video Resolve(ItemResolveArgs args)
        {
            // Avoid expensive tests against VF's and all their children by not allowing this
            if (args.Parent != null)
            {
                if (args.Parent.IsRoot)
                {
                    return(null);
                }

                // If the parent is not a boxset, the only other allowed parent type is Folder
                if (!(args.Parent is BoxSet))
                {
                    if (args.Parent.GetType() != typeof(Folder))
                    {
                        return(null);
                    }
                }
            }

            // Since the looping is expensive, this is an optimization to help us avoid it
            if (args.Path.IndexOf("[tvdbid", StringComparison.OrdinalIgnoreCase) != -1)
            {
                return(null);
            }

            var isDirectory = args.IsDirectory;

            if (isDirectory)
            {
                // Since the looping is expensive, this is an optimization to help us avoid it
                if (args.ContainsMetaFileByName("series.xml"))
                {
                    return(null);
                }
            }

            var collectionType = args.GetCollectionType();

            // Find movies with their own folders
            if (isDirectory)
            {
                if (args.Path.IndexOf("[trailers]", StringComparison.OrdinalIgnoreCase) != -1 ||
                    string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase))
                {
                    return(FindMovie <Trailer>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService));
                }

                if (args.Path.IndexOf("[musicvideos]", StringComparison.OrdinalIgnoreCase) != -1 ||
                    string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
                {
                    return(FindMovie <MusicVideo>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService));
                }

                if (args.Path.IndexOf("[adultvideos]", StringComparison.OrdinalIgnoreCase) != -1 ||
                    string.Equals(collectionType, CollectionType.AdultVideos, StringComparison.OrdinalIgnoreCase))
                {
                    return(FindMovie <AdultVideo>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService));
                }

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

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

                return(null);
            }

            var filename = Path.GetFileName(args.Path);

            // Don't misidentify xbmc trailers as a movie
            if (filename.IndexOf(BaseItem.XbmcTrailerFileSuffix, StringComparison.OrdinalIgnoreCase) != -1)
            {
                return(null);
            }

            // Find movies that are mixed in the same folder
            if (args.Path.IndexOf("[trailers]", StringComparison.OrdinalIgnoreCase) != -1 ||
                string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase))
            {
                return(ResolveVideo <Trailer>(args));
            }

            Video item = null;

            if (args.Path.IndexOf("[musicvideos]", StringComparison.OrdinalIgnoreCase) != -1 ||
                string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
            {
                item = ResolveVideo <MusicVideo>(args);
            }

            if (args.Path.IndexOf("[adultvideos]", StringComparison.OrdinalIgnoreCase) != -1 ||
                string.Equals(collectionType, CollectionType.AdultVideos, StringComparison.OrdinalIgnoreCase))
            {
                item = ResolveVideo <AdultVideo>(args);
            }

            // To find a movie file, the collection type must be movies or boxsets
            // Otherwise we'll consider it a plain video and let the video resolver handle it
            if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) ||
                string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
            {
                item = ResolveVideo <Movie>(args);
            }

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

            return(item);
        }
예제 #30
0
        /// <summary>
        /// Resolves the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>Entities.Audio.Audio.</returns>
        protected override MediaBrowser.Controller.Entities.Audio.Audio Resolve(ItemResolveArgs args)
        {
            // Return audio if the path is a file and has a matching extension

            var collectionType = args.GetCollectionType();

            var isBooksCollectionType = string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase);

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

                var files = args.FileSystemChildren
                            .Where(i => !LibraryManager.IgnoreFile(i, args.Parent))
                            .ToList();

                return(FindAudio <AudioBook>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, false));
            }

            if (LibraryManager.IsAudioFile(args.Path))
            {
                var extension = Path.GetExtension(args.Path);

                if (string.Equals(extension, ".cue", StringComparison.OrdinalIgnoreCase))
                {
                    // if audio file exists of same name, return null
                    return(null);
                }

                var isMixedCollectionType = string.IsNullOrEmpty(collectionType);

                // For conflicting extensions, give priority to videos
                if (isMixedCollectionType && LibraryManager.IsVideoFile(args.Path))
                {
                    return(null);
                }

                MediaBrowser.Controller.Entities.Audio.Audio item = null;

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

                // Use regular audio type for mixed libraries, owned items and music
                if (isMixedCollectionType ||
                    args.Parent == null ||
                    isMusicCollectionType)
                {
                    item = new MediaBrowser.Controller.Entities.Audio.Audio();
                }
                else if (isBooksCollectionType)
                {
                    item = new AudioBook();
                }

                if (item != null)
                {
                    item.IsShortcut = string.Equals(extension, ".strm", StringComparison.OrdinalIgnoreCase);

                    item.IsInMixedFolder = true;
                }

                return(item);
            }

            return(null);
        }