Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -6,22 +6,6 @@ import experimental/parser/unifiedcard
|
|||||||
|
|
||||||
proc parseGraphTweet(js: JsonNode; isLegacy=false): Tweet
|
proc parseGraphTweet(js: JsonNode; isLegacy=false): Tweet
|
||||||
|
|
||||||
proc extractTweetsFromEntry(e: JsonNode; entryId: string): seq[Tweet] =
|
|
||||||
if e{"content", "items"}.notNull:
|
|
||||||
for item in e{"content", "items"}:
|
|
||||||
with tweetResult, item{"item", "itemContent", "tweet_results", "result"}:
|
|
||||||
var tweet = parseGraphTweet(tweetResult, false)
|
|
||||||
if not tweet.available:
|
|
||||||
tweet.id = parseBiggestInt(item{"entryId"}.getStr.getId())
|
|
||||||
result.add tweet
|
|
||||||
return
|
|
||||||
|
|
||||||
with tweetResult, e{"content", "content", "tweetResult", "result"}:
|
|
||||||
var tweet = parseGraphTweet(tweetResult, false)
|
|
||||||
if not tweet.available:
|
|
||||||
tweet.id = parseBiggestInt(entryId.getId())
|
|
||||||
result.add tweet
|
|
||||||
|
|
||||||
proc parseUser(js: JsonNode; id=""): User =
|
proc parseUser(js: JsonNode; id=""): User =
|
||||||
if js.isNull: return
|
if js.isNull: return
|
||||||
result = User(
|
result = User(
|
||||||
@@ -432,6 +416,22 @@ proc parseGraphConversation*(js: JsonNode; tweetId: string; v2=true): Conversati
|
|||||||
elif entryId.startsWith("cursor-bottom"):
|
elif entryId.startsWith("cursor-bottom"):
|
||||||
result.replies.bottom = e{"content", contentKey, "value"}.getStr
|
result.replies.bottom = e{"content", contentKey, "value"}.getStr
|
||||||
|
|
||||||
|
proc extractTweetsFromEntry*(e: JsonNode; entryId: string): seq[Tweet] =
|
||||||
|
if e{"content", "items"}.notNull:
|
||||||
|
for item in e{"content", "items"}:
|
||||||
|
with tweetResult, item{"item", "itemContent", "tweet_results", "result"}:
|
||||||
|
var tweet = parseGraphTweet(tweetResult, false)
|
||||||
|
if not tweet.available:
|
||||||
|
tweet.id = parseBiggestInt(item{"entryId"}.getStr.getId())
|
||||||
|
result.add tweet
|
||||||
|
return
|
||||||
|
|
||||||
|
with tweetResult, e{"content", "content", "tweetResult", "result"}:
|
||||||
|
var tweet = parseGraphTweet(tweetResult, false)
|
||||||
|
if not tweet.available:
|
||||||
|
tweet.id = parseBiggestInt(entryId.getId())
|
||||||
|
result.add tweet
|
||||||
|
|
||||||
proc parseGraphTimeline*(js: JsonNode; after=""): Profile =
|
proc parseGraphTimeline*(js: JsonNode; after=""): Profile =
|
||||||
result = Profile(tweets: Timeline(beginning: after.len == 0))
|
result = Profile(tweets: Timeline(beginning: after.len == 0))
|
||||||
|
|
||||||
@@ -482,31 +482,43 @@ proc parseGraphTimeline*(js: JsonNode; after=""): Profile =
|
|||||||
proc parseGraphPhotoRail*(js: JsonNode): PhotoRail =
|
proc parseGraphPhotoRail*(js: JsonNode): PhotoRail =
|
||||||
result = @[]
|
result = @[]
|
||||||
|
|
||||||
var instructions = ? js{"data", "user", "result", "timeline", "timeline", "instructions"}
|
let instructions =
|
||||||
|
if js{"data", "user"}.notNull:
|
||||||
|
? js{"data", "user", "result", "timeline", "timeline", "instructions"}
|
||||||
|
else:
|
||||||
|
? js{"data", "user_result", "result", "timeline_response", "timeline", "instructions"}
|
||||||
|
|
||||||
if instructions.len == 0:
|
if instructions.len == 0:
|
||||||
instructions = ? js{"data", "user_result", "result", "timeline_response", "timeline", "instructions"}
|
return
|
||||||
|
|
||||||
for i in instructions:
|
for i in instructions:
|
||||||
let instrType = i{"type"}.getStr
|
# TimelineAddToModule instruction is used by MediaTimelineV2
|
||||||
if instrType.len == 0:
|
if i{"moduleItems"}.notNull:
|
||||||
if i{"__typename"}.getStr != "TimelineAddEntries":
|
for item in i{"moduleItems"}:
|
||||||
|
with tweetResult, item{"item", "itemContent", "tweet_results", "result"}:
|
||||||
|
let t = parseGraphTweet(tweetResult, false)
|
||||||
|
if not t.available:
|
||||||
|
t.id = parseBiggestInt(item{"entryId"}.getStr.getId())
|
||||||
|
|
||||||
|
let photo = extractGalleryPhoto(t)
|
||||||
|
if photo.url.len > 0:
|
||||||
|
result.add photo
|
||||||
|
|
||||||
|
if result.len == 16:
|
||||||
|
return
|
||||||
continue
|
continue
|
||||||
elif instrType != "TimelineAddEntries":
|
|
||||||
|
let instrType = i{"type"}.getStr(i{"__typename"}.getStr)
|
||||||
|
if instrType != "TimelineAddEntries":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for e in i{"entries"}:
|
for e in i{"entries"}:
|
||||||
let entryId = e{"entryId"}.getStr
|
let entryId = e{"entryId"}.getStr
|
||||||
if entryId.startsWith("tweet") or entryId.startsWith("profile-grid"):
|
if entryId.startsWith("tweet") or entryId.startsWith("profile-grid"):
|
||||||
for t in extractTweetsFromEntry(e, entryId):
|
for t in extractTweetsFromEntry(e, entryId):
|
||||||
let url =
|
let photo = extractGalleryPhoto(t)
|
||||||
if t.photos.len > 0: t.photos[0]
|
if photo.url.len > 0:
|
||||||
elif t.video.isSome: get(t.video).thumb
|
result.add photo
|
||||||
elif t.gif.isSome: get(t.gif).thumb
|
|
||||||
elif t.card.isSome: get(t.card).image
|
|
||||||
else: ""
|
|
||||||
|
|
||||||
if url.len > 0:
|
|
||||||
result.add GalleryPhoto(url: url, tweetId: $t.id)
|
|
||||||
|
|
||||||
if result.len == 16:
|
if result.len == 16:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -319,3 +319,13 @@ proc expandNoteTweetEntities*(tweet: Tweet; js: JsonNode) =
|
|||||||
tweet.expandTextEntities(entities, text, textSlice)
|
tweet.expandTextEntities(entities, text, textSlice)
|
||||||
|
|
||||||
tweet.text = tweet.text.multiReplace((unicodeOpen, xmlOpen), (unicodeClose, xmlClose))
|
tweet.text = tweet.text.multiReplace((unicodeOpen, xmlOpen), (unicodeClose, xmlClose))
|
||||||
|
|
||||||
|
proc extractGalleryPhoto*(t: Tweet): GalleryPhoto =
|
||||||
|
let url =
|
||||||
|
if t.photos.len > 0: t.photos[0]
|
||||||
|
elif t.video.isSome: get(t.video).thumb
|
||||||
|
elif t.gif.isSome: get(t.gif).thumb
|
||||||
|
elif t.card.isSome: get(t.card).image
|
||||||
|
else: ""
|
||||||
|
|
||||||
|
result = GalleryPhoto(url: url, tweetId: $t.id)
|
||||||
|
|||||||
Reference in New Issue
Block a user