#11: Add the discovering of channels having commented on ended livestreams
This commit is contained in:
parent
68b1f9a77f
commit
d34fade0cd
44
main.cpp
44
main.cpp
@ -488,11 +488,11 @@ void treatChannelOrVideo(unsigned short threadId, bool isChannel, string id, str
|
||||
{
|
||||
if(item.contains("liveStreamingDetails"))
|
||||
{
|
||||
PRINT(item["id"])
|
||||
string videoId = item["id"];
|
||||
//PRINT(videoId)
|
||||
json liveStreamingDetails = item["liveStreamingDetails"];
|
||||
if(liveStreamingDetails.contains("activeLiveChatId"))
|
||||
{
|
||||
PRINT("streaming")
|
||||
string activeLiveChatId = liveStreamingDetails["activeLiveChatId"];
|
||||
json data = getJson(threadId, "liveChat/messages?part=snippet,authorDetails&liveChatId=" + activeLiveChatId, true, id),
|
||||
items = data["items"];
|
||||
@ -500,12 +500,48 @@ void treatChannelOrVideo(unsigned short threadId, bool isChannel, string id, str
|
||||
{
|
||||
string channelId = item["snippet"]["authorChannelId"];
|
||||
addChannelToTreat(threadId, channelId);
|
||||
PRINT("Found: " << channelId)
|
||||
}
|
||||
}
|
||||
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"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user