Skip to content

Commit

Permalink
New: (Torznab) Add `magneturl' attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
mynameisbogdan committed Sep 10, 2023
1 parent 0463e66 commit 1d345b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/NzbDrone.Core/IndexerSearch/NewznabResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public string ToXml(DownloadProtocol protocol)
r.InfoUrl == null ? null : new XElement("comments", r.InfoUrl),
r.PublishDate == DateTime.MinValue ? new XElement("pubDate", XmlDateFormat(DateTime.Now)) : new XElement("pubDate", XmlDateFormat(r.PublishDate)),
new XElement("size", r.Size),
new XElement("link", r.DownloadUrl ?? t.MagnetUrl ?? string.Empty),
new XElement("link", r.DownloadUrl ?? string.Empty),
r.Categories == null ? null : from c in r.Categories select new XElement("category", c.Id),
new XElement(
"enclosure",
Expand Down Expand Up @@ -115,6 +115,7 @@ public string ToXml(DownloadProtocol protocol)
GetNabElement("label", RemoveInvalidXMLChars(r.Label), protocol),
GetNabElement("track", RemoveInvalidXMLChars(r.Track), protocol),
GetNabElement("infohash", RemoveInvalidXMLChars(t.InfoHash), protocol),
GetNabElement("magneturl", t.MagnetUrl, protocol),
GetNabElement("minimumratio", t.MinimumRatio, protocol),
GetNabElement("minimumseedtime", t.MinimumSeedTime, protocol),
GetNabElement("downloadvolumefactor", t.DownloadVolumeFactor, protocol),
Expand Down
6 changes: 4 additions & 2 deletions src/Prowlarr.Api.V1/Indexers/NewznabController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,11 @@ public async Task<IActionResult> GetNewznabResponse(int id, [FromQuery] NewznabR
{
result.DownloadUrl = result.DownloadUrl.IsNotNullOrWhiteSpace() ? _downloadMappingService.ConvertToProxyLink(new Uri(result.DownloadUrl), request.server, indexerDef.Id, result.Title).AbsoluteUri : null;

if (result.DownloadProtocol == DownloadProtocol.Torrent)
if (result.DownloadProtocol == DownloadProtocol.Torrent &&
result is TorrentInfo torrentRelease &&
torrentRelease.MagnetUrl.IsNotNullOrWhiteSpace())
{
((TorrentInfo)result).MagnetUrl = ((TorrentInfo)result).MagnetUrl.IsNotNullOrWhiteSpace() ? _downloadMappingService.ConvertToProxyLink(new Uri(((TorrentInfo)result).MagnetUrl), request.server, indexerDef.Id, result.Title).AbsoluteUri : null;
result.DownloadUrl ??= _downloadMappingService.ConvertToProxyLink(new Uri(torrentRelease.MagnetUrl), request.server, indexerDef.Id, torrentRelease.Title).AbsoluteUri;
}
}

Expand Down

0 comments on commit 1d345b9

Please sign in to comment.