From 371a2473bc2990085442f133fb42fd752353bc51 Mon Sep 17 00:00:00 2001 From: Zed Date: Sat, 26 Oct 2019 15:50:42 +0200 Subject: [PATCH] Support title and description for videos --- src/cache.nim | 6 ++++++ src/parserutils.nim | 11 +++++++---- src/sass/tweet/card.scss | 1 + src/sass/tweet/video.scss | 1 + src/types.nim | 2 ++ src/views/tweet.nim | 10 +++++++++- 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/cache.nim b/src/cache.nim index 92a3d3e..52a4bae 100644 --- a/src/cache.nim +++ b/src/cache.nim @@ -3,6 +3,10 @@ import norm/sqlite import types, api/profile +template safeAddColumn(field: typedesc): untyped = + try: field.addColumn + except DbError: discard + dbFromTypes("cache.db", "", "", "", [Profile, Video]) withDb: @@ -10,6 +14,8 @@ withDb: createTables() except DbError: discard + Video.title.safeAddColumn + Video.description.safeAddColumn var profileCacheTime = initDuration(minutes=10) diff --git a/src/parserutils.nim b/src/parserutils.nim index fa31bea..35b5a1e 100644 --- a/src/parserutils.nim +++ b/src/parserutils.nim @@ -202,11 +202,14 @@ proc getTweetMedia*(tweet: Tweet; node: XmlNode) = if "gif" in player.attr("class"): tweet.gif = some getGif(player.select(".PlayableMedia-player")) 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: - tweet.video = some Video(thumb: thumb[^2]) - else: - tweet.video = some Video() + video.thumb = thumb[^2] + tweet.video = some video proc getQuoteMedia*(quote: var Quote; node: XmlNode) = if node.select(".QuoteTweet--sensitive") != nil: diff --git a/src/sass/tweet/card.scss b/src/sass/tweet/card.scss index 7ebd37e..174f13a 100644 --- a/src/sass/tweet/card.scss +++ b/src/sass/tweet/card.scss @@ -15,6 +15,7 @@ overflow: hidden; color: inherit; display: flex; + flex-direction: column; text-decoration: none !important; &:hover { diff --git a/src/sass/tweet/video.scss b/src/sass/tweet/video.scss index 070353c..151404c 100644 --- a/src/sass/tweet/video.scss +++ b/src/sass/tweet/video.scss @@ -13,6 +13,7 @@ video { .video-container { max-height: 530px; + margin: 0; img { height: 100%; diff --git a/src/types.nim b/src/types.nim index 291aae7..0373436 100644 --- a/src/types.nim +++ b/src/types.nim @@ -44,6 +44,8 @@ dbTypes: views*: string available*: bool reason*: string + title*: string + description*: string playbackType* {. dbType: "STRING" parseIt: parseEnum[VideoType](it.s) diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 220e67a..8f567dc 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -76,8 +76,11 @@ proc renderVideoUnavailable(video: Video): VNode = p: text "This media is unavailable" 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")): - tdiv(class="gallery-video"): + tdiv(class="gallery-video" & container): tdiv(class="attachment video-container"): let thumb = getPicUrl(video.thumb) if not video.available: @@ -99,6 +102,11 @@ proc renderVideo(video: Video; prefs: Prefs; path: string): VNode = verbatim "
" verbatim "
" verbatim "
" + 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 = buildHtml(tdiv(class="attachments media-gif")):