diff --git a/src/api/media.nim b/src/api/media.nim index 988a91c..f82194c 100644 --- a/src/api/media.nim +++ b/src/api/media.nim @@ -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 diff --git a/src/cache.nim b/src/cache.nim index 99383f9..7916165 100644 --- a/src/cache.nim +++ b/src/cache.nim @@ -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: