diff --git a/src/NzbDrone.Core/Indexers/IndexerBase.cs b/src/NzbDrone.Core/Indexers/IndexerBase.cs index 75717c1b5..cd123f4ad 100644 --- a/src/NzbDrone.Core/Indexers/IndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/IndexerBase.cs @@ -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); + } } }); diff --git a/src/NzbDrone.Core/Indexers/MagnetLinkBuilder.cs b/src/NzbDrone.Core/Indexers/MagnetLinkBuilder.cs index 5732c3dcf..a41d64b98 100644 --- a/src/NzbDrone.Core/Indexers/MagnetLinkBuilder.cs +++ b/src/NzbDrone.Core/Indexers/MagnetLinkBuilder.cs @@ -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; + } + } } }