diff --git a/src/torrentinim.nim b/src/torrentinim.nim
index b5af75d..1d518d3 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,28 @@ 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()
+ 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."
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..0511442
--- /dev/null
+++ b/src/torznab.nim
@@ -0,0 +1,88 @@
+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 =
+ """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+"""
\ No newline at end of file