Exemplo n.º 1
0
        public bool Rename(bool dryRun)
        {
            var files = renameService.GetFilesToProcess();

            fileOperatingService.RemoveUnwantedFiles(files, dryRun);

            var renamerResults    = renameService.ProcessBatch(files);
            var knownVideoResults = renameService.GetKnownVideoQualityResults();

            renamerResults = renameService.CheckForDuplicatesInResults(renamerResults);
            renamerResults = renameService.CheckForDuplicates(renamerResults, knownVideoResults);

            fileOperatingService.WriteJsonFromObject(renamerResults, $"rename_{DateTime.Now:yyMMdd_hh_mm}.json");
            fileOperatingService.MoveFilesBasedOnRenameResults(renamerResults, renameService.GetTargetPath(), dryRun);
            fileOperatingService.DeleteDirectories(renameService.GetEmptyDirectories(), dryRun);

            return(true);
        }
Exemplo n.º 2
0
        public void Execute(bool dryRun, DownloadClient?overrideActiveClient, int?backFillingActors, int?backFillingSites, int daysBack)
        {
            var client = options.ActiveClient;

            if (overrideActiveClient != null)
            {
                client = overrideActiveClient.GetValueOrDefault(DownloadClient.Sabnzbd);
            }

            PreFlightCheck(client);

            var resultList        = new List <UsenetRelease>();
            var knownVideosOnDisk = renameService.GetKnownVideoQualityResults();

            if (backFillingActors != null || backFillingSites != null)
            {
                if (backFillingActors != null)
                {
                    var usenetReleases = GetBackfillingActors(backFillingActors.GetValueOrDefault(0), knownVideosOnDisk, daysBack);
                    if (usenetReleases != null)
                    {
                        logger.LogInformation($"A total of {usenetReleases.Count}  actor-related releases were found.");
                        resultList.AddRange(usenetReleases);
                    }
                }

                if (backFillingSites != null)
                {
                    var usenetReleases = GetBackfillingSites(backFillingSites.GetValueOrDefault(0), knownVideosOnDisk, daysBack);
                    if (usenetReleases != null)
                    {
                        logger.LogInformation($"A total of {usenetReleases.Count}  site-related releases were found.");
                        resultList.AddRange(usenetReleases);
                    }
                }
            }
            else
            {
                var usenetReleases = GetLatestReleases();
                if (usenetReleases != null)
                {
                    resultList.AddRange(usenetReleases);
                }
            }

            if (resultList == null || resultList.Count == 0)
            {
                logger.LogError($"{resultList?.Count ?? -1} releases found. Exiting.");
                return;
            }

            logger.LogInformation($"A total of {resultList.Count} releases were found.");

            if (options.KeepOnlyHighestQuality)
            {
                resultList = KeepOnlyHighestQuality(resultList);
                // TODO: remove releases that are knownVideosOnDisk with higher quality:

                logger.LogInformation($"{resultList.Count} releases after Filter: keep only highest quality release.");
            }

            var excludeReleases = GetReleasesToExcludeFromDownloadClient(resultList, client);

            var excludeReleasesIds = excludeReleases.Select(x => x.Id);

            resultList.RemoveAll(x => excludeReleasesIds.Contains(x.Id));
            logger.LogInformation($"{resultList.Count} releases after Filter: Exclude active downloads Downloads - exlcuded {excludeReleases.Count}.");

            resultList = RemoveDuplicates(resultList);
            logger.LogInformation($"{resultList.Count} releases after Filter: remove duplicates.");

            logger.LogInformation($"-- List releases to add");


            if (client.Equals(DownloadClient.Nzbget))
            {
                foreach (var result in resultList)
                {
                    logger.LogInformation($"Add {result.Title} to download list (Id: {result.Id}, Indexer: {result.Indexer}, PID: {result.Video}).");
                    if (!dryRun)
                    {
                        var donwloadLink = GetDownloadLink(result);
                        logger.LogInformation($"Add to nzbget: {donwloadLink}");
                        nzbgetService.AddDownload(donwloadLink);
                    }
                }
            }
            else if (client.Equals(DownloadClient.Sabnzbd))
            {
                foreach (var result in resultList)
                {
                    logger.LogInformation($"Add {result.Title} to download list (Id: {result.Id}, Indexer: {result.Indexer}).");
                    if (!dryRun)
                    {
                        var donwloadLink = GetDownloadLink(result);
                        logger.LogInformation($"Add to sabnzbd: {donwloadLink}");
                        sabnzbdService.AddDownload(donwloadLink);
                    }
                }
            }
            else
            {
                throw new NotImplementedException();
            }
            logger.LogInformation($"-----------------------");
        }