Exemplo n.º 1
0
        private int?GetSeasonNumberFromEpisodeFile(string path)
        {
            var result = new EpisodeResolver(_namingOptions)
                         .Resolve(path, false);

            return(result.SeasonNumber);
        }
Exemplo n.º 2
0
        // TODO: [InlineData(@"Seinfeld/Seinfeld 0807 The Checks.avi", 8)]
        public void GetSeasonNumberFromEpisodeFileTest(string path, int?expected)
        {
            var result = new EpisodeResolver(_namingOptions)
                         .Resolve(path, false);

            Assert.Equal(expected, result?.SeasonNumber);
        }
Exemplo n.º 3
0
        public void Resolve_GivenVideoInExtrasFolder_DoesNotResolveToEpisode()
        {
            var season = new Season {
                Name = "Season 1"
            };
            var parent = new Folder {
                Name = "extras"
            };
            var libraryManagerMock = new Mock <ILibraryManager>();

            libraryManagerMock.Setup(x => x.GetItemById(It.IsAny <Guid>())).Returns(season);

            var episodeResolver = new EpisodeResolver(libraryManagerMock.Object);
            var itemResolveArgs = new ItemResolveArgs(
                Mock.Of <IServerApplicationPaths>(),
                Mock.Of <IDirectoryService>())
            {
                Parent         = parent,
                CollectionType = CollectionType.TvShows,
                FileInfo       = new FileSystemMetadata()
                {
                    FullName = "All My Children/Season 01/Extras/All My Children S01E01 - Behind The Scenes.mkv"
                }
            };

            Assert.Null(episodeResolver.Resolve(itemResolveArgs));
        }
Exemplo n.º 4
0
        public void EpisodeResolverTest_WrongExtensionStub()
        {
            var res = new EpisodeResolver(_namingOptions).Resolve("dvd.disc", false);

            Assert.NotNull(res);
            Assert.True(res !.IsStub);
        }
        private int?GetEpisodeNumberFromFile(string path)
        {
            var options = new NamingOptions();

            var result = new EpisodeResolver(options)
                         .Resolve(path, false);

            return(result.EpisodeNumber);
        }
Exemplo n.º 6
0
        public void GetEpisodeNumberFromFileTest(string path, int episodeNumber)
        {
            var options = new NamingOptions();

            var result = new EpisodeResolver(options)
                         .Resolve(path, false, null, null, true);

            Assert.Equal(episodeNumber, result.EpisodeNumber);
        }
        private int?GetEpisodeNumberFromFile(string path)
        {
            var options = new ExtendedNamingOptions();

            var result = new EpisodeResolver(options, new RegexProvider())
                         .Resolve(path, false);

            return(result.EpisodeNumber);
        }
Exemplo n.º 8
0
        private void Test(string path, string seriesName, int?seasonNumber, int?episodeNumber)
        {
            var options = new NamingOptions();

            var result = new EpisodeResolver(options)
                         .Resolve(path, false);

            Assert.AreEqual(seasonNumber, result.SeasonNumber);
            Assert.AreEqual(episodeNumber, result.EpisodeNumber);
            Assert.AreEqual(seriesName, result.SeriesName, true, CultureInfo.InvariantCulture);
        }
Exemplo n.º 9
0
        // TODO: [Theory]
        // TODO: [InlineData(@"/server/anything_ep02.mp4", "anything", null, 2)]
        // TODO: [InlineData(@"/server/anything_ep_02.mp4", "anything", null, 2)]
        // TODO: [InlineData(@"/server/anything_part.II.mp4", "anything", null, null)]
        // TODO: [InlineData(@"/server/anything_pt.II.mp4", "anything", null, null)]
        // TODO: [InlineData(@"/server/anything_pt_II.mp4", "anything", null, null)]
        public void Test(string path, string seriesName, int?seasonNumber, int?episodeNumber)
        {
            var options = new NamingOptions();

            var result = new EpisodeResolver(options)
                         .Resolve(path, false);

            Assert.Equal(seasonNumber, result?.SeasonNumber);
            Assert.Equal(episodeNumber, result?.EpisodeNumber);
            Assert.Equal(seriesName, result?.SeriesName, ignoreCase: true);
        }
Exemplo n.º 10
0
        // TODO: [InlineData(@"/server/anything_14.11.1996.mp4", "anything", 1996, 11, 14)]
        // TODO: [InlineData(@"/server/A Daily Show - (2015-01-15) - Episode Name - [720p].mkv", "A Daily Show", 2015, 01, 15)]
        // TODO: [InlineData(@"/server/Last Man Standing_KTLADT_2018_05_25_01_28_00.wtv", "Last Man Standing", 2018, 05, 25)]
        public void Test(string path, string seriesName, int?year, int?month, int?day)
        {
            var options = new NamingOptions();

            var result = new EpisodeResolver(options)
                         .Resolve(path, false);

            Assert.Null(result?.SeasonNumber);
            Assert.Null(result?.EpisodeNumber);
            Assert.Equal(year, result?.Year);
            Assert.Equal(month, result?.Month);
            Assert.Equal(day, result?.Day);
            Assert.Equal(seriesName, result?.SeriesName, true);
        }
Exemplo n.º 11
0
        private void Test(string path, string seriesName, int?year, int?month, int?day)
        {
            var options = new NamingOptions();

            var result = new EpisodeResolver(options, new RegexProvider())
                         .Resolve(path, false);

            Assert.IsNull(result.SeasonNumber);
            Assert.IsNull(result.EpisodeNumber);
            Assert.AreEqual(year, result.Year);
            Assert.AreEqual(month, result.Month);
            Assert.AreEqual(day, result.Day);
            //Assert.AreEqual(seriesName, result.SeriesName, true, CultureInfo.InvariantCulture);
        }
Exemplo n.º 12
0
        private void Test(string path, string seriesName, int?seasonNumber, int?episodeNumber, int?episodeEndNumber)
        {
            var options = new NamingOptions();

            var result = new EpisodeResolver(options)
                         .Resolve(path, false);

            Assert.NotNull(result);
            Assert.Equal(seasonNumber, result?.SeasonNumber);
            Assert.Equal(episodeNumber, result?.EpisodeNumber);
            Assert.Equal(seriesName, result?.SeriesName, true);
            Assert.Equal(path, result?.Path);
            Assert.Equal(Path.GetExtension(path).Substring(1), result?.Container);
            Assert.Null(result?.Format3D);
            Assert.False(result?.Is3D);
            Assert.False(result?.IsStub);
            Assert.Null(result?.StubType);
            Assert.Equal(episodeEndNumber, result?.EndingEpisodeNumber);
            Assert.False(result?.IsByDate);
        }
Exemplo n.º 13
0
        public void Resolve_GivenVideoInExtrasFolder_DoesNotResolveToEpisode()
        {
            var parent = new Folder {
                Name = "extras"
            };

            var episodeResolver = new EpisodeResolver(null);
            var itemResolveArgs = new ItemResolveArgs(
                Mock.Of <IServerApplicationPaths>(),
                Mock.Of <IDirectoryService>())
            {
                Parent         = parent,
                CollectionType = CollectionType.TvShows,
                FileInfo       = new FileSystemMetadata
                {
                    FullName = "All My Children/Season 01/Extras/All My Children S01E01 - Behind The Scenes.mkv"
                }
            };

            Assert.Null(episodeResolver.Resolve(itemResolveArgs));
        }
Exemplo n.º 14
0
        public async Task <FileOrganizationResult> OrganizeEpisodeFile(string path, AutoOrganizeOptions options, bool overwriteExisting, CancellationToken cancellationToken)
        {
            _logger.Info("Sorting file {0}", path);

            var result = new FileOrganizationResult
            {
                Date             = DateTime.UtcNow,
                OriginalPath     = path,
                OriginalFileName = Path.GetFileName(path),
                Type             = FileOrganizerType.Episode,
                FileSize         = _fileSystem.GetFileInfo(path).Length
            };

            try
            {
                if (_libraryMonitor.IsPathLocked(path))
                {
                    result.Status        = FileSortingStatus.Failure;
                    result.StatusMessage = "Path is locked by other processes. Please try again later.";
                    return(result);
                }

                var namingOptions = GetNamingOptionsInternal();
                var resolver      = new EpisodeResolver(namingOptions);

                var episodeInfo = resolver.Resolve(path, false) ??
                                  new Emby.Naming.TV.EpisodeInfo();

                var seriesName = episodeInfo.SeriesName;

                if (!string.IsNullOrEmpty(seriesName))
                {
                    var seasonNumber = episodeInfo.SeasonNumber;

                    result.ExtractedSeasonNumber = seasonNumber;

                    // Passing in true will include a few extra regex's
                    var episodeNumber = episodeInfo.EpisodeNumber;

                    result.ExtractedEpisodeNumber = episodeNumber;

                    var premiereDate = episodeInfo.IsByDate ?
                                       new DateTime(episodeInfo.Year.Value, episodeInfo.Month.Value, episodeInfo.Day.Value) :
                                       (DateTime?)null;

                    if (episodeInfo.IsByDate || (seasonNumber.HasValue && episodeNumber.HasValue))
                    {
                        if (episodeInfo.IsByDate)
                        {
                            _logger.Debug("Extracted information from {0}. Series name {1}, Date {2}", path, seriesName, premiereDate.Value);
                        }
                        else
                        {
                            _logger.Debug("Extracted information from {0}. Series name {1}, Season {2}, Episode {3}", path, seriesName, seasonNumber, episodeNumber);
                        }

                        var endingEpisodeNumber = episodeInfo.EndingEpsiodeNumber;

                        result.ExtractedEndingEpisodeNumber = endingEpisodeNumber;

                        await OrganizeEpisode(path,
                                              seriesName,
                                              seasonNumber,
                                              episodeNumber,
                                              endingEpisodeNumber,
                                              premiereDate,
                                              options,
                                              overwriteExisting,
                                              false,
                                              result,
                                              cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        var msg = string.Format("Unable to determine episode number from {0}", path);
                        result.Status        = FileSortingStatus.Failure;
                        result.StatusMessage = msg;
                        _logger.Warn(msg);
                    }
                }
                else
                {
                    var msg = string.Format("Unable to determine series name from {0}", path);
                    result.Status        = FileSortingStatus.Failure;
                    result.StatusMessage = msg;
                    _logger.Warn(msg);
                }

                var previousResult = _organizationService.GetResultBySourcePath(path);

                if (previousResult != null)
                {
                    // Don't keep saving the same result over and over if nothing has changed
                    if (previousResult.Status == result.Status && previousResult.StatusMessage == result.StatusMessage && result.Status != FileSortingStatus.Success)
                    {
                        return(previousResult);
                    }
                }

                await _organizationService.SaveResult(result, CancellationToken.None).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                result.Status        = FileSortingStatus.Failure;
                result.StatusMessage = ex.Message;
            }

            return(result);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Organize an episode file.
        /// </summary>
        /// <param name="path">The path to the episode file.</param>
        /// <param name="options">The options to use for organizing the file.</param>
        /// <param name="cancellationToken">Cancellation token for the operation.</param>
        /// <returns>A task representing the file organization operation and containing the operation result.</returns>
        public async Task <FileOrganizationResult> OrganizeEpisodeFile(
            string path,
            TvFileOrganizationOptions options,
            CancellationToken cancellationToken)
        {
            _logger.LogInformation("Sorting file {0}", path);

            var result = new FileOrganizationResult
            {
                Date             = DateTime.UtcNow,
                OriginalPath     = path,
                OriginalFileName = Path.GetFileName(path),
                Type             = FileOrganizerType.Unknown,
                FileSize         = _fileSystem.GetFileInfo(path).Length
            };

            try
            {
                if (_libraryMonitor.IsPathLocked(path))
                {
                    result.Status        = FileSortingStatus.Failure;
                    result.StatusMessage = "Path is locked by other processes. Please try again later.";
                    _logger.LogInformation("Auto-organize Path is locked by other processes. Please try again later.");
                    return(result);
                }

                var namingOptions = GetNamingOptionsInternal();
                var resolver      = new EpisodeResolver(namingOptions);

                var episodeInfo = resolver.Resolve(path, false) ??
                                  new Naming.TV.EpisodeInfo(string.Empty);

                var seriesName = episodeInfo.SeriesName;
                int?seriesYear = null;

                if (!string.IsNullOrEmpty(seriesName))
                {
                    var seriesParseResult = _libraryManager.ParseName(seriesName);

                    seriesName = seriesParseResult.Name;
                    seriesYear = seriesParseResult.Year;
                }

                if (string.IsNullOrWhiteSpace(seriesName))
                {
                    seriesName = episodeInfo.SeriesName;
                }

                if (!string.IsNullOrEmpty(seriesName))
                {
                    var seasonNumber = episodeInfo.SeasonNumber;

                    result.ExtractedSeasonNumber = seasonNumber;

                    // Passing in true will include a few extra regex's
                    var episodeNumber = episodeInfo.EpisodeNumber;

                    result.ExtractedEpisodeNumber = episodeNumber;

                    var premiereDate = episodeInfo.IsByDate ?
                                       new DateTime(episodeInfo.Year.Value, episodeInfo.Month.Value, episodeInfo.Day.Value) :
                                       (DateTime?)null;

                    if (episodeInfo.IsByDate || (seasonNumber.HasValue && episodeNumber.HasValue))
                    {
                        if (episodeInfo.IsByDate)
                        {
                            _logger.LogDebug("Extracted information from {0}. Series name {1}, Date {2}", path, seriesName, premiereDate.Value);
                        }
                        else
                        {
                            _logger.LogDebug("Extracted information from {0}. Series name {1}, Season {2}, Episode {3}", path, seriesName, seasonNumber, episodeNumber);
                        }

                        // We detected an airdate or (an season number and an episode number)
                        // We have all the chance that the media type is an Episode
                        // if an earlier result exist with an different type, we update it
                        result.Type = CurrentFileOrganizerType;

                        var endingEpisodeNumber = episodeInfo.EndingEpisodeNumber;

                        result.ExtractedEndingEpisodeNumber = endingEpisodeNumber;

                        await OrganizeEpisode(
                            path,
                            seriesName,
                            seriesYear,
                            seasonNumber,
                            episodeNumber,
                            endingEpisodeNumber,
                            premiereDate,
                            options,
                            false,
                            result,
                            cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        var msg = "Unable to determine episode number from " + path;
                        result.Status        = FileSortingStatus.Failure;
                        result.StatusMessage = msg;
                        _logger.LogWarning(msg);
                    }
                }
                else
                {
                    var msg = "Unable to determine series name from " + path;
                    result.Status        = FileSortingStatus.Failure;
                    result.StatusMessage = msg;
                    _logger.LogWarning(msg);
                }

                // Handle previous result
                var previousResult = _organizationService.GetResultBySourcePath(path);

                if ((previousResult != null && result.Type == FileOrganizerType.Unknown) || (previousResult?.Status == result.Status &&
                                                                                             previousResult?.StatusMessage == result.StatusMessage &&
                                                                                             result.Status != FileSortingStatus.Success))
                {
                    // Don't keep saving the same result over and over if nothing has changed
                    return(previousResult);
                }
            }
            catch (OrganizationException ex)
            {
                result.Status        = FileSortingStatus.Failure;
                result.StatusMessage = ex.Message;
            }
            catch (Exception ex)
            {
                result.Status        = FileSortingStatus.Failure;
                result.StatusMessage = ex.Message;
                _logger.LogError(ex, "Error organizing file");
            }

            _organizationService.SaveResult(result, CancellationToken.None);

            return(result);
        }
Exemplo n.º 16
0
        public void EpisodeResolverTest_WrongExtension()
        {
            var res = new EpisodeResolver(_namingOptions).Resolve("test.mp3", false);

            Assert.Null(res);
        }