Was a little inspired. Now we have a database (self populating) of imdb id's - why shouldn't we actually have the ability to scrape any other instance of torrentio, or knightcrawler? Also restructured the producer to be vertically sliced to make it easier to work with Too much flicking back and forth between Jobs and Crawlers when configuring
44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
namespace Producer.Features.Crawlers.Yts;
|
|
|
|
public class YtsCrawler(IHttpClientFactory httpClientFactory, ILogger<YtsCrawler> logger, IDataStorage storage) : BaseXmlCrawler(httpClientFactory, logger, storage)
|
|
{
|
|
protected override string Url => "https://yts.am/rss";
|
|
|
|
protected override string Source => "YTS";
|
|
protected override IReadOnlyDictionary<string, string> Mappings
|
|
=> new Dictionary<string, string>
|
|
{
|
|
[nameof(Torrent.Name)] = "title",
|
|
[nameof(Torrent.Size)] = "size",
|
|
[nameof(Torrent.Seeders)] = "seeders",
|
|
[nameof(Torrent.Leechers)] = "leechers",
|
|
[nameof(Torrent.InfoHash)] = "enclosure",
|
|
};
|
|
|
|
protected override Torrent? ParseTorrent(XElement itemNode)
|
|
{
|
|
var torrent = new Torrent
|
|
{
|
|
Source = Source,
|
|
Name = itemNode.Element(Mappings["Name"])?.Value,
|
|
Category = "movies",
|
|
Size = "0",
|
|
Seeders = 0,
|
|
Leechers = 0,
|
|
};
|
|
|
|
HandleInfoHash(itemNode, torrent, "InfoHash");
|
|
|
|
return torrent;
|
|
}
|
|
|
|
protected override void HandleInfoHash(XElement itemNode, Torrent torrent, string infoHashKey)
|
|
{
|
|
var infoHash = itemNode.Element(Mappings[infoHashKey])?.Attribute("url")?.Value.Split("/download/").ElementAtOrDefault(1);
|
|
|
|
if (infoHash is not null)
|
|
{
|
|
torrent.InfoHash = infoHash;
|
|
}
|
|
}
|
|
} |