Support promo_video_website cards
This commit is contained in:
parent
d12f14135e
commit
27cf4cdf64
|
@ -237,7 +237,7 @@ nav {
|
||||||
|
|
||||||
.gallery-row .attachment:last-child, .gallery-row .attachments:last-child, .video-container {
|
.gallery-row .attachment:last-child, .gallery-row .attachments:last-child, .video-container {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
max-height: 500px;
|
max-height: 530px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.attachments .attachment {
|
.attachments .attachment {
|
||||||
|
@ -901,6 +901,11 @@ video {
|
||||||
border-color: #808080;
|
border-color: #808080;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.card-container .attachments {
|
||||||
|
margin: 0;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.large .card-container {
|
.large .card-container {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,11 @@ proc getVideo*(tweet: Tweet; token: string) {.async.} =
|
||||||
await getVideo(tweet, guestToken)
|
await getVideo(tweet, guestToken)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if tweet.card.isNone:
|
||||||
tweet.video = some(parseVideo(json))
|
tweet.video = some(parseVideo(json))
|
||||||
|
else:
|
||||||
|
get(tweet.card).video = some(parseVideo(json))
|
||||||
|
tweet.video = none(Video)
|
||||||
tokenUses.inc
|
tokenUses.inc
|
||||||
|
|
||||||
proc getVideos*(thread: Thread; token="") {.async.} =
|
proc getVideos*(thread: Thread; token="") {.async.} =
|
||||||
|
|
|
@ -180,19 +180,6 @@ proc parsePhotoRail*(node: XmlNode): seq[GalleryPhoto] =
|
||||||
)
|
)
|
||||||
|
|
||||||
proc parseCard*(card: var Card; node: XmlNode) =
|
proc parseCard*(card: var Card; node: XmlNode) =
|
||||||
let cardKind = node.select("head > meta[name*=card_name]").attr("content")
|
|
||||||
|
|
||||||
if "summary_large_image" in cardKind:
|
|
||||||
card.kind = summaryLarge
|
|
||||||
elif "summary" in cardKind:
|
|
||||||
card.kind = summary
|
|
||||||
elif "live_event" in cardKind:
|
|
||||||
card.kind = liveEvent
|
|
||||||
elif "player" in cardKind:
|
|
||||||
card.kind = player
|
|
||||||
elif "promo_website" in cardKind:
|
|
||||||
card.kind = promoWebsite
|
|
||||||
|
|
||||||
card.title = node.selectText("h2.TwitterCard-title")
|
card.title = node.selectText("h2.TwitterCard-title")
|
||||||
card.text = node.selectText("p.tcu-resetMargin")
|
card.text = node.selectText("p.tcu-resetMargin")
|
||||||
card.dest = node.selectText("span.SummaryCard-destination")
|
card.dest = node.selectText("span.SummaryCard-destination")
|
||||||
|
@ -203,9 +190,7 @@ proc parseCard*(card: var Card; node: XmlNode) =
|
||||||
let image = node.select(".tcu-imageWrapper img")
|
let image = node.select(".tcu-imageWrapper img")
|
||||||
if image != nil:
|
if image != nil:
|
||||||
# workaround for issue 11713
|
# workaround for issue 11713
|
||||||
card.image = image.attr("data-src").replace("gname", "g&name")
|
card.image = some(image.attr("data-src").replace("gname", "g&name"))
|
||||||
else:
|
|
||||||
echo card.id
|
|
||||||
|
|
||||||
if card.kind == liveEvent:
|
if card.kind == liveEvent:
|
||||||
card.text = card.title
|
card.text = card.title
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import xmltree, htmlparser, strtabs, strformat, times
|
import xmltree, htmlparser, strtabs, strformat, strutils, times
|
||||||
import regex
|
import regex
|
||||||
|
|
||||||
import types, formatters, api
|
import types, formatters, api
|
||||||
|
@ -169,13 +169,16 @@ proc getQuoteMedia*(quote: var Quote; node: XmlNode) =
|
||||||
|
|
||||||
proc getTweetCard*(tweet: Tweet; node: XmlNode) =
|
proc getTweetCard*(tweet: Tweet; node: XmlNode) =
|
||||||
if node.attr("data-has-cards") == "false": return
|
if node.attr("data-has-cards") == "false": return
|
||||||
let cardType = node.attr("data-card2-type")
|
var cardType = node.attr("data-card2-type")
|
||||||
|
|
||||||
|
if ":" in cardType:
|
||||||
|
cardType = cardType.split(":")[^1]
|
||||||
|
|
||||||
if "poll" in cardType:
|
if "poll" in cardType:
|
||||||
tweet.poll = some(Poll())
|
tweet.poll = some(Poll())
|
||||||
return
|
return
|
||||||
|
|
||||||
let cardDiv = node.select(".card2 > div")
|
let cardDiv = node.select(".card2 > .js-macaw-cards-iframe-container")
|
||||||
if cardDiv == nil: return
|
if cardDiv == nil: return
|
||||||
|
|
||||||
var card = Card(
|
var card = Card(
|
||||||
|
@ -183,6 +186,11 @@ proc getTweetCard*(tweet: Tweet; node: XmlNode) =
|
||||||
query: cardDiv.attr("data-src")
|
query: cardDiv.attr("data-src")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
card.kind = parseEnum[CardKind](cardType)
|
||||||
|
except ValueError:
|
||||||
|
card.kind = summary
|
||||||
|
|
||||||
let cardUrl = cardDiv.attr("data-card-url")
|
let cardUrl = cardDiv.attr("data-card-url")
|
||||||
for n in node.selectAll(".tweet-text a"):
|
for n in node.selectAll(".tweet-text a"):
|
||||||
if n.attr("href") == cardUrl:
|
if n.attr("href") == cardUrl:
|
||||||
|
|
|
@ -71,7 +71,12 @@ type
|
||||||
leader*: int
|
leader*: int
|
||||||
|
|
||||||
CardKind* = enum
|
CardKind* = enum
|
||||||
summary, summaryLarge, liveEvent, player, promoWebsite
|
summary = "summary"
|
||||||
|
summaryLarge = "summary_large_image"
|
||||||
|
promoWebsite = "promo_website"
|
||||||
|
promoVideo = "promo_video_website"
|
||||||
|
player = "player"
|
||||||
|
liveEvent = "live_event"
|
||||||
|
|
||||||
Card* = object
|
Card* = object
|
||||||
kind*: CardKind
|
kind*: CardKind
|
||||||
|
@ -81,7 +86,8 @@ type
|
||||||
title*: string
|
title*: string
|
||||||
dest*: string
|
dest*: string
|
||||||
text*: string
|
text*: string
|
||||||
image*: string
|
image*: Option[string]
|
||||||
|
video*: Option[Video]
|
||||||
|
|
||||||
Quote* = object
|
Quote* = object
|
||||||
id*: string
|
id*: string
|
||||||
|
|
|
@ -77,21 +77,26 @@ proc renderPoll(poll: Poll): VNode =
|
||||||
span(class="poll-info"):
|
span(class="poll-info"):
|
||||||
text $poll.votes & " votes • " & poll.status
|
text $poll.votes & " votes • " & poll.status
|
||||||
|
|
||||||
proc renderCard(card: Card): VNode =
|
proc renderCardImage(card: Card): VNode =
|
||||||
const largeCards = {summaryLarge, liveEvent, promoWebsite}
|
buildHtml(tdiv(class="card-image-container")):
|
||||||
let large = if card.kind in largeCards: " large" else: ""
|
|
||||||
|
|
||||||
buildHtml(tdiv(class=("card" & large))):
|
|
||||||
a(class="card-container", href=card.url):
|
|
||||||
if card.image.len > 0:
|
|
||||||
tdiv(class="card-image-container"):
|
|
||||||
tdiv(class="card-image"):
|
tdiv(class="card-image"):
|
||||||
img(src=card.image.getSigUrl("pic"))
|
img(src=get(card.image).getSigUrl("pic"))
|
||||||
if card.kind == player:
|
if card.kind == player:
|
||||||
tdiv(class="card-overlay"):
|
tdiv(class="card-overlay"):
|
||||||
tdiv(class="card-overlay-circle"):
|
tdiv(class="card-overlay-circle"):
|
||||||
span(class="card-overlay-triangle")
|
span(class="card-overlay-triangle")
|
||||||
|
|
||||||
|
proc renderCard(card: Card): VNode =
|
||||||
|
const largeCards = {summaryLarge, liveEvent, promoWebsite, promoVideo}
|
||||||
|
let large = if card.kind in largeCards: " large" else: ""
|
||||||
|
|
||||||
|
buildHtml(tdiv(class=("card" & large))):
|
||||||
|
a(class="card-container", href=card.url):
|
||||||
|
if card.image.isSome:
|
||||||
|
renderCardImage(card)
|
||||||
|
elif card.video.isSome:
|
||||||
|
renderVideo(get(card.video))
|
||||||
|
|
||||||
tdiv(class="card-content-container"):
|
tdiv(class="card-content-container"):
|
||||||
tdiv(class="card-content"):
|
tdiv(class="card-content"):
|
||||||
h2(class="card-title"): text card.title
|
h2(class="card-title"): text card.title
|
||||||
|
@ -181,7 +186,9 @@ proc renderTweet*(tweet: Tweet; class=""; index=0; total=(-1); last=false): VNod
|
||||||
if tweet.quote.isSome:
|
if tweet.quote.isSome:
|
||||||
renderQuote(tweet.quote.get())
|
renderQuote(tweet.quote.get())
|
||||||
|
|
||||||
if tweet.photos.len > 0:
|
if tweet.card.isSome:
|
||||||
|
renderCard(tweet.card.get())
|
||||||
|
elif tweet.photos.len > 0:
|
||||||
renderAlbum(tweet)
|
renderAlbum(tweet)
|
||||||
elif tweet.video.isSome:
|
elif tweet.video.isSome:
|
||||||
renderVideo(tweet.video.get())
|
renderVideo(tweet.video.get())
|
||||||
|
@ -189,8 +196,6 @@ proc renderTweet*(tweet: Tweet; class=""; index=0; total=(-1); last=false): VNod
|
||||||
renderGif(tweet.gif.get())
|
renderGif(tweet.gif.get())
|
||||||
elif tweet.poll.isSome:
|
elif tweet.poll.isSome:
|
||||||
renderPoll(tweet.poll.get())
|
renderPoll(tweet.poll.get())
|
||||||
elif tweet.card.isSome:
|
|
||||||
renderCard(tweet.card.get())
|
|
||||||
|
|
||||||
renderStats(tweet.stats)
|
renderStats(tweet.stats)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue