mirror of
https://github.com/Radarr/Radarr
synced 2026-01-27 18:03:45 +01:00
Refactored logic.
This commit is contained in:
parent
151d7f4d52
commit
7293a2f4ed
4 changed files with 54 additions and 59 deletions
|
|
@ -21,6 +21,7 @@ public class Torrent
|
|||
public bool Scene { get; set; }
|
||||
public string Size { get; set; }
|
||||
public DateTime UploadTime { get; set; }
|
||||
public string RemasterTitle { get; set; }
|
||||
public string Snatched { get; set; }
|
||||
public string Seeders { get; set; }
|
||||
public string Leechers { get; set; }
|
||||
|
|
|
|||
|
|
@ -44,75 +44,61 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
|
|||
foreach (var torrent in result.Torrents)
|
||||
{
|
||||
var id = torrent.Id;
|
||||
var title = torrent.ReleaseName;
|
||||
|
||||
if (_settings.GoldenOnly)
|
||||
{
|
||||
if (torrent.GoldenPopcorn)
|
||||
{
|
||||
torrentInfos.Add(new TorrentInfo()
|
||||
{
|
||||
Guid = string.Format("PassThePopcorn-{0}", id),
|
||||
Title = torrent.ReleaseName,
|
||||
Size = Int64.Parse(torrent.Size),
|
||||
DownloadUrl = GetDownloadUrl(id, jsonResponse.AuthKey, jsonResponse.PassKey),
|
||||
InfoUrl = GetInfoUrl(result.GroupId, id),
|
||||
Seeders = Int32.Parse(torrent.Seeders),
|
||||
Peers = Int32.Parse(torrent.Leechers) + Int32.Parse(torrent.Seeders),
|
||||
PublishDate = torrent.UploadTime.ToUniversalTime(),
|
||||
Golden = torrent.GoldenPopcorn,
|
||||
Checked = torrent.Checked
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//if (IsPropertyExist(torrent, "RemasterTitle"))
|
||||
//{
|
||||
// title = string.Format("{0] - {1}", title, torrent.RemasterTitle);
|
||||
//}
|
||||
|
||||
if (_settings.CheckedOnly)
|
||||
{
|
||||
if (torrent.Checked)
|
||||
{
|
||||
torrentInfos.Add(new TorrentInfo()
|
||||
{
|
||||
Guid = string.Format("PassThePopcorn-{0}", id),
|
||||
Title = torrent.ReleaseName,
|
||||
Size = Int64.Parse(torrent.Size),
|
||||
DownloadUrl = GetDownloadUrl(id, jsonResponse.AuthKey, jsonResponse.PassKey),
|
||||
InfoUrl = GetInfoUrl(result.GroupId, id),
|
||||
Seeders = Int32.Parse(torrent.Seeders),
|
||||
Peers = Int32.Parse(torrent.Leechers) + Int32.Parse(torrent.Seeders),
|
||||
PublishDate = torrent.UploadTime.ToUniversalTime(),
|
||||
Golden = torrent.GoldenPopcorn,
|
||||
Checked = torrent.Checked
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_settings.GoldenOnly && !_settings.CheckedOnly)
|
||||
// Only add approved torrents
|
||||
if (_settings.Approved && torrent.Checked)
|
||||
{
|
||||
torrentInfos.Add(new TorrentInfo()
|
||||
{
|
||||
Guid = string.Format("PassThePopcorn-{0}", id),
|
||||
Title = torrent.ReleaseName,
|
||||
Size = Int64.Parse(torrent.Size),
|
||||
Title = title,
|
||||
Size = long.Parse(torrent.Size),
|
||||
DownloadUrl = GetDownloadUrl(id, jsonResponse.AuthKey, jsonResponse.PassKey),
|
||||
InfoUrl = GetInfoUrl(result.GroupId, id),
|
||||
Seeders = Int32.Parse(torrent.Seeders),
|
||||
Peers = Int32.Parse(torrent.Leechers) + Int32.Parse(torrent.Seeders),
|
||||
Seeders = int.Parse(torrent.Seeders),
|
||||
Peers = int.Parse(torrent.Leechers) + int.Parse(torrent.Seeders),
|
||||
PublishDate = torrent.UploadTime.ToUniversalTime(),
|
||||
Golden = torrent.GoldenPopcorn,
|
||||
Checked = torrent.Checked
|
||||
Scene = torrent.Scene,
|
||||
Approved = torrent.Checked
|
||||
});
|
||||
}
|
||||
// Add all torrents
|
||||
else if (!_settings.Approved)
|
||||
{
|
||||
torrentInfos.Add(new TorrentInfo()
|
||||
{
|
||||
Guid = string.Format("PassThePopcorn-{0}", id),
|
||||
Title = title,
|
||||
Size = long.Parse(torrent.Size),
|
||||
DownloadUrl = GetDownloadUrl(id, jsonResponse.AuthKey, jsonResponse.PassKey),
|
||||
InfoUrl = GetInfoUrl(result.GroupId, id),
|
||||
Seeders = int.Parse(torrent.Seeders),
|
||||
Peers = int.Parse(torrent.Leechers) + int.Parse(torrent.Seeders),
|
||||
PublishDate = torrent.UploadTime.ToUniversalTime(),
|
||||
Golden = torrent.GoldenPopcorn,
|
||||
Scene = torrent.Scene,
|
||||
Approved = torrent.Checked
|
||||
});
|
||||
}
|
||||
// Don't add any torrents
|
||||
else if (_settings.Approved && !torrent.Checked)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return torrentInfos.OrderBy(o => ((dynamic)o).Golden ? 0 : 1).ThenBy(o => ((dynamic)o).Checked ? 0 : 1).ThenBy(o => ((dynamic)o).PublishDate).ToArray();
|
||||
// prefer golden
|
||||
// prefer scene
|
||||
// require approval
|
||||
return torrentInfos.OrderBy(o => ((dynamic)o).Golden ? 0 : 1).ThenBy(o => ((dynamic)o).Scene ? 0 : 1).ThenByDescending(o => ((dynamic)o).PublishDate).ToArray();
|
||||
}
|
||||
|
||||
private string GetDownloadUrl(int torrentId, string authKey, string passKey)
|
||||
|
|
@ -135,7 +121,11 @@ private string GetInfoUrl(string groupId, int torrentId)
|
|||
.AddQueryParam("torrentid", torrentId);
|
||||
|
||||
return url.FullUri;
|
||||
}
|
||||
|
||||
public static bool IsPropertyExist(dynamic torrents, string name)
|
||||
{
|
||||
return torrents.GetType().GetProperty(name) != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,11 +35,14 @@ public PassThePopcornSettings()
|
|||
[FieldDefinition(1, Label = "Cookie", HelpText = "PassThePopcorn uses a login cookie needed to access the API, you'll have to retrieve it via a browser.")]
|
||||
public string Cookie { get; set; }
|
||||
|
||||
[FieldDefinition(2, Type = FieldType.Checkbox, Label = "Only Golden", HelpText = "Only include golden torrents.")]
|
||||
public bool GoldenOnly { get; set; }
|
||||
[FieldDefinition(2, Type = FieldType.Checkbox, Label = "Prefer Golden", HelpText = "Favors Golden Popcorn-releases over all other releases.")]
|
||||
public bool Golden { get; set; }
|
||||
|
||||
[FieldDefinition(3, Type = FieldType.Checkbox, Label = "Ony Staff Approved", HelpText = "Only include staff approved torrents.")]
|
||||
public bool CheckedOnly { get; set; }
|
||||
[FieldDefinition(3, Type = FieldType.Checkbox, Label = "Prefer Scene", HelpText = "Favors scene-releases over non-scene releases.")]
|
||||
public bool Scene { get; set; }
|
||||
|
||||
[FieldDefinition(4, Type = FieldType.Checkbox, Label = "Require Approved", HelpText = "Require staff-approval for releases to be accepted.")]
|
||||
public bool Approved { get; set; }
|
||||
|
||||
public NzbDroneValidationResult Validate()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ public class TorrentInfo : ReleaseInfo
|
|||
|
||||
// For PassThePopcorn
|
||||
public bool? Golden { get; set; }
|
||||
public bool? Checked { get; set; }
|
||||
public bool? Scene { get; set; }
|
||||
public bool? Approved { get; set; }
|
||||
|
||||
public static int? GetSeeders(ReleaseInfo release)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue