added iframe for rss feed

This commit is contained in:
Paul Wilde 2024-12-23 10:22:41 +00:00
parent 8eb5c63f9c
commit 2a69baf840
2 changed files with 52 additions and 21 deletions

View file

@ -22,6 +22,14 @@ proc videoHandler(request: Request) =
headers["content-type"] = "text/html"
request.respond(200, headers, content)
proc onlyVideoHandler(request: Request) =
echo request.uri
let real_uri = request.uri.replace("/only","")
var headers: HttpHeaders
let content = genVideo(path=real_uri, video_uri=real_uri)
headers["content-type"] = "text/html"
request.respond(200, headers, content)
proc staticFileHandler(request: Request) =
var file = request.uri[1..^1]
if file == "favicon.ico": file = "favicon.png"
@ -47,9 +55,10 @@ proc createRouter(): Router =
var router: Router
router.get("/", pageHandler)
router.get("/new/*", pageHandler)
router.get("/video.*/*", videoHandler)
router.get("/video.*/*/*", videoHandler)
router.get("/video.*/*/*/*", videoHandler)
for x in countup(1,5):
var s = "/video.*" & "/*".repeat(x)
router.get(s, videoHandler)
router.get("/only" & s, onlyVideoHandler)
router.get("/favicon.ico", staticFileHandler)
router.get("/favicon.png", staticFileHandler)
router.get("/css.css", staticFileHandler)

View file

@ -4,6 +4,12 @@ import os, strutils, strformat, tables, re, sugar, uri, times
type
Urls = seq[string]
Thumbs = seq[string]
type
Video = object
thumb: string
uri: string
low: string
hls: string
proc cacheResources(): Table[string, string] =
echo "Compiling Resources..."
@ -41,29 +47,34 @@ proc parseThumbs(content: string): seq[string] =
thumb.split("\"")[1]
return thumbs
proc setUpVideo(content: string, video_uri: string): (string, Urls, Thumbs) =
proc getVideoStreamURI(content: string, video_uri: string): Video =
let
rel_vids_re = re"""video_related=(.+)"""
vid_h_url_re = re"""setVideoUrlHigh(.*)"""
vid_l_url_re = re"""setVideoUrlLow(.*)"""
vid_hls_re = re"""setVideoHLS(.*)"""
vid_thumb_re = re"""setThumbUrl(.*)"""
vid_hls_re = re"""setVideoHLS(.*)"""
var video = Video()
video.uri = content.findAll(vid_h_url_re)[0].split("'")[1]
video.low = content.findAll(vid_l_url_re)[0].split("'")[1]
let video_hls_matches = content.findAll(vid_hls_re)
if video_hls_matches.len > 0:
video.hls = video_hls_matches[0].split("'")[1]
if video.uri == "":
video.uri = video.low
video.thumb = content.findAll(vid_thumb_re)[0].split("'")[1]
return video
proc setUpVideo(content: string, video_uri: string): (string, Urls, Thumbs) =
let video = getVideoStreamURI(content, video_uri)
let rel_vids_re = re"""video_related=(.+)"""
let
related_vids = collect:
for vid in content.findAll(rel_vids_re):
vid.replace(",","\n")
var video = content.findAll(vid_h_url_re)[0].split("'")[1]
let video_low = content.findAll(vid_l_url_re)[0].split("'")[1]
var video_hls: string
var video_hls_matches = content.findAll(vid_hls_re)
if video_hls_matches.len > 0:
video_hls = video_hls_matches[0].split("'")[1]
if video == "":
video = video_low
let video_thumb = content.findAll(vid_thumb_re)[0].split("'")[1]
var HTML_VIDEO = fmt"""<center><video poster="{video_thumb}" controls autoplay loop><source src="{video}"/></video></center><center id='infoblock'>"""
if video_hls != "":
HTML_VIDEO &= fmt"""<h3>HD Stream: </h3><input type='text' size='50' value='{video_hls}' /><br/>(use with a video player)"""
var HTML_VIDEO = fmt"""<center><video poster="{video.thumb}" controls autoplay loop><source src="{video.uri}"/></video></center><center id='infoblock'>"""
if video.hls != "":
HTML_VIDEO &= fmt"""<h3>HD Stream: </h3><a href="{video.hls}">{video.hls}</a><br/>(use with a video player)"""
HTML_VIDEO &= "</center>"
var thumbs: Thumbs = @[]
var urls: Urls = @[]
@ -82,6 +93,11 @@ proc getPagination(content:string): string =
if pagination.len > 0:
return pagination[0]
proc compileVideo(content: string, video_uri: string): string =
let video = getVideoStreamURI(content, video_uri)
let page = fmt"""<center><video poster="{video.thumb}" controls autoplay loop><source src="{video.uri}"/></video></center>"""
return page
proc compilePage(content: string, video_uri: string = "", search_query: string = ""): string =
var
page: string = ""
@ -133,6 +149,7 @@ proc compileRSSPage(content: string, search_query: string = ""): string =
else:
vid_url = url.replace("THUMBNUM","1")
vid_thumb = thumbs[^1].replace("THUMBNUM","1")
let o_vid_uri = "/only" & vid_url
let title = vid_url.split("/")[^1].replace("_"," ")
rss &= fmt"""
<item>
@ -140,7 +157,8 @@ proc compileRSSPage(content: string, search_query: string = ""): string =
<title>{title}</title>
<link>{vid_url}</link>
<description>{title}&lt;br /&gt;
&lt;img src="{vid_thumb}"&gt;
&lt;img src="{vid_thumb}"&gt;&lt;br /&gt;
&lt;iframe src="{o_vid_uri}" height="300" width="400"&gt;&lt;/iframe&gt;
</description>
<media:content url="{vid_thumb}" type="image/png" medium="image">
<media:rating scheme="urn:simple">adult</media:rating>
@ -161,6 +179,10 @@ proc findSearchQuery(query: string): string =
break
return search_query
proc genvideo*(path: string, video_uri: string): string =
let content = request(XV & path)
return compileVideo(content, video_uri)
proc genpage*(path: string, video_uri: string = ""): string =
let content = request(XV & path)
let search_query = findSearchQuery(path)