Refactor "withheld" parsing

This commit is contained in:
Zed 2021-12-26 06:48:55 +01:00
parent 2a40dd8059
commit 5e49e94bf1

View file

@ -269,19 +269,19 @@ proc parseTweet(js: JsonNode): Tweet =
result.gif = some(parseGif(m)) result.gif = some(parseGif(m))
else: discard else: discard
let withheldInCountries: seq[string] = with jsWithheld, js{"withheld_in_countries"}:
if js{"withheld_in_countries"}.kind == JArray: var withheldInCountries: seq[string]
js{"withheld_in_countries"}.to(seq[string])
else:
newSeq[string]()
if js{"withheld_copyright"}.getBool or if jsWithheld.kind == JArray:
# XX - Content is withheld in all countries withheldInCountries = jsWithheld.to(seq[string])
"XX" in withheldInCountries or
# XY - Content is withheld due to a DMCA request. # XX - Content is withheld in all countries
"XY" in withheldInCountries or # XY - Content is withheld due to a DMCA request.
(withheldInCountries.len > 0 and "withheld" in result.text): if js{"withheld_copyright"}.getBool or
result.available = false 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 = proc finalizeTweet(global: GlobalObjects; id: string): Tweet =
let intId = if id.len > 0: parseBiggestInt(id) else: 0 let intId = if id.len > 0: parseBiggestInt(id) else: 0