1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2025-03-06 11:48:49 +00:00

assorted c#: auto generate magnet links from info hash (#10090)

#8590 #10087
This commit is contained in:
Diego Heras 2020-11-02 18:01:06 +01:00 committed by GitHub
parent 14fdea164c
commit 858ef530d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 101 deletions

View file

@ -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

View file

@ -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<long>("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<T>(string field, JToken torrent) =>
torrent[field] is JArray array ? array.First.ToObject<T>() : torrent.Value<T>(field);
}

View file

@ -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
};
}

View file

@ -112,58 +112,18 @@ namespace Jackett.Common.Indexers
var seeders = torrent.Value<int>("seeders");
var leechers = torrent.Value<int>("leechers");
var grabs = ParseUtil.CoerceInt(torrent.Value<string>("completed") ?? "0");
var infohash = torrent.Value<JToken>("infohash").ToString();
var infoHash = torrent.Value<JToken>("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<long>("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<int> { TorznabCatType.Other.ID },
PublishDate = publishDate,
Size = size,

View file

@ -154,20 +154,7 @@ namespace Jackett.Common.Indexers
var imdb = movie_item.Value<string>("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<string>("hash") +
"&dn=" + movie_item.Value<string>("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<string>("hash");
release.InfoHash = torrent_info.Value<string>("hash"); // magnet link is auto generated from infohash
// ex: 2015-08-16 21:25:08 +0000
var dateStr = torrent_info.Value<string>("date_uploaded");