From a9826151e9b4b9b74f5214cc952d3b59cc99a9f3 Mon Sep 17 00:00:00 2001 From: Zed Date: Thu, 20 Jun 2019 17:20:32 +0200 Subject: [PATCH] Preliminary video support --- public/style.css | 19 +++++++++++++++++++ src/parser.nim | 15 +++++++++------ src/types.nim | 2 ++ src/views/tweet.nim | 15 +++++++++++++++ 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/public/style.css b/public/style.css index 3881143..f0cae67 100644 --- a/public/style.css +++ b/public/style.css @@ -559,3 +559,22 @@ nav { font-size: 21px; font-weight: bold; } + +.video-overlay { + width: 100%; + height: 100%; + position: absolute; + top: 0; + left: 0; + z-index: 1; + background-color: #000000bd; +} + +.video-overlay p { + position: relative; + z-index: 0; + color: #dcdcdc; + text-align: center; + top: calc(50% - 20px); + font-size: 20px; +} diff --git a/src/parser.nim b/src/parser.nim index 3a732e7..e3d9127 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -9,7 +9,7 @@ proc getAttr(node: XmlNode; attr: string; default=""): string = proc selectAttr(node: XmlNode; selector: string; attr: string; default=""): string = let res = node.querySelector(selector) - return res.getAttr(attr, default) + if res == nil: "" else: res.getAttr(attr, default) proc selectText(node: XmlNode; selector: string): string = let res = node.querySelector(selector) @@ -63,9 +63,8 @@ proc parseTweet*(tweet: XmlNode): Tweet = let text = action.innerText.split() num = text[0] - act = text[1] - case act + case text[1] of "replies": result.replies = num of "likes": result.likes = num of "retweets": result.retweets = num @@ -74,9 +73,13 @@ proc parseTweet*(tweet: XmlNode): Tweet = for photo in tweet.querySelectorAll(".AdaptiveMedia-photoContainer"): result.photos.add photo.attrs["data-image-url"] - let gif = tweet.selectAttr(".PlayableMedia-player", "style") - if gif != "": - result.gif = gif.replace(re".+thumb/([^\.']+)\.jpg.+", "$1") + let player = tweet.selectAttr(".PlayableMedia-player", "style") + if player.len > 0: + let thumb = player.replace(re".+:url\('([^']+)'\)", "$1") + if "tweet_video" in thumb: + result.gif = thumb.replace(re".+thumb/([^\.']+)\.jpg.+", "$1") + else: + result.videoThumb = thumb proc parseTweets*(node: XmlNode): Tweets = if node.isNil: return diff --git a/src/types.nim b/src/types.nim index 75597d1..9da08ac 100644 --- a/src/types.nim +++ b/src/types.nim @@ -27,6 +27,8 @@ type pinned*: bool photos*: seq[string] gif*: string + video*: string + videoThumb*: string Tweets* = seq[Tweet] diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 99ffe74..d26bc1d 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -55,6 +55,19 @@ #end proc # +#proc renderVideo(tweet: Tweet): string = +
+ +
+#end proc +# #proc renderGif(tweet: Tweet): string = #let thumbUrl = getGifThumb(tweet).getSigUrl("pic") #let videoUrl = getGifSrc(tweet).getSigUrl("video") @@ -89,6 +102,8 @@ #if tweet.photos.len > 0: ${renderMediaGroup(tweet)} + #elif tweet.videoThumb.len > 0: + ${renderVideo(tweet)} #elif tweet.gif.len > 0: ${renderGif(tweet)} #end if