From 5e49e94bf12b2355a7ef71ec30602b0179939fc8 Mon Sep 17 00:00:00 2001 From: Zed Date: Sun, 26 Dec 2021 06:48:55 +0100 Subject: [PATCH] Refactor "withheld" parsing --- src/parser.nim | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/parser.nim b/src/parser.nim index f094639..fe4acc6 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -269,19 +269,19 @@ proc parseTweet(js: JsonNode): Tweet = result.gif = some(parseGif(m)) else: discard - let withheldInCountries: seq[string] = - if js{"withheld_in_countries"}.kind == JArray: - js{"withheld_in_countries"}.to(seq[string]) - else: - newSeq[string]() + with jsWithheld, js{"withheld_in_countries"}: + var withheldInCountries: seq[string] - if js{"withheld_copyright"}.getBool or - # XX - Content is withheld in all countries - "XX" in withheldInCountries or - # XY - Content is withheld due to a DMCA request. - "XY" in withheldInCountries or - (withheldInCountries.len > 0 and "withheld" in result.text): - result.available = false + if jsWithheld.kind == JArray: + withheldInCountries = jsWithheld.to(seq[string]) + + # XX - Content is withheld in all countries + # XY - Content is withheld due to a DMCA request. + if js{"withheld_copyright"}.getBool or + withheldInCountries.len > 0 and ("XX" in withheldInCountries or + "XY" in withheldInCountries or + "withheld" in result.text): + result.available = false proc finalizeTweet(global: GlobalObjects; id: string): Tweet = let intId = if id.len > 0: parseBiggestInt(id) else: 0