Fix rare edge case where gifs get parsed as videos
This commit is contained in:
parent
8836cf51e8
commit
7ef3a4faba
2 changed files with 16 additions and 0 deletions
|
@ -93,11 +93,19 @@ proc getVideoFetch(tweet: Tweet; agent, token: string; retry=true): Future[Optio
|
|||
result = some video
|
||||
tokenUses.inc
|
||||
|
||||
proc videoIsInvalid(video: Video): bool =
|
||||
not video.available and video.url.len == 0
|
||||
|
||||
proc getVideo*(tweet: Tweet; agent, token: string; force=false) {.async.} =
|
||||
let token = if token.len == 0: guestToken else: token
|
||||
var video = getCachedVideo(tweet.id)
|
||||
if video.isNone:
|
||||
video = await getVideoFetch(tweet, agent, token)
|
||||
elif videoIsInvalid(get(video)) and tweet.gif.isSome:
|
||||
# gif was mistakenly parsed as a gif
|
||||
uncache(tweet.id)
|
||||
return
|
||||
|
||||
getVideoVar(tweet) = video
|
||||
if tweet.card.isSome: tweet.video = none Video
|
||||
|
||||
|
|
|
@ -63,6 +63,14 @@ proc cache*(video: var Video) =
|
|||
if video.videoId.len > 0:
|
||||
video.insert()
|
||||
|
||||
proc uncache*(id: int64) =
|
||||
withDb:
|
||||
try:
|
||||
var video = Video.getOne("videoId = ?", $id)
|
||||
video.delete()
|
||||
except:
|
||||
discard
|
||||
|
||||
proc getCachedVideo*(id: int64): Option[Video] =
|
||||
withDb:
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue