#11: Add the discovering of channels having commented on ended livestreams

This commit is contained in:
Benjamin Loison 2023-01-22 15:15:27 +01:00
parent 68b1f9a77f
commit d34fade0cd
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -488,11 +488,11 @@ void treatChannelOrVideo(unsigned short threadId, bool isChannel, string id, str
{ {
if(item.contains("liveStreamingDetails")) if(item.contains("liveStreamingDetails"))
{ {
PRINT(item["id"]) string videoId = item["id"];
//PRINT(videoId)
json liveStreamingDetails = item["liveStreamingDetails"]; json liveStreamingDetails = item["liveStreamingDetails"];
if(liveStreamingDetails.contains("activeLiveChatId")) if(liveStreamingDetails.contains("activeLiveChatId"))
{ {
PRINT("streaming")
string activeLiveChatId = liveStreamingDetails["activeLiveChatId"]; string activeLiveChatId = liveStreamingDetails["activeLiveChatId"];
json data = getJson(threadId, "liveChat/messages?part=snippet,authorDetails&liveChatId=" + activeLiveChatId, true, id), json data = getJson(threadId, "liveChat/messages?part=snippet,authorDetails&liveChatId=" + activeLiveChatId, true, id),
items = data["items"]; items = data["items"];
@ -500,12 +500,48 @@ void treatChannelOrVideo(unsigned short threadId, bool isChannel, string id, str
{ {
string channelId = item["snippet"]["authorChannelId"]; string channelId = item["snippet"]["authorChannelId"];
addChannelToTreat(threadId, channelId); addChannelToTreat(threadId, channelId);
PRINT("Found: " << channelId)
} }
} }
else else
{ {
PRINT("no more streaming") // As there isn't the usual pagination mechanism for these ended livestreams, we proceed in an uncertain way as follows.
set<string> messageIds;
unsigned long long lastMessageTimestampRelativeMsec = 0;
while(true)
{
string time = to_string(lastMessageTimestampRelativeMsec);
json data = getJson(threadId, "liveChats?part=snippet&id=" + videoId + "&time=" + time, false, id),
snippet = data["items"][0]["snippet"];
if(snippet.empty())
{
break;
}
json firstMessage = snippet[0];
string firstMessageId = firstMessage["id"];
// We verify that we don't skip any message by verifying that the first message was already treated if we already treated some messages.
if(!messageIds.empty() && messageIds.find(firstMessageId) == messageIds.end())
{
PRINT("The verification that we don't skip any message failed!")
exit(EXIT_FAILURE);
}
for(const auto& message : snippet)
{
string messageId = message["id"];
if(messageIds.find(messageId) == messageIds.end())
{
messageIds.insert(messageId);
string channelId = message["authorChannelId"];
addChannelToTreat(threadId, channelId);
}
}
json lastMessage = snippet.back();
// If there isn't any new message, then we stop the retrieving.
if(lastMessageTimestampRelativeMsec == lastMessage["videoOffsetTimeMsec"])
{
break;
}
lastMessageTimestampRelativeMsec = lastMessage["videoOffsetTimeMsec"];
}
} }
} }
} }