From 13ae6c3fbd2281fc9aa19d9c03947512ba9a7f43 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Wed, 18 Dec 2024 14:09:57 +0000 Subject: [PATCH] added starts of rss feeds... ha --- src/Pimvidious.nim | 8 ++++++++ src/genpage.nim | 41 +++++++++++++++++++++++++++++++++++------ src/resources/rss_end | 2 ++ src/resources/rss_start | 4 ++++ 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 src/resources/rss_end create mode 100644 src/resources/rss_start diff --git a/src/Pimvidious.nim b/src/Pimvidious.nim index 288a443..0156e08 100644 --- a/src/Pimvidious.nim +++ b/src/Pimvidious.nim @@ -35,6 +35,13 @@ proc staticFileHandler(request: Request) = else: request.respond(404) +proc rssHandler(request: Request) = + echo request.uri + var headers: HttpHeaders + let content = genRSS(path=request.uri) + headers["content-type"] = "application/rss+xml" + request.respond(200, headers, content) + proc createRouter(): Router = var router: Router @@ -46,6 +53,7 @@ proc createRouter(): Router = router.get("/favicon.ico", staticFileHandler) router.get("/favicon.png", staticFileHandler) router.get("/css.css", staticFileHandler) + router.get("/*.rss", rssHandler) return router diff --git a/src/genpage.nim b/src/genpage.nim index 3a231e9..d65e1ef 100644 --- a/src/genpage.nim +++ b/src/genpage.nim @@ -119,16 +119,45 @@ proc compilePage(content: string, video_uri: string = "", search_query: string = page &= RESOURCES["html_end"] return page +proc compileRSSPage(content: string, search_query: string = ""): string = + var rss = RESOURCES["rss_start"] + let urls = parseUrls(content) + let thumbs = parseThumbs(content) + for idx, url in urls: + var + vid_url, vid_thumb: string + vid_url = url.replace("THUMBNUM","0") + if thumbs.len > idx: + vid_thumb = thumbs[idx].replace("THUMBNUM","1") + else: + vid_url = url.replace("THUMBNUM","1") + vid_thumb = thumbs[^1].replace("THUMBNUM","1") + let title = vid_url.split("/")[^1].replace("_"," ") + rss &= fmt"""{title}</titcle><link>{vid_url}</link><description>{title}</description><image><title>{title}{vid_thumb}""" + rss &= RESOURCES["rss_end"] + return rss + const XV = "https://www.xvideos.com" +proc findSearchQuery(query: string): string = + var search_query: string + let search = parseUri(query) + for item in search.query.split("&"): + let parm = item.split("=") + if parm[0] == "k": + search_query = parm[1] + break + return search_query + proc genpage*(path: string, video_uri: string = ""): string = let content = request(XV & path) - var search_query: string + let search_query = findSearchQuery(path) if video_uri == "": - let search = parseUri(path) - for item in search.query.split("&"): - let parm = item.split("=") - if parm[0] == "k": - search_query = parm[1] return compilePage(content, search_query = search_query) else: return compilePage(content, video_uri) + +proc genRSS*(path: string): string = + let content = request(XV & path) + let search_query = findSearchQuery(path) + return compileRSSPage(content, search_query = search_query) + diff --git a/src/resources/rss_end b/src/resources/rss_end new file mode 100644 index 0000000..3a9dbde --- /dev/null +++ b/src/resources/rss_end @@ -0,0 +1,2 @@ + + diff --git a/src/resources/rss_start b/src/resources/rss_start new file mode 100644 index 0000000..64b0b2b --- /dev/null +++ b/src/resources/rss_start @@ -0,0 +1,4 @@ + + +Pimvidious +https://example.com