added starts of rss feeds... ha
This commit is contained in:
parent
dcbe4c565e
commit
13ae6c3fbd
4 changed files with 49 additions and 6 deletions
|
@ -35,6 +35,13 @@ proc staticFileHandler(request: Request) =
|
||||||
else:
|
else:
|
||||||
request.respond(404)
|
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 =
|
proc createRouter(): Router =
|
||||||
var router: Router
|
var router: Router
|
||||||
|
@ -46,6 +53,7 @@ proc createRouter(): Router =
|
||||||
router.get("/favicon.ico", staticFileHandler)
|
router.get("/favicon.ico", staticFileHandler)
|
||||||
router.get("/favicon.png", staticFileHandler)
|
router.get("/favicon.png", staticFileHandler)
|
||||||
router.get("/css.css", staticFileHandler)
|
router.get("/css.css", staticFileHandler)
|
||||||
|
router.get("/*.rss", rssHandler)
|
||||||
return router
|
return router
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -119,16 +119,45 @@ proc compilePage(content: string, video_uri: string = "", search_query: string =
|
||||||
page &= RESOURCES["html_end"]
|
page &= RESOURCES["html_end"]
|
||||||
return page
|
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"""<item><title>{title}</titcle><link>{vid_url}</link><description>{title}</description><image><title>{title}</title><url>{vid_thumb}</url></image></item>"""
|
||||||
|
rss &= RESOURCES["rss_end"]
|
||||||
|
return rss
|
||||||
|
|
||||||
const XV = "https://www.xvideos.com"
|
const XV = "https://www.xvideos.com"
|
||||||
proc genpage*(path: string, video_uri: string = ""): string =
|
proc findSearchQuery(query: string): string =
|
||||||
let content = request(XV & path)
|
|
||||||
var search_query: string
|
var search_query: string
|
||||||
if video_uri == "":
|
let search = parseUri(query)
|
||||||
let search = parseUri(path)
|
|
||||||
for item in search.query.split("&"):
|
for item in search.query.split("&"):
|
||||||
let parm = item.split("=")
|
let parm = item.split("=")
|
||||||
if parm[0] == "k":
|
if parm[0] == "k":
|
||||||
search_query = parm[1]
|
search_query = parm[1]
|
||||||
|
break
|
||||||
|
return search_query
|
||||||
|
|
||||||
|
proc genpage*(path: string, video_uri: string = ""): string =
|
||||||
|
let content = request(XV & path)
|
||||||
|
let search_query = findSearchQuery(path)
|
||||||
|
if video_uri == "":
|
||||||
return compilePage(content, search_query = search_query)
|
return compilePage(content, search_query = search_query)
|
||||||
else:
|
else:
|
||||||
return compilePage(content, video_uri)
|
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)
|
||||||
|
|
||||||
|
|
2
src/resources/rss_end
Normal file
2
src/resources/rss_end
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
</channel>
|
||||||
|
</rss>
|
4
src/resources/rss_start
Normal file
4
src/resources/rss_start
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<rss version="2.0">
|
||||||
|
<channel>
|
||||||
|
<title>Pimvidious</title>
|
||||||
|
<link>https://example.com</link>
|
Loading…
Reference in a new issue