Skip to content

Commit

Permalink
Support embedded data in TikTok import
Browse files Browse the repository at this point in the history
  • Loading branch information
stijn-uva committed Jan 31, 2022
1 parent 564b740 commit f54b4dd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions datasources/tiktok/search_tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,24 @@ def import_from_file(self, path):

hashtags = [extra["hashtagName"] for extra in post.get("textExtra", []) if "hashtagName" in extra and extra["hashtagName"]]

if type(post["author"]) is dict:
# from intercepted API response
user_nickname = post["author"]["uniqueId"]
user_fullname = post["author"]["nickname"]
user_id = post["author"]["id"]
else:
# from embedded JSON object
user_nickname = post["author"]
user_fullname = post["nickname"]
user_id = ""


mapped_item = {
"id": post["id"],
"thread_id": post["id"],
"author": post["author"]["uniqueId"],
"author_full": post["author"]["nickname"],
"author_id": post["author"]["id"],
"author": user_nickname,
"author_full": user_fullname,
"author_id": user_id,
"author_followers": post["authorStats"]["followerCount"],
"subject": "",
"body": post["desc"],
Expand All @@ -78,7 +90,7 @@ def import_from_file(self, path):
"music_id": post["music"]["id"],
"music_url": post["music"]["playUrl"],
"video_url": post["video"].get("downloadAddr", ""),
"tiktok_url": "https://tiktok.com/@%s/video/%s" % (post["author"]["uniqueId"], post["id"]),
"tiktok_url": "https://tiktok.com/@%s/video/%s" % (user_nickname, post["id"]),
"thumbnail_url": post["video"]["cover"],
"likes": post["stats"]["diggCount"],
"comments": post["stats"]["commentCount"],
Expand Down

0 comments on commit f54b4dd

Please sign in to comment.