1
0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2024-11-21 23:27:29 +00:00

Support rating counts and allowRatings

This commit is contained in:
Cadence Ember 2020-08-21 14:42:36 +12:00
parent 7b13e65118
commit 932f45c92d

View File

@ -72,8 +72,8 @@ def extract_video(id):
"viewCount": info["view_count"], "viewCount": info["view_count"],
"second__viewCountText": None, "second__viewCountText": None,
"second__viewCountTextShort": None, "second__viewCountTextShort": None,
"likeCount": info["like_count"], "likeCount": 0,
"dislikeCount": info["dislike_count"], "dislikeCount": 0,
"paid": None, "paid": None,
"premium": None, "premium": None,
"isFamilyFriendly": None, "isFamilyFriendly": None,
@ -163,14 +163,25 @@ def get_more_stuff_from_file(id, result):
content = file.read() content = file.read()
yt_initial_data = extract_yt_initial_data(content) yt_initial_data = extract_yt_initial_data(content)
views = yt_initial_data["contents"]["twoColumnWatchNextResults"]["results"]["results"]["contents"][0]\
["videoPrimaryInfoRenderer"]["viewCount"]["videoViewCountRenderer"] main_video = yt_initial_data["contents"]["twoColumnWatchNextResults"]["results"]["results"]["contents"][0]["videoPrimaryInfoRenderer"]
views = main_video["viewCount"]["videoViewCountRenderer"]
result["second__viewCountText"] = get_view_count_text_or_recommended(views) result["second__viewCountText"] = get_view_count_text_or_recommended(views)
if "shortViewCount" in views: if "shortViewCount" in views:
result["second__viewCountTextShort"] = views["shortViewCount"]["simpleText"] result["second__viewCountTextShort"] = views["shortViewCount"]["simpleText"]
if "sentimentBar" in main_video:
sentiment = main_video["sentimentBar"]["sentimentBarRenderer"]["tooltip"]
result["likeCount"] = view_count_text_to_number(sentiment.split(" / ")[0])
result["dislikeCount"] = view_count_text_to_number(sentiment.split(" / ")[1])
result["allowRatings"] = True
else:
result["allowRatings"] = False
recommendations = yt_initial_data["contents"]["twoColumnWatchNextResults"]["secondaryResults"]\ recommendations = yt_initial_data["contents"]["twoColumnWatchNextResults"]["secondaryResults"]\
["secondaryResults"]["results"] ["secondaryResults"]["results"]
# result = yt_initial_data
# return result
def get_useful_recommendation_data(r): def get_useful_recommendation_data(r):
if "compactVideoRenderer" in r: if "compactVideoRenderer" in r:
return r["compactVideoRenderer"] return r["compactVideoRenderer"]