From 858ef530d0938ff356f18bf81b4c26b7560c466a Mon Sep 17 00:00:00 2001 From: Diego Heras Date: Mon, 2 Nov 2020 18:01:06 +0100 Subject: [PATCH] assorted c#: auto generate magnet links from info hash (#10090) #8590 #10087 --- .../Indexers/DarmoweTorrenty.cs | 7 +-- .../Indexers/InternetArchive.cs | 18 +------- src/Jackett.Common/Indexers/ThePirateBay.cs | 28 +++-------- src/Jackett.Common/Indexers/TorrentsCSV.cs | 46 ++----------------- src/Jackett.Common/Indexers/YTS.cs | 15 +----- 5 files changed, 13 insertions(+), 101 deletions(-) diff --git a/src/Jackett.Common/Indexers/DarmoweTorrenty.cs b/src/Jackett.Common/Indexers/DarmoweTorrenty.cs index 6ebd16269..818351898 100644 --- a/src/Jackett.Common/Indexers/DarmoweTorrenty.cs +++ b/src/Jackett.Common/Indexers/DarmoweTorrenty.cs @@ -171,10 +171,7 @@ namespace Jackett.Common.Indexers var detailsLink = new Uri(SiteLink + details.GetAttribute("href")); var encodedDownloadLink = detailsRow.QuerySelector("a[id^=\"download_\"]").GetAttribute("data-href"); var siteDownloadLink = new Uri(SiteLink + Uri.UnescapeDataString(StringUtil.FromBase64(encodedDownloadLink))); - var hash = HttpUtility.ParseQueryString(siteDownloadLink.Query)["id"]; - var magnet = - $"magnet:?xt=urn:btih:{hash}&tr=udp://tracker.opentrackr.org:1337&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://tracker.internetwarriors.net:1337&tr=udp://tracker.leechers-paradise.org:6969"; - var downloadLink = new Uri(magnet); + var infoHash = HttpUtility.ParseQueryString(siteDownloadLink.Query)["id"]; var bannerLink = detailsRow.QuerySelector("img[src^=\"./imgtorrent/\"]")?.GetAttribute("src"); var seeders = seedsMatch.Success ? int.Parse(seedsMatch.Groups[1].Value) : 0; var leechers = leechersMatch.Success ? int.Parse(leechersMatch.Groups[1].Value) : 0; @@ -189,7 +186,7 @@ namespace Jackett.Common.Indexers PublishDate = date, DownloadVolumeFactor = 0, UploadVolumeFactor = 1, - Link = downloadLink, + InfoHash = infoHash, // magnet link is auto generated from infohash Guid = detailsLink, Comments = detailsLink, Size = sizeMatch.Success ? ReleaseInfo.GetBytes(sizeMatch.Groups[1].Value) : 0 diff --git a/src/Jackett.Common/Indexers/InternetArchive.cs b/src/Jackett.Common/Indexers/InternetArchive.cs index 6302e4077..c7d135794 100644 --- a/src/Jackett.Common/Indexers/InternetArchive.cs +++ b/src/Jackett.Common/Indexers/InternetArchive.cs @@ -26,15 +26,6 @@ namespace Jackett.Common.Indexers private string CommentsUrl => SiteLink + "details/"; private string LinkUrl => SiteLink + "download/"; - private readonly NameValueCollection _trackers = new NameValueCollection - { - {"tr", "udp://tracker.coppersurfer.tk:6969/announce"}, - {"tr", "udp://tracker.leechers-paradise.org:6969/announce"}, - {"tr", "udp://tracker.opentrackr.org:1337/announce"}, - {"tr", "udp://tracker.internetwarriors.net:1337/announce"}, - {"tr", "udp://open.demonii.si:1337/announce"} - }; - private string _sort; private string _order; private bool _titleOnly; @@ -206,8 +197,7 @@ namespace Jackett.Common.Indexers Peers = 2, Grabs = GetFieldAs("downloads", torrent), Link = link, - MagnetUri = GenerateMagnetLink(btih, title), - InfoHash = btih, + InfoHash = btih, // magnet link is auto generated from infohash DownloadVolumeFactor = 0, UploadVolumeFactor = 1 }; @@ -215,12 +205,6 @@ namespace Jackett.Common.Indexers return release; } - private Uri GenerateMagnetLink(string btih, string title) - { - _trackers.Set("dn", title); - return new Uri("magnet:?xt=urn:btih:" + btih + "&" + _trackers.GetQueryString()); - } - private static T GetFieldAs(string field, JToken torrent) => torrent[field] is JArray array ? array.First.ToObject() : torrent.Value(field); } diff --git a/src/Jackett.Common/Indexers/ThePirateBay.cs b/src/Jackett.Common/Indexers/ThePirateBay.cs index 46be31664..a7226091f 100644 --- a/src/Jackett.Common/Indexers/ThePirateBay.cs +++ b/src/Jackett.Common/Indexers/ThePirateBay.cs @@ -53,19 +53,8 @@ namespace Jackett.Common.Indexers "https://tpb18.ukpass.co/" }; - private const string KeyInfoHash = "{info_hash}"; - private static readonly Uri _ApiBaseUri = new Uri("https://apibay.org/"); - private static readonly string _MagnetUri = - $"magnet:?xt=urn:btih:{KeyInfoHash}&tr=udp%3A%2F%2Ftracker.coppersurfer.tk" + - "%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2920%2Fannounce&tr=udp%3" + - "A%2F%2Ftracker.opentrackr.org%3A1337&tr=udp%3A%2F%2Ftracker.internetwar" + - "riors.net%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.or" + - "g%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fann" + - "ounce&tr=udp%3A%2F%2Ftracker.pirateparty.gr%3A6969%2Fannounce&tr=udp%3A" + - "%2F%2Ftracker.cyberia.is%3A6969%2Fannounce"; - public ThePirateBay( IIndexerConfigurationService configService, WebClient client, @@ -224,28 +213,23 @@ namespace Jackett.Common.Indexers private ReleaseInfo CreateReleaseInfo(QueryResponseItem item) { - var magnetUri = new Uri(_MagnetUri.Replace(KeyInfoHash, item.InfoHash)); - + var commentsUri = item.Id == 0 ? null : new Uri($"{SiteLink}description.php?id={item.Id}"); + var imdbId = string.IsNullOrEmpty(item.Imdb) ? null : ParseUtil.GetImdbID(item.Imdb); return new ReleaseInfo { Title = item.Name, Category = MapTrackerCatToNewznab(item.Category.ToString()), - Comments = item.Id == 0 - ? null - : new Uri($"{SiteLink}description.php?id={item.Id}"), - MagnetUri = magnetUri, - InfoHash = item.InfoHash, + Guid = commentsUri, + Comments = commentsUri, + InfoHash = item.InfoHash, // magnet link is auto generated from infohash PublishDate = DateTimeUtil.UnixTimestampToDateTime(item.Added), - Guid = magnetUri, Seeders = item.Seeders, Peers = item.Seeders + item.Leechers, Size = item.Size, Files = item.NumFiles, DownloadVolumeFactor = 0, UploadVolumeFactor = 1, - Imdb = string.IsNullOrEmpty(item.Imdb) - ? null - : ParseUtil.GetImdbID(item.Imdb) + Imdb = imdbId }; } diff --git a/src/Jackett.Common/Indexers/TorrentsCSV.cs b/src/Jackett.Common/Indexers/TorrentsCSV.cs index b82b295d6..8a77b1980 100644 --- a/src/Jackett.Common/Indexers/TorrentsCSV.cs +++ b/src/Jackett.Common/Indexers/TorrentsCSV.cs @@ -112,58 +112,18 @@ namespace Jackett.Common.Indexers var seeders = torrent.Value("seeders"); var leechers = torrent.Value("leechers"); var grabs = ParseUtil.CoerceInt(torrent.Value("completed") ?? "0"); - var infohash = torrent.Value("infohash").ToString(); + var infoHash = torrent.Value("infohash").ToString(); // convert unix timestamp to human readable date var publishDate = new DateTime(1970, 1, 1, 0, 0, 0, 0); publishDate = publishDate.AddSeconds(torrent.Value("created_unix")); - // construct magnet link from infohash with public trackers - // TODO move trackers to List for reuse elsewhere - // TODO dynamically generate list periodically from online tracker repositories like - // https://github.com/ngosang/trackerslist - var magnet = new Uri("magnet:?xt=urn:btih:" + infohash + - "&tr=udp://tracker.coppersurfer.tk:6969/announce" + - "&tr=udp://tracker.leechers-paradise.org:6969/announce" + - "&tr=udp://tracker.internetwarriors.net:1337/announce" + - "&tr=udp://tracker.opentrackr.org:1337/announce" + - "&tr=udp://9.rarbg.to:2710/announce" + - "&tr=udp://exodus.desync.com:6969/announce" + - "&tr=udp://explodie.org:6969/announce" + - "&tr=udp://tracker2.itzmx.com:6961/announce" + - "&tr=udp://tracker1.itzmx.com:8080/announce" + - "&tr=udp://tracker.torrent.eu.org:451/announce" + - "&tr=udp://tracker.tiny-vps.com:6969/announce" + - "&tr=udp://tracker.port443.xyz:6969/announce" + - "&tr=udp://thetracker.org:80/announce" + - "&tr=udp://open.stealth.si:80/announce" + - "&tr=udp://open.demonii.si:1337/announce" + - "&tr=udp://ipv4.tracker.harry.lu:80/announce" + - "&tr=udp://denis.stalker.upeer.me:6969/announce" + - "&tr=udp://tracker1.wasabii.com.tw:6969/announce" + - "&tr=udp://tracker.dler.org:6969/announce" + - "&tr=udp://tracker.cyberia.is:6969/announce" + - "&tr=udp://tracker4.itzmx.com:2710/announce" + - "&tr=udp://tracker.uw0.xyz:6969/announce" + - "&tr=udp://tracker.moeking.me:6969/announce" + - "&tr=udp://retracker.lanta-net.ru:2710/announce" + - "&tr=udp://tracker.nyaa.uk:6969/announce" + - "&tr=udp://tracker.novg.net:6969/announce" + - "&tr=udp://tracker.iamhansen.xyz:2000/announce" + - "&tr=udp://tracker.filepit.to:6969/announce" + - "&tr=udp://tracker.dyn.im:6969/announce" + - "&tr=udp://torrentclub.tech:6969/announce" + - "&tr=udp://tracker.tvunderground.org.ru:3218/announce" + - "&tr=udp://tracker.open-tracker.org:1337/announce" + - "&tr=udp://tracker.justseed.it:1337/announce"); - var release = new ReleaseInfo { Title = title, Comments = new Uri(SiteLink), // there is no comments or details link - Guid = magnet, - MagnetUri = magnet, - InfoHash = infohash, + Guid = new Uri($"magnet:?xt=urn:btih:{infoHash}"), + InfoHash = infoHash, // magnet link is auto generated from infohash Category = new List { TorznabCatType.Other.ID }, PublishDate = publishDate, Size = size, diff --git a/src/Jackett.Common/Indexers/YTS.cs b/src/Jackett.Common/Indexers/YTS.cs index 64a5faaa7..52f74cdf0 100644 --- a/src/Jackett.Common/Indexers/YTS.cs +++ b/src/Jackett.Common/Indexers/YTS.cs @@ -154,20 +154,7 @@ namespace Jackett.Common.Indexers var imdb = movie_item.Value("imdb_code"); release.Imdb = ParseUtil.GetImdbID(imdb); - // API does not provide magnet link, so, construct it - var magnet_uri = "magnet:?xt=urn:btih:" + torrent_info.Value("hash") + - "&dn=" + movie_item.Value("slug") + - "&tr=udp://open.demonii.com:1337/announce" + - "&tr=udp://tracker.openbittorrent.com:80" + - "&tr=udp://tracker.coppersurfer.tk:6969" + - "&tr=udp://glotorrents.pw:6969/announce" + - "&tr=udp://tracker.opentrackr.org:1337/announce" + - "&tr=udp://torrent.gresille.org:80/announce" + - "&tr=udp://p4p.arenabg.com:1337" + - "&tr=udp://tracker.leechers-paradise.org:6969"; - - release.MagnetUri = new Uri(magnet_uri); - release.InfoHash = torrent_info.Value("hash"); + release.InfoHash = torrent_info.Value("hash"); // magnet link is auto generated from infohash // ex: 2015-08-16 21:25:08 +0000 var dateStr = torrent_info.Value("date_uploaded");