1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-22 22:16:13 -04:00
Files
Sonarr/src/NzbDrone.Core/Indexers/SeedConfigProvider.cs
T
2024-12-01 16:15:52 -08:00

67 lines
2.0 KiB
C#

using System;
using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Indexers
{
public interface ISeedConfigProvider
{
TorrentSeedConfiguration GetSeedConfiguration(RemoteEpisode release);
TorrentSeedConfiguration GetSeedConfiguration(int indexerId, bool fullSeason);
}
public class SeedConfigProvider : ISeedConfigProvider
{
private readonly ICachedIndexerSettingsProvider _cachedIndexerSettingsProvider;
public SeedConfigProvider(ICachedIndexerSettingsProvider cachedIndexerSettingsProvider)
{
_cachedIndexerSettingsProvider = cachedIndexerSettingsProvider;
}
public TorrentSeedConfiguration GetSeedConfiguration(RemoteEpisode remoteEpisode)
{
if (remoteEpisode.Release.DownloadProtocol != DownloadProtocol.Torrent)
{
return null;
}
if (remoteEpisode.Release.IndexerId == 0)
{
return null;
}
return GetSeedConfiguration(remoteEpisode.Release.IndexerId, remoteEpisode.ParsedEpisodeInfo.FullSeason);
}
public TorrentSeedConfiguration GetSeedConfiguration(int indexerId, bool fullSeason)
{
if (indexerId == 0)
{
return null;
}
var settings = _cachedIndexerSettingsProvider.GetSettings(indexerId);
var seedCriteria = settings?.SeedCriteriaSettings;
if (seedCriteria == null)
{
return null;
}
var seedConfig = new TorrentSeedConfiguration
{
Ratio = seedCriteria.SeedRatio
};
var seedTime = fullSeason ? seedCriteria.SeasonPackSeedTime : seedCriteria.SeedTime;
if (seedTime.HasValue)
{
seedConfig.SeedTime = TimeSpan.FromMinutes(seedTime.Value);
}
return seedConfig;
}
}
}