From 025156978b4bdade014ee61a6c274b506da18e38 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sat, 22 Apr 2023 03:13:56 +0300 Subject: [PATCH] Fixed: (AnimeBytes) Ignore useless extensions to improve single file names --- .../Indexers/Definitions/AnimeBytes.cs | 62 +++++++++++-------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/AnimeBytes.cs b/src/NzbDrone.Core/Indexers/Definitions/AnimeBytes.cs index 8a22b6005..b6d51a04d 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/AnimeBytes.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/AnimeBytes.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Globalization; +using System.IO; using System.Linq; using System.Net; using System.Text; @@ -223,8 +224,6 @@ namespace NzbDrone.Core.Indexers.Definitions public class AnimeBytesParser : IParseIndexerResponse { - private readonly AnimeBytesSettings _settings; - private static readonly HashSet ExcludedProperties = new (StringComparer.OrdinalIgnoreCase) { "Freeleech" }; private static readonly HashSet RemuxResolutions = new (StringComparer.OrdinalIgnoreCase) { "1080i", "1080p", "2160p", "4K" }; private static readonly HashSet CommonReleaseGroupsProperties = new (StringComparer.OrdinalIgnoreCase) @@ -234,6 +233,9 @@ namespace NzbDrone.Core.Indexers.Definitions "RAW", "Translated" }; + private static readonly HashSet ExcludedFileExtensions = new (StringComparer.OrdinalIgnoreCase) { ".mka", ".mds", ".md5", ".nfo", ".sfv", ".ass", ".mks", ".srt", ".ssa", ".sup", ".jpeg", ".jpg", ".png", ".otf", ".ttf" }; + + private readonly AnimeBytesSettings _settings; public AnimeBytesParser(AnimeBytesSettings settings) { @@ -497,35 +499,45 @@ namespace NzbDrone.Core.Indexers.Definitions var infoString = properties.Select(p => "[" + p + "]").Join(string.Empty); - if (_settings.UseFilenameForSingleEpisodes && torrent.FileCount == 1) + if (_settings.UseFilenameForSingleEpisodes) { - var fileName = torrent.Files.First().FileName; + var files = torrent.Files; - var guid = new Uri(details + "?nh=" + HashUtil.CalculateMd5(fileName)); + if (files.Count > 1) + { + files = files.Where(f => !ExcludedFileExtensions.Contains(Path.GetExtension(f.FileName))).ToList(); + } - var release = new TorrentInfo + if (files.Count == 1) { - MinimumRatio = 1, - MinimumSeedTime = minimumSeedTime, - Title = fileName, - InfoUrl = details.AbsoluteUri, - Guid = guid.AbsoluteUri, - DownloadUrl = link.AbsoluteUri, - PublishDate = publishDate, - Categories = categories, - Description = description, - Size = size, - Seeders = seeders, - Peers = peers, - Grabs = snatched, - Files = fileCount, - DownloadVolumeFactor = rawDownMultiplier, - UploadVolumeFactor = rawUpMultiplier, - }; + var fileName = files.First().FileName; - releaseInfos.Add(release); + var guid = new Uri(details + "?nh=" + HashUtil.CalculateMd5(fileName)); - continue; + var release = new TorrentInfo + { + MinimumRatio = 1, + MinimumSeedTime = minimumSeedTime, + Title = fileName, + InfoUrl = details.AbsoluteUri, + Guid = guid.AbsoluteUri, + DownloadUrl = link.AbsoluteUri, + PublishDate = publishDate, + Categories = categories, + Description = description, + Size = size, + Seeders = seeders, + Peers = peers, + Grabs = snatched, + Files = fileCount, + DownloadVolumeFactor = rawDownMultiplier, + UploadVolumeFactor = rawUpMultiplier, + }; + + releaseInfos.Add(release); + + continue; + } } foreach (var title in synonyms)