Fixed: (Cardigann) Magnet generation for public indexers with InfoHash

Fixes #668
pull/673/head
Qstick 3 years ago
parent 08c68e26c1
commit 6d62744667

@ -132,10 +132,25 @@ namespace NzbDrone.Core.Indexers
c.DownloadProtocol = Protocol;
c.IndexerPriority = ((IndexerDefinition)Definition).Priority;
//Add common flags
if (Protocol == DownloadProtocol.Torrent && ((TorrentInfo)c).DownloadVolumeFactor == 0)
if (Protocol == DownloadProtocol.Torrent)
{
c.IndexerFlags.Add(IndexerFlag.FreeLeech);
// generate magnet link from info hash (not allowed for private sites)
if (((TorrentInfo)c).MagnetUrl == null && !string.IsNullOrWhiteSpace(((TorrentInfo)c).InfoHash) && ((IndexerDefinition)Definition).Privacy != IndexerPrivacy.Private)
{
((TorrentInfo)c).MagnetUrl = MagnetLinkBuilder.BuildPublicMagnetLink(((TorrentInfo)c).InfoHash, c.Title);
}
// generate info hash from magnet link
if (((TorrentInfo)c).MagnetUrl != null && string.IsNullOrWhiteSpace(((TorrentInfo)c).InfoHash))
{
((TorrentInfo)c).InfoHash = MagnetLinkBuilder.GetInfoHashFromMagnet(((TorrentInfo)c).MagnetUrl);
}
//Add common flags
if (((TorrentInfo)c).DownloadVolumeFactor == 0)
{
((TorrentInfo)c).IndexerFlags.Add(IndexerFlag.FreeLeech);
}
}
});

@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTorrent;
using NzbDrone.Core.Parser;
namespace NzbDrone.Core.Indexers
{
@ -33,5 +36,18 @@ namespace NzbDrone.Core.Indexers
{
return new MagnetLink(InfoHash.FromHex(infoHash), releaseTitle, _trackers).ToV1String();
}
public static string GetInfoHashFromMagnet(string magnet)
{
try
{
var xt = ParseUtil.GetArgumentFromQueryString(magnet.ToString(), "xt");
return xt.Split(':').Last(); // remove prefix urn:btih:
}
catch (Exception)
{
return null;
}
}
}
}

Loading…
Cancel
Save