diff options
| author | ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> | 2024-04-09 17:06:36 -0400 |
|---|---|---|
| committer | ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> | 2024-04-10 18:21:53 -0400 |
| commit | a9f55aa31062e148bd0fa15636a004762acabedd (patch) | |
| tree | 08a409cd2d98c5eb618937c7967a49bca3d7901e /src | |
| parent | c27bb90e4d8286665658e2805a26ad8881472618 (diff) | |
| download | invidious-a9f55aa31062e148bd0fa15636a004762acabedd.tar.gz invidious-a9f55aa31062e148bd0fa15636a004762acabedd.tar.bz2 invidious-a9f55aa31062e148bd0fa15636a004762acabedd.zip | |
fix lint, improve performance
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious/comments/youtube.cr | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/invidious/comments/youtube.cr b/src/invidious/comments/youtube.cr index 375672d7..4c6a0d56 100644 --- a/src/invidious/comments/youtube.cr +++ b/src/invidious/comments/youtube.cr @@ -104,6 +104,8 @@ module Invidious::Comments end end + mutations = response.dig?("frameworkUpdates", "entityBatchUpdate", "mutations").try &.as_a || [] of JSON::Any + response = JSON.build do |json| json.object do if header @@ -135,9 +137,9 @@ module Invidious::Comments cvm = node.dig("commentViewModel", "commentViewModel") comment_key = cvm["commentKey"] toolbar_key = cvm["toolbarStateKey"] - if mutations = response.dig?("frameworkUpdates", "entityBatchUpdate", "mutations") - comment_mutation = mutations.as_a.find { |i| i.dig?("payload", "commentEntityPayload", "key") == comment_key} - toolbar_mutation = mutations.as_a.find { |i| i.dig?("entityKey") == toolbar_key} + if mutations.size != 0 + comment_mutation = mutations.find { |i| i.dig?("payload", "commentEntityPayload", "key") == comment_key } + toolbar_mutation = mutations.find { |i| i.dig?("entityKey") == toolbar_key } if !comment_mutation.nil? && !toolbar_mutation.nil? html_content = comment_mutation.dig("payload", "commentEntityPayload", "properties", "content", "content").as_s if comment_author = comment_mutation.dig?("payload", "commentEntityPayload", "author") @@ -156,8 +158,8 @@ module Invidious::Comments end end end - json.field "authorIsChannelOwner", comment_author["isCreator"].as_bool - json.field "isSponsor", (comment_author["sponsorBadgeUrl"]?!= nil) + json.field "authorIsChannelOwner", comment_author["isCreator"].as_bool + json.field "isSponsor", (comment_author["sponsorBadgeUrl"]? != nil) if comment_author["sponsorBadgeUrl"]? # Sponsor icon thumbnails always have one object and there's only ever the url property in it json.field "sponsorIconUrl", comment_author["sponsorBadgeUrl"].to_s |
