diff --git a/src/routes/rss.nim b/src/routes/rss.nim index d378396..a6a7c3f 100644 --- a/src/routes/rss.nim +++ b/src/routes/rss.nim @@ -15,7 +15,7 @@ proc redisKey*(page, name, cursor: string): string = if cursor.len > 0: result &= ":" & cursor -proc timelineRss*(req: Request; cfg: Config; query: Query): Future[Rss] {.async.} = +proc timelineRss*(req: Request; cfg: Config; query: Query; prefs: Prefs): Future[Rss] {.async.} = var profile: Profile let name = req.params.getOrDefault("name") @@ -39,7 +39,7 @@ proc timelineRss*(req: Request; cfg: Config; query: Query): Future[Rss] {.async. return Rss(feed: profile.user.username, cursor: "suspended") if profile.user.fullname.len > 0: - let rss = renderTimelineRss(profile, cfg, multi=(names.len > 1)) + let rss = renderTimelineRss(profile, cfg, prefs, multi=(names.len > 1)) return Rss(feed: rss, cursor: profile.tweets.bottom) template respRss*(rss, page) = @@ -78,7 +78,7 @@ proc createRssRouter*(cfg: Config) = let tweets = await getTweetSearch(query, cursor) rss.cursor = tweets.bottom - rss.feed = renderSearchRss(tweets.content, query.text, genQueryUrl(query), cfg) + rss.feed = renderSearchRss(tweets.content, query.text, genQueryUrl(query), cfg, cookiePrefs()) await cacheRss(key, rss) respRss(rss, "Search") @@ -94,7 +94,7 @@ proc createRssRouter*(cfg: Config) = if rss.cursor.len > 0: respRss(rss, "User") - rss = await timelineRss(request, cfg, Query(fromUser: @[name])) + rss = await timelineRss(request, cfg, Query(fromUser: @[name]), cookiePrefs()) await cacheRss(key, rss) respRss(rss, "User") @@ -122,7 +122,7 @@ proc createRssRouter*(cfg: Config) = if rss.cursor.len > 0: respRss(rss, "User") - rss = await timelineRss(request, cfg, query) + rss = await timelineRss(request, cfg, query, cookiePrefs()) await cacheRss(key, rss) respRss(rss, "User") @@ -159,7 +159,7 @@ proc createRssRouter*(cfg: Config) = list = await getCachedList(id=id) timeline = await getGraphListTweets(list.id, cursor) rss.cursor = timeline.bottom - rss.feed = renderListRss(timeline.content, list, cfg) + rss.feed = renderListRss(timeline.content, list, cfg, cookiePrefs()) await cacheRss(key, rss) respRss(rss, "List") diff --git a/src/views/rss.nimf b/src/views/rss.nimf index 036a7b9..0773c70 100644 --- a/src/views/rss.nimf +++ b/src/views/rss.nimf @@ -1,6 +1,6 @@ #? stdtmpl(subsChar = '$', metaChar = '#') ## SPDX-License-Identifier: AGPL-3.0-only -#import strutils, xmltree, strformat, options, unicode +#import strutils, xmltree, strformat, options, unicode, algorithm #import ../types, ../utils, ../formatters, ../prefs # #proc getTitle(tweet: Tweet; retweet: string): string = @@ -28,7 +28,37 @@ Twitter feed for: ${desc}. Generated by ${cfg.hostname} #end proc # -#proc renderRssTweet(tweet: Tweet; cfg: Config): string = +## Copied from views/tweet.nim +#proc isPlaybackEnabled(prefs: Prefs; playbackType: VideoType): bool = +# case playbackType +# of mp4: return prefs.mp4Playback +# of m3u8, vmap: return prefs.hlsPlayback +# end case +#end proc +# +#proc hasMp4Url(video: Video): bool = +# video.variants.anyIt(it.contentType == mp4) +#end proc +# +#proc getVideoDisabledText(playbackType: VideoType): string = +# case playbackType +# of mp4: + mp4 playback disabled in preferences +# of m3u8, vmap: + hls playback disabled in preferences +# end case +#end proc +# +#proc getVideoUnavailableText(video: Video): string = +# case video.reason +# of "dmcaed": + This media has been disabled in response to a report by the copyright owner +# else: + This media is unavailable +# end case +#end proc +# +#proc renderRssTweet(tweet: Tweet; cfg: Config; prefs: Prefs): string = #let tweet = tweet.retweet.get(tweet) #let urlPrefix = getUrlPrefix(cfg) #let text = replaceUrls(tweet.text, defaultPrefs, absolute=urlPrefix) @@ -42,7 +72,27 @@ Twitter feed for: ${desc}. Generated by ${cfg.hostname} # end for #elif tweet.video.isSome: - +# let video = get(tweet.video) +# let thumb = &"{urlPrefix}{getPicUrl(video.thumb)}" +# let playbackType = if not prefs.proxyVideos and video.hasMp4Url: mp4 +# else: video.playbackType +# if not video.available: + +
${getVideoUnavailableText(video)}
+# elif not isPlaybackEnabled(prefs, playbackType): + +${getVideoDisabledText(playbackType)}
+# else: +# let vars = video.variants.filterIt(it.contentType == playbackType) +# let vidUrl = vars.sortedByIt(it.resolution)[^1].url +# let source = if prefs.proxyVideos: getVidUrl(vidUrl) +# else: vidUrl +# let mutedAttribute = if prefs.muteVideos: "muted=\"\"" +# else: "" + +# end if #elif tweet.gif.isSome: # let thumb = &"{urlPrefix}{getPicUrl(get(tweet.gif).thumb)}" # let url = &"{urlPrefix}{getPicUrl(get(tweet.gif).url)}" @@ -56,7 +106,7 @@ Twitter feed for: ${desc}. Generated by ${cfg.hostname} #end if #end proc # -#proc renderRssTweets(tweets: seq[Tweets]; cfg: Config; userId=""): string = +#proc renderRssTweets(tweets: seq[Tweets]; cfg: Config; prefs: Prefs; userId=""): string = #let urlPrefix = getUrlPrefix(cfg) #var links: seq[string] #for thread in tweets: @@ -73,7 +123,7 @@ Twitter feed for: ${desc}. Generated by ${cfg.hostname}