|
|
@ -70,34 +70,34 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
|
|
|
|
|
|
|
|
|
|
|
|
client_config = YoutubeAPI::ClientConfig.new(region: region)
|
|
|
|
client_config = YoutubeAPI::ClientConfig.new(region: region)
|
|
|
|
response = YoutubeAPI.next(continuation: ctoken, client_config: client_config)
|
|
|
|
response = YoutubeAPI.next(continuation: ctoken, client_config: client_config)
|
|
|
|
|
|
|
|
contents = nil
|
|
|
|
|
|
|
|
|
|
|
|
if response["continuationContents"]?
|
|
|
|
if response["onResponseReceivedEndpoints"]?
|
|
|
|
response = response["continuationContents"]
|
|
|
|
|
|
|
|
if response["commentRepliesContinuation"]?
|
|
|
|
|
|
|
|
body = response["commentRepliesContinuation"]
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
body = response["itemSectionContinuation"]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
contents = body["contents"]?
|
|
|
|
|
|
|
|
header = body["header"]?
|
|
|
|
|
|
|
|
if body["continuations"]?
|
|
|
|
|
|
|
|
moreRepliesContinuation = body["continuations"][0]["nextContinuationData"]["continuation"].as_s
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
elsif response["onResponseReceivedEndpoints"]?
|
|
|
|
|
|
|
|
onResponseReceivedEndpoints = response["onResponseReceivedEndpoints"]
|
|
|
|
onResponseReceivedEndpoints = response["onResponseReceivedEndpoints"]
|
|
|
|
|
|
|
|
header = nil
|
|
|
|
onResponseReceivedEndpoints.as_a.each do |item|
|
|
|
|
onResponseReceivedEndpoints.as_a.each do |item|
|
|
|
|
|
|
|
|
if item["reloadContinuationItemsCommand"]?
|
|
|
|
case item["reloadContinuationItemsCommand"]["slot"]
|
|
|
|
case item["reloadContinuationItemsCommand"]["slot"]
|
|
|
|
when "RELOAD_CONTINUATION_SLOT_HEADER"
|
|
|
|
when "RELOAD_CONTINUATION_SLOT_HEADER"
|
|
|
|
header = item["reloadContinuationItemsCommand"]["continuationItems"][0]
|
|
|
|
header = item["reloadContinuationItemsCommand"]["continuationItems"][0]
|
|
|
|
when "RELOAD_CONTINUATION_SLOT_BODY"
|
|
|
|
when "RELOAD_CONTINUATION_SLOT_BODY"
|
|
|
|
contents = item["reloadContinuationItemsCommand"]["continuationItems"]
|
|
|
|
contents = item["reloadContinuationItemsCommand"]["continuationItems"]
|
|
|
|
contents.as_a.reject! do |item|
|
|
|
|
|
|
|
|
if item["continuationItemRenderer"]?
|
|
|
|
|
|
|
|
moreRepliesContinuation = item["continuationItemRenderer"]["continuationEndpoint"]["continuationCommand"]["token"].as_s
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
elsif item["appendContinuationItemsAction"]?
|
|
|
|
|
|
|
|
contents = item["appendContinuationItemsAction"]["continuationItems"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
elsif response["continuationContents"]?
|
|
|
|
|
|
|
|
response = response["continuationContents"]
|
|
|
|
|
|
|
|
if response["commentRepliesContinuation"]?
|
|
|
|
|
|
|
|
body = response["commentRepliesContinuation"]
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
body = response["itemSectionContinuation"]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
contents = body["contents"]?
|
|
|
|
|
|
|
|
header = body["header"]?
|
|
|
|
|
|
|
|
if body["continuations"]?
|
|
|
|
|
|
|
|
moreRepliesContinuation = body["continuations"][0]["nextContinuationData"]["continuation"].as_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
else
|
|
|
|
raise InfoException.new("Could not fetch comments")
|
|
|
|
raise InfoException.new("Could not fetch comments")
|
|
|
@ -111,6 +111,14 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
continuationItemRenderer = nil
|
|
|
|
|
|
|
|
contents.as_a.reject! do |item|
|
|
|
|
|
|
|
|
if item["continuationItemRenderer"]?
|
|
|
|
|
|
|
|
continuationItemRenderer = item["continuationItemRenderer"]
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
response = JSON.build do |json|
|
|
|
|
response = JSON.build do |json|
|
|
|
|
json.object do
|
|
|
|
json.object do
|
|
|
|
if header
|
|
|
|
if header
|
|
|
@ -126,7 +134,7 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
|
|
|
|
json.array do
|
|
|
|
json.array do
|
|
|
|
contents.as_a.each do |node|
|
|
|
|
contents.as_a.each do |node|
|
|
|
|
json.object do
|
|
|
|
json.object do
|
|
|
|
if !response["commentRepliesContinuation"]?
|
|
|
|
if node["commentThreadRenderer"]?
|
|
|
|
node = node["commentThreadRenderer"]
|
|
|
|
node = node["commentThreadRenderer"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -134,7 +142,7 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
|
|
|
|
node_replies = node["replies"]["commentRepliesRenderer"]
|
|
|
|
node_replies = node["replies"]["commentRepliesRenderer"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if !response["commentRepliesContinuation"]?
|
|
|
|
if node["comment"]?
|
|
|
|
node_comment = node["comment"]["commentRenderer"]
|
|
|
|
node_comment = node["comment"]["commentRenderer"]
|
|
|
|
else
|
|
|
|
else
|
|
|
|
node_comment = node["commentRenderer"]
|
|
|
|
node_comment = node["commentRenderer"]
|
|
|
@ -224,8 +232,15 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if moreRepliesContinuation
|
|
|
|
if continuationItemRenderer
|
|
|
|
json.field "continuation", moreRepliesContinuation
|
|
|
|
if continuationItemRenderer["continuationEndpoint"]?
|
|
|
|
|
|
|
|
continuationEndpoint = continuationItemRenderer["continuationEndpoint"]
|
|
|
|
|
|
|
|
elsif continuationItemRenderer["button"]?
|
|
|
|
|
|
|
|
continuationEndpoint = continuationItemRenderer["button"]["buttonRenderer"]["command"]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if continuationEndpoint
|
|
|
|
|
|
|
|
json.field "continuation", continuationEndpoint["continuationCommand"]["token"].as_s
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|