private List <string> GetOtherDuplicatePaths(
            string targetPath,
            Series series,
            Episode episode)
        {
            // TODO: Support date-naming?
            if (!series.ParentIndexNumber.HasValue || !episode.IndexNumber.HasValue)
            {
                return(new List <string>());
            }

            var episodePaths = series.GetRecursiveChildren()
                               .OfType <Episode>()
                               .Where(i =>
            {
                var locationType = i.LocationType;

                // Must be file system based and match exactly
                if (locationType != LocationType.Remote &&
                    locationType != LocationType.Virtual &&
                    i.ParentIndexNumber.HasValue &&
                    i.ParentIndexNumber.Value == series.ParentIndexNumber &&
                    i.IndexNumber.HasValue &&
                    i.IndexNumber.Value == episode.IndexNumber)
                {
                    if (episode.IndexNumberEnd.HasValue || i.IndexNumberEnd.HasValue)
                    {
                        return(episode.IndexNumberEnd.HasValue && i.IndexNumberEnd.HasValue &&
                               episode.IndexNumberEnd.Value == i.IndexNumberEnd.Value);
                    }

                    return(true);
                }

                return(false);
            })
                               .Select(i => i.Path)
                               .ToList();

            var folder = Path.GetDirectoryName(targetPath);
            var targetFileNameWithoutExtension = Path.GetFileNameWithoutExtension(targetPath);

            try
            {
                var filesOfOtherExtensions = _fileSystem.GetFilePaths(folder)
                                             .Where(i => VideoResolver.IsVideoFile(i, _namingOptions) && string.Equals(Path.GetFileNameWithoutExtension(i), targetFileNameWithoutExtension, StringComparison.OrdinalIgnoreCase));

                episodePaths.AddRange(filesOfOtherExtensions);
            }
            catch (IOException)
            {
                // No big deal. Maybe the season folder doesn't already exist.
            }

            return(episodePaths.Where(i => !string.Equals(i, targetPath, StringComparison.OrdinalIgnoreCase))
                   .Distinct(StringComparer.OrdinalIgnoreCase)
                   .ToList());
        }
        private bool EnableOrganization(FileSystemMetadata fileInfo, TvFileOrganizationOptions options)
        {
            var minFileBytes = options.MinFileSizeMb * 1024 * 1024;

            try
            {
                return(VideoResolver.IsVideoFile(fileInfo.FullName, _namingOptions) && fileInfo.Length >= minFileBytes);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error organizing file {0}", fileInfo.Name);
            }

            return(false);
        }
Пример #3
0
        private bool IsSeriesFolder(
            string path,
            IEnumerable <FileSystemMetadata> fileSystemChildren,
            bool isTvContentType)
        {
            foreach (var child in fileSystemChildren)
            {
                if (child.IsDirectory)
                {
                    if (IsSeasonFolder(child.FullName, isTvContentType))
                    {
                        _logger.LogDebug("{Path} is a series because of season folder {Dir}.", path, child.FullName);
                        return(true);
                    }
                }
                else
                {
                    string fullName = child.FullName;
                    if (VideoResolver.IsVideoFile(path, _namingOptions))
                    {
                        if (isTvContentType)
                        {
                            return(true);
                        }

                        var namingOptions = _namingOptions;

                        var episodeResolver = new Naming.TV.EpisodeResolver(namingOptions);

                        var episodeInfo = episodeResolver.Resolve(fullName, false, true, false, fillExtendedInfo: false);
                        if (episodeInfo != null && episodeInfo.EpisodeNumber.HasValue)
                        {
                            return(true);
                        }
                    }
                }
            }

            _logger.LogDebug("{Path} is not a series folder.", path);
            return(false);
        }
Пример #4
0
        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);
                }

                return(FindAudioBook(args, false));
            }

            if (AudioFileParser.IsAudioFile(args.Path, _namingOptions))
            {
                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 && VideoResolver.IsVideoFile(args.Path, _namingOptions))
                {
                    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);
        }