Пример #1
0
        private List <UsenetRelease> GetLatestReleases()
        {
            var knownVideosOnDisk = renameService.GetKnownVideoQualityResults();
            var favoriteSites     = options.DownloadFavoriteSites ? pdbApiService.GetFavoriteSites() : null;
            var favoriteActors    = options.DownloadFavoriteActors ? pdbApiService.GetFavoriteActors() : null;
            var releases          = pdbApiService.GetReleases(1, 1000, 0, 0, "");
            var myIndexers        = pdbApiService.GetMyIndexer();

            if (releases == null || !releases.Any())
            {
                logger.LogError("No releases found");
                return(null);
            }

            var resultList = new List <UsenetRelease>();

            foreach (var release in releases)
            {
                release.VideoQuality = videoQualityProdiver.GetByName(StringExtractor.ExtractQuality(release.Title));
                bool matchActor = favoriteActors != null && options.DownloadFavoriteActors && favoriteActors.Any(x => x.Id == release.Actor1 || x.Id == release.Actor2);
                bool matchSite  = favoriteSites != null && options.DownloadFavoriteSites && favoriteSites.Any(x => x.Id == release.Site);

                if (myIndexers.Any(x => x.Id == release.Indexer) && (matchActor || matchSite) && !IsDuplicate(release, knownVideosOnDisk, resultList))
                {
                    logger.LogDebug($"Add {release.Title} to resultlist.");
                    resultList.Add(release);
                }
            }
            logger.LogInformation($"{resultList.Count} releases found.");

            return(resultList);
        }
Пример #2
0
        private void ProcessBySite(Site site, List <Video> videos, string searchFolder, bool dryRun)
        {
            if (!Directory.Exists(searchFolder))
            {
                logger.LogError($"Directory {searchFolder} does not exist.");
                return;
            }

            var files = Directory.EnumerateFiles(searchFolder, "*.*", SearchOption.TopDirectoryOnly).ToList();

            foreach (var file in files)
            {
                Match match = Regex.Match(file, @"P([0-9]{7})", RegexOptions.IgnoreCase);

                if (!match.Success)
                {
                    continue;
                }

                int  videoQualityId = 0;
                bool parsed         = int.TryParse(match.Groups[1].Value, out var pdbId);
                if (!parsed)
                {
                    continue;
                }

                FileInfo fi = new FileInfo(file);
                videoQualityId = videoQualityProdiver.GetByName(StringExtractor.ExtractQuality(fi.Name))?.Id ?? 0;

                var video = videos.SingleOrDefault(x => x.Id == pdbId);
                if (video == null)
                {
                    logger.LogInformation($"Video info for id {pdbId} not found (in videos for site {site.Sitename}).");
                    continue;
                }

                string newFilename = renameService.ReplaceTemplatePlaceholders(renameServiceOptions.FilenameTemplate, new RenamerResult()
                {
                    Video          = video,
                    VideoQualityId = videoQualityId,
                    FileExtension  = fi.Extension,
                    Filename       = fi.Name,
                    Foldername     = searchFolder,
                    Source         = new SourceFile()
                    {
                        Filename      = fi.Name,
                        FileExtension = fi.Extension
                    }
                });

                logger.LogInformation($"Rename {fi.Name} to {newFilename}");
                if (!dryRun)
                {
                    File.Move(Path.Combine(searchFolder, fi.Name), Path.Combine(searchFolder, newFilename));
                }
            }
        }
Пример #3
0
        public List <RenamerResult> ProcessFiles(List <SourceFile> sourceFiles)
        {
            List <RenamerResult> resultList = new List <RenamerResult>();

            foreach (var sourceFile in sourceFiles)
            {
                var v = new RenamerResult()
                {
                    Source         = sourceFile,
                    Video          = null,
                    VideoQualityId = 0
                };

                if (!sourceFile.IsNoVideoExtension && !sourceFile.IsToSmall)
                {
                    var titleAndSite = GetRelevantTitleAndSite(sourceFile.Filename, sourceFile.Foldername);
                    if (titleAndSite != null)
                    {
                        var title = titleAndSite.Item1;
                        var site  = titleAndSite.Item2;

                        logger.LogDebug($"Next GetVideoByFilename for {title} - Site: {site.Sitename}");
                        Video video = GetVideoByFilename(title, site);
                        logger.LogDebug($"Result GetVideoByFilename: {video?.Title ?? ""}");
                        if (video != null)
                        {
                            v.Video          = video;
                            v.VideoQualityId = videoQualityProdiver.GetByName(StringExtractor.ExtractQuality(title))?.Id ?? 0;
                        }
                    }
                }

                resultList.Add(v);
            }

            return(resultList);
        }