Support title and description for videos

This commit is contained in:
Zed 2019-10-26 15:50:42 +02:00
parent 02b206078d
commit 371a2473bc
6 changed files with 26 additions and 5 deletions

View File

@ -3,6 +3,10 @@ import norm/sqlite
import types, api/profile import types, api/profile
template safeAddColumn(field: typedesc): untyped =
try: field.addColumn
except DbError: discard
dbFromTypes("cache.db", "", "", "", [Profile, Video]) dbFromTypes("cache.db", "", "", "", [Profile, Video])
withDb: withDb:
@ -10,6 +14,8 @@ withDb:
createTables() createTables()
except DbError: except DbError:
discard discard
Video.title.safeAddColumn
Video.description.safeAddColumn
var profileCacheTime = initDuration(minutes=10) var profileCacheTime = initDuration(minutes=10)

View File

@ -202,11 +202,14 @@ proc getTweetMedia*(tweet: Tweet; node: XmlNode) =
if "gif" in player.attr("class"): if "gif" in player.attr("class"):
tweet.gif = some getGif(player.select(".PlayableMedia-player")) tweet.gif = some getGif(player.select(".PlayableMedia-player"))
elif "video" in player.attr("class"): elif "video" in player.attr("class"):
let thumb = player.selectAttr(".PlayableMedia-player", "style").split("'") let
thumb = player.selectAttr(".PlayableMedia-player", "style").split("'")
desc = player.selectText(".PlayableMedia-description")
title = player.selectText(".PlayableMedia-title")
var video = Video(title: title, description: desc)
if thumb.len > 1: if thumb.len > 1:
tweet.video = some Video(thumb: thumb[^2]) video.thumb = thumb[^2]
else: tweet.video = some video
tweet.video = some Video()
proc getQuoteMedia*(quote: var Quote; node: XmlNode) = proc getQuoteMedia*(quote: var Quote; node: XmlNode) =
if node.select(".QuoteTweet--sensitive") != nil: if node.select(".QuoteTweet--sensitive") != nil:

View File

@ -15,6 +15,7 @@
overflow: hidden; overflow: hidden;
color: inherit; color: inherit;
display: flex; display: flex;
flex-direction: column;
text-decoration: none !important; text-decoration: none !important;
&:hover { &:hover {

View File

@ -13,6 +13,7 @@ video {
.video-container { .video-container {
max-height: 530px; max-height: 530px;
margin: 0;
img { img {
height: 100%; height: 100%;

View File

@ -44,6 +44,8 @@ dbTypes:
views*: string views*: string
available*: bool available*: bool
reason*: string reason*: string
title*: string
description*: string
playbackType* {. playbackType* {.
dbType: "STRING" dbType: "STRING"
parseIt: parseEnum[VideoType](it.s) parseIt: parseEnum[VideoType](it.s)

View File

@ -76,8 +76,11 @@ proc renderVideoUnavailable(video: Video): VNode =
p: text "This media is unavailable" p: text "This media is unavailable"
proc renderVideo(video: Video; prefs: Prefs; path: string): VNode = proc renderVideo(video: Video; prefs: Prefs; path: string): VNode =
let container =
if video.description.len > 0 or video.title.len > 0: " card-container"
else: ""
buildHtml(tdiv(class="attachments")): buildHtml(tdiv(class="attachments")):
tdiv(class="gallery-video"): tdiv(class="gallery-video" & container):
tdiv(class="attachment video-container"): tdiv(class="attachment video-container"):
let thumb = getPicUrl(video.thumb) let thumb = getPicUrl(video.thumb)
if not video.available: if not video.available:
@ -99,6 +102,11 @@ proc renderVideo(video: Video; prefs: Prefs; path: string): VNode =
verbatim "<div class=\"video-overlay\" onclick=\"playVideo(this)\">" verbatim "<div class=\"video-overlay\" onclick=\"playVideo(this)\">"
verbatim "<div class=\"overlay-circle\">" verbatim "<div class=\"overlay-circle\">"
verbatim "<span class=\"overlay-triangle\"</span></div></div>" verbatim "<span class=\"overlay-triangle\"</span></div></div>"
if container.len > 0:
tdiv(class="card-content"):
h2(class="card-title"): text video.title
if video.description.len > 0:
p(class="card-description"): text video.description
proc renderGif(gif: Gif; prefs: Prefs): VNode = proc renderGif(gif: Gif; prefs: Prefs): VNode =
buildHtml(tdiv(class="attachments media-gif")): buildHtml(tdiv(class="attachments media-gif")):