From bbdfcdde4be61b665cde9cd3b1ba75f023c268d4 Mon Sep 17 00:00:00 2001 From: Sergio Tapia Date: Fri, 12 Feb 2021 00:25:03 -0500 Subject: [PATCH 1/3] t=caps endpoint implemented --- src/torrentinim.nim | 25 +++++++++++++++---------- src/torznab.nim | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 src/torznab.nim diff --git a/src/torrentinim.nim b/src/torrentinim.nim index b5af75d..f746e32 100644 --- a/src/torrentinim.nim +++ b/src/torrentinim.nim @@ -6,6 +6,7 @@ import strutils import "database" import "./helpers/datetime" import "./torrents" +import "./torznab" from "./crawlers/eztv" import nil from "./crawlers/leetx.nim" import nil from "./crawlers/nyaa.nim" import nil @@ -20,21 +21,25 @@ when isMainModule: if (initRequested()): discard initDatabase() - asyncCheck eztv.startCrawl() - asyncCheck leetx.startCrawl() - asyncCheck nyaa.startCrawl() - asyncCheck nyaa_pantsu.startCrawl() - asyncCheck nyaa_sukebei.startCrawl() - asyncCheck yts.startCrawl() - asyncCheck torrentdownloads.startCrawl() - asyncCheck thepiratebay.startCrawl() - asyncCheck rarbg.startCrawl() + # asyncCheck eztv.startCrawl() + # asyncCheck leetx.startCrawl() + # asyncCheck nyaa.startCrawl() + # asyncCheck nyaa_pantsu.startCrawl() + # asyncCheck nyaa_sukebei.startCrawl() + # asyncCheck yts.startCrawl() + # asyncCheck torrentdownloads.startCrawl() + # asyncCheck thepiratebay.startCrawl() + # asyncCheck rarbg.startCrawl() let settings = newSettings(debug = false, port = Port(getEnv("TORRENTINIM_PORT", "50123").parseInt())) var app = newApp(settings = settings) proc hello*(ctx: Context) {.async.} = - resp "Torrentinim is running, bambino." + if ctx.getQueryParams("t") == "caps": + ctx.response.setHeader("Content-Type", "text/xml") + resp torznabCaps() + else: + resp "Torrentinim is running, bambino." proc search*(ctx: Context) {.async.} = let query = ctx.getQueryParams("query") diff --git a/src/torznab.nim b/src/torznab.nim new file mode 100644 index 0000000..b63a384 --- /dev/null +++ b/src/torznab.nim @@ -0,0 +1,27 @@ +proc torznabCaps*(): string = + """ + + + + + + + + + + + + + + + + + + + + + + + + +""" \ No newline at end of file From 4bc4b74840a8292a3be05bd1419d3f0aba9e106d Mon Sep 17 00:00:00 2001 From: Sergio Tapia Date: Fri, 12 Feb 2021 00:28:56 -0500 Subject: [PATCH 2/3] Tweak caps categories --- src/torznab.nim | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/torznab.nim b/src/torznab.nim index b63a384..c4d5efc 100644 --- a/src/torznab.nim +++ b/src/torznab.nim @@ -9,17 +9,14 @@ proc torznabCaps*(): string = - + - - - + - From 2744ccdd41e822f88d454d348cac3256e3fd3f04 Mon Sep 17 00:00:00 2001 From: Sergio Tapia Date: Fri, 12 Feb 2021 01:46:28 -0500 Subject: [PATCH 3/3] Basic torznab search functionality --- src/torrentinim.nim | 3 +++ src/torznab.nim | 66 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/torrentinim.nim b/src/torrentinim.nim index f746e32..1d518d3 100644 --- a/src/torrentinim.nim +++ b/src/torrentinim.nim @@ -38,6 +38,9 @@ when isMainModule: if ctx.getQueryParams("t") == "caps": ctx.response.setHeader("Content-Type", "text/xml") resp torznabCaps() + elif ctx.getQueryParams("q") != "" and ctx.getQueryParams("page") != "": + ctx.response.setHeader("Content-Type", "text/xml") + resp torznabSearch(ctx.getQueryParams("q"), ctx.getQueryParams("page")) else: resp "Torrentinim is running, bambino." diff --git a/src/torznab.nim b/src/torznab.nim index c4d5efc..0511442 100644 --- a/src/torznab.nim +++ b/src/torznab.nim @@ -1,3 +1,67 @@ +import strformat +import strutils +import times +import xmltree + +import "./torrents" +import "./torrents/torrent" + +proc torrentXml*(torrent: Torrent): string = + let uploadDate = torrent.uploaded_at.format("ddd, d MMM yyyy HH:mm:ss zzz") + + fmt""" + + {torrent.name} + {torrent.canonical_url} + {torrent.canonical_url} + {torrent.canonical_url} + {uploadDate} + {torrent.size} + {torrent.name} + + + + + + + + + + + + """ + +proc torznabSearch*(query: string, page: string): string = + let results = searchTorrents(query, page) + var torrentsXml = newSeq[string](0) + for item in results: + torrentsXml.add(torrentXml(item)) + + let torrentXmlString = join(torrentsXml, "\n") + + fmt""" + + + + + HDAccess + HDAccess API + https://hdaccess.net + en-us + ($email) (HDA Invites) + search + + https://hdaccess.net/logo_small.png + HDAccess + https://hdaccess.net + HDAccess API + + + {torrentXmlString} + + + """ + proc torznabCaps*(): string = """ @@ -10,7 +74,7 @@ proc torznabCaps*(): string = - +