Preliminary video support

This commit is contained in:
Zed 2019-06-20 17:20:32 +02:00
parent cea5cc0523
commit a9826151e9
4 changed files with 45 additions and 6 deletions

View File

@ -559,3 +559,22 @@ nav {
font-size: 21px; font-size: 21px;
font-weight: bold; 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;
}

View File

@ -9,7 +9,7 @@ proc getAttr(node: XmlNode; attr: string; default=""): string =
proc selectAttr(node: XmlNode; selector: string; attr: string; default=""): string = proc selectAttr(node: XmlNode; selector: string; attr: string; default=""): string =
let res = node.querySelector(selector) 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 = proc selectText(node: XmlNode; selector: string): string =
let res = node.querySelector(selector) let res = node.querySelector(selector)
@ -63,9 +63,8 @@ proc parseTweet*(tweet: XmlNode): Tweet =
let let
text = action.innerText.split() text = action.innerText.split()
num = text[0] num = text[0]
act = text[1]
case act case text[1]
of "replies": result.replies = num of "replies": result.replies = num
of "likes": result.likes = num of "likes": result.likes = num
of "retweets": result.retweets = num of "retweets": result.retweets = num
@ -74,9 +73,13 @@ proc parseTweet*(tweet: XmlNode): Tweet =
for photo in tweet.querySelectorAll(".AdaptiveMedia-photoContainer"): for photo in tweet.querySelectorAll(".AdaptiveMedia-photoContainer"):
result.photos.add photo.attrs["data-image-url"] result.photos.add photo.attrs["data-image-url"]
let gif = tweet.selectAttr(".PlayableMedia-player", "style") let player = tweet.selectAttr(".PlayableMedia-player", "style")
if gif != "": if player.len > 0:
result.gif = gif.replace(re".+thumb/([^\.']+)\.jpg.+", "$1") 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 = proc parseTweets*(node: XmlNode): Tweets =
if node.isNil: return if node.isNil: return

View File

@ -27,6 +27,8 @@ type
pinned*: bool pinned*: bool
photos*: seq[string] photos*: seq[string]
gif*: string gif*: string
video*: string
videoThumb*: string
Tweets* = seq[Tweet] Tweets* = seq[Tweet]

View File

@ -55,6 +55,19 @@
</div> </div>
#end proc #end proc
# #
#proc renderVideo(tweet: Tweet): string =
<div class="attachments media-body">
<div class="gallery-row" style="max-height: unset;">
<div class="attachment image">
<video poster=${tweet.videoThumb} style="width: 100%; height: 100%;" autoplay muted loop></video>
<div class="video-overlay">
<p>Video playback not supported</p>
</div>
</div>
</div>
</div>
#end proc
#
#proc renderGif(tweet: Tweet): string = #proc renderGif(tweet: Tweet): string =
#let thumbUrl = getGifThumb(tweet).getSigUrl("pic") #let thumbUrl = getGifThumb(tweet).getSigUrl("pic")
#let videoUrl = getGifSrc(tweet).getSigUrl("video") #let videoUrl = getGifSrc(tweet).getSigUrl("video")
@ -89,6 +102,8 @@
</div> </div>
#if tweet.photos.len > 0: #if tweet.photos.len > 0:
${renderMediaGroup(tweet)} ${renderMediaGroup(tweet)}
#elif tweet.videoThumb.len > 0:
${renderVideo(tweet)}
#elif tweet.gif.len > 0: #elif tweet.gif.len > 0:
${renderGif(tweet)} ${renderGif(tweet)}
#end if #end if