diff --git a/src/routes/rss.nim b/src/routes/rss.nim index 5672b7e..fad8a44 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; tab, param: string): Future[Rss] {.async.} = +proc timelineRss*(req: Request; cfg: Config; query: Query; prefs: Prefs; tab, param: string): Future[Rss] {.async.} = var profile: Profile let name = req.params.getOrDefault("name") @@ -39,7 +39,7 @@ proc timelineRss*(req: Request; cfg: Config; query: Query; tab, param: string): return Rss(feed: profile.user.username, cursor: "suspended") if profile.user.fullname.len > 0: - let rss = renderTimelineRss(profile, cfg, tab, param, multi=(names.len > 1)) + let rss = renderTimelineRss(profile, cfg, prefs, tab, param, 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 getGraphTweetSearch(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") @@ -124,7 +124,7 @@ proc createRssRouter*(cfg: Config) = if rss.cursor.len > 0: respRss(rss, "User") - rss = await timelineRss(request, cfg, query, tab, param) + rss = await timelineRss(request, cfg, query, cookiePrefs(), tab, param) await cacheRss(key, rss) respRss(rss, "User") @@ -161,7 +161,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 4586446..e5a58e1 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} ${getTitle(tweet, retweet)} @${tweet.user.username} - + ${getRfc822Time(tweet)} ${urlPrefix & link} ${urlPrefix & link} @@ -82,7 +132,7 @@ Twitter feed for: ${desc}. Generated by ${cfg.hostname} #end for #end proc # -#proc renderTimelineRss*(profile: Profile; cfg: Config; tab, param: string; multi=false): string = +#proc renderTimelineRss*(profile: Profile; cfg: Config; prefs: Prefs; tab, param: string; multi=false): string = #let urlPrefix = getUrlPrefix(cfg) #var atomLink = &"{urlPrefix}/{profile.user.username}" #var link = &"{urlPrefix}/{profile.user.username}" @@ -119,13 +169,13 @@ Twitter feed for: ${desc}. Generated by ${cfg.hostname} 128 #if profile.tweets.content.len > 0: -${renderRssTweets(profile.tweets.content, cfg, userId=profile.user.id)} +${renderRssTweets(profile.tweets.content, cfg, prefs, userId=profile.user.id)} #end if #end proc # -#proc renderListRss*(tweets: seq[Tweets]; list: List; cfg: Config): string = +#proc renderListRss*(tweets: seq[Tweets]; list: List; cfg: Config; prefs: Prefs): string = #let link = &"{getUrlPrefix(cfg)}/i/lists/{list.id}" #result = "" @@ -137,12 +187,12 @@ ${renderRssTweets(profile.tweets.content, cfg, userId=profile.user.id)} ${getDescription(&"{list.name} by @{list.username}", cfg)} en-us 40 -${renderRssTweets(tweets, cfg)} +${renderRssTweets(tweets, cfg, prefs)} #end proc # -#proc renderSearchRss*(tweets: seq[Tweets]; name, param: string; cfg: Config): string = +#proc renderSearchRss*(tweets: seq[Tweets]; name, param: string; cfg: Config; prefs: Prefs): string = #let urlPrefix = getUrlPrefix(cfg) #let escName = xmltree.escape(name) #let escParam = xmltree.escape(param) @@ -156,7 +206,7 @@ ${renderRssTweets(tweets, cfg)} ${getDescription(&"Search \"{escName}\"", cfg)} en-us 40 -${renderRssTweets(tweets, cfg)} +${renderRssTweets(tweets, cfg, prefs)} #end proc