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); }
public List <KnownVideoQualityResult> GetKnownVideoQualityResults() { List <KnownVideoQualityResult> result = new List <KnownVideoQualityResult>(); string targetFolder = renameServiceOptions.TargetFolder; if (!Directory.Exists(targetFolder)) { logger.LogError($"Target directory {targetFolder} does not exist."); return(new List <KnownVideoQualityResult>()); } var files = Directory.EnumerateFiles(targetFolder, "*.*", SearchOption.AllDirectories).ToList(); foreach (var file in files) { Match match = Regex.Match(file, @"P([0-9]{7})", RegexOptions.IgnoreCase); if (match.Success) { string pdbIdString = match.Groups[1].Value; bool parsed = int.TryParse(pdbIdString, out var pdbId); if (parsed) { FileInfo fi = new FileInfo(file); result.Add(new KnownVideoQualityResult() { VideoId = pdbId, VideoQualityId = videoQualityProdiver.GetByName(StringExtractor.ExtractQuality(fi.Name))?.Id ?? 0 }); } } } return(result); }
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)); } } }
private List <UsenetRelease> GetBackfillingActors(int backFillingActors, List <KnownVideoQualityResult> knownVideosOnDisk, int daysBack) { var dateDaysBack = DateTime.Now.AddDays(-1 * daysBack); var favoriteActors = new List <Actor>(); if (backFillingActors == 0) { favoriteActors.AddRange(pdbApiService.GetFavoriteActors()); } else { favoriteActors.Add(new Actor() { Id = backFillingActors }); } var resultList = new List <UsenetRelease>(); var myIndexers = pdbApiService.GetMyIndexer(); var myIndexersInts = myIndexers.Select(x => x.Id).ToList(); foreach (var actor in favoriteActors) { var releases = pdbApiService.GetReleases(1, 5000, actor.Id, 0, ""); if (releases == null || !releases.Any()) { logger.LogError("No releases found"); continue; } var foundReleasess = releases.Where(x => (x.Actor1 == actor.Id || x.Actor2 == actor.Id) && myIndexersInts.Contains(x.Indexer) && x.Created >= dateDaysBack); foreach (var release in foundReleasess) { release.VideoQuality = videoQualityProdiver.GetByName(StringExtractor.ExtractQuality(release.Title)); if (!IsDuplicate(release, knownVideosOnDisk, resultList)) { logger.LogDebug($"Add {release.Title} to resultlist."); resultList.Add(release); } } logger.LogInformation($"{resultList.Count} releases added for actor id: {actor.Id}."); } return(resultList); }
private List <UsenetRelease> GetReleasesToExcludeFromSabnzbd(List <UsenetRelease> releases) { // All releases found in queue must be excluded from releases list List <UsenetRelease> excludeReleases = new List <UsenetRelease>(); var slots = sabnzbdService.GetQueue(0, 1000).Slots; foreach (var slot in slots) { var videoFound = videoMatching.GetVideoByName(slot.Filename); if (videoFound != null) { var quality = videoQualityProdiver.GetByName(StringExtractor.ExtractQuality(slot.Filename)); var releasesFound = releases .Where(x => x.Video == videoFound.Id && x.VideoQuality.Id == quality.Id).ToList(); if (releasesFound != null && releasesFound.Any()) { excludeReleases.AddRange(releasesFound); } } } var slotsHistory = sabnzbdService.GetHistory(0, 1000).Slots; foreach (var slot in slotsHistory) { var videoFound = videoMatching.GetVideoByName(slot.Name); if (videoFound != null) { var quality = videoQualityProdiver.GetByName(StringExtractor.ExtractQuality(slot.Name)); var releasesFound = releases .Where(x => x.Video == videoFound.Id && x.VideoQuality.Id == quality.Id).ToList(); if (releasesFound != null && releasesFound.Any()) { excludeReleases.AddRange(releasesFound); } } } return(excludeReleases); }
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); }
private List <UsenetRelease> GetReleasesToExcludeFromNzbget(List <UsenetRelease> releases) { // All releases found in queue must be excluded from releases list List <UsenetRelease> excludeReleases = new List <UsenetRelease>(); var queueEntries = nzbgetService.GetQueue(); if (queueEntries == null || queueEntries.Count == 0) { return(excludeReleases); } foreach (var queueEntry in queueEntries) { var videoFound = videoMatching.GetVideoByName(queueEntry.NzbName); if (videoFound != null) { var quality = videoQualityProdiver.GetByName(StringExtractor.ExtractQuality(queueEntry.NzbName)); if (quality == null) { logger.LogError("Quality not found for queue entry {nzbname}.", queueEntry.NzbName); continue; } var releasesFound = releases .Where(x => x.Video == videoFound.Id && x.VideoQuality.Id == quality.Id).ToList(); if (releasesFound != null && releasesFound.Any()) { excludeReleases.AddRange(releasesFound); } } } var historyEntries = nzbgetService.GetHistory(); if (historyEntries == null || historyEntries.Count == 0) { return(excludeReleases); } foreach (var historyEntry in historyEntries) { var videoFound = videoMatching.GetVideoByName(historyEntry.NzbName); if (videoFound != null) { var quality = videoQualityProdiver.GetByName(StringExtractor.ExtractQuality(historyEntry.NzbName)); if (quality == null) { logger.LogError("Quality not found for history entry {nzbname}.", historyEntry.NzbName); continue; } var releasesFound = releases .Where(x => x.Video == videoFound.Id && x.VideoQuality.Id == quality.Id).ToList(); if (releasesFound != null && releasesFound.Any()) { excludeReleases.AddRange(releasesFound); } } } return(excludeReleases); }