Fix #37: Use a number of channels seen (possibly repeated) instead of YouTube Data API v3 Comment(Thread): resource

This commit is contained in:
Benjamin Loison 2023-02-12 16:31:27 +01:00
parent 54fe40e588
commit 454503271e
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -47,8 +47,8 @@ set<string> channelsAlreadyTreated;
map<unsigned int, string> channelsToTreat; map<unsigned int, string> channelsToTreat;
map<string, unsigned int> channelsToTreatRev; map<string, unsigned int> channelsToTreatRev;
vector<string> keys; vector<string> keys;
unsigned int commentsPerSecondCount = 0; unsigned int channelsPerSecondCount = 0;
map<unsigned short, unsigned int> commentsCountThreads, map<unsigned short, unsigned int> channelsCountThreads,
requestsPerChannelThreads; requestsPerChannelThreads;
unsigned short THREADS_NUMBER = 1; unsigned short THREADS_NUMBER = 1;
// Use `string` variables instead of macros to have `string` properties, even if could use a meta-macro inlining as `string`s. // Use `string` variables instead of macros to have `string` properties, even if could use a meta-macro inlining as `string`s.
@ -137,8 +137,8 @@ int main(int argc, char *argv[])
while(true) while(true)
{ {
MAIN_PRINT("Comments per second: " << commentsPerSecondCount) MAIN_PRINT("Channels per second: " << channelsPerSecondCount)
commentsPerSecondCount = 0; channelsPerSecondCount = 0;
sleep(1); sleep(1);
} }
@ -168,7 +168,7 @@ void treatChannels(unsigned short threadId)
PRINT("Treating channel " << channelToTreat << " (treated: " << channelsAlreadyTreated.size() << ", to treat: " << channelsToTreat.size() << ")") PRINT("Treating channel " << channelToTreat << " (treated: " << channelsAlreadyTreated.size() << ", to treat: " << channelsToTreat.size() << ")")
commentsCountThreads[threadId] = 0; channelsCountThreads[threadId] = 0;
requestsPerChannelThreads[threadId] = 0; requestsPerChannelThreads[threadId] = 0;
channelsToTreat.erase(channelsToTreatRev[channelToTreat]); channelsToTreat.erase(channelsToTreatRev[channelToTreat]);
@ -197,7 +197,7 @@ void treatChannels(unsigned short threadId)
deleteDirectory(channelToTreatDirectory); deleteDirectory(channelToTreatDirectory);
PRINT("Deleting directory finished.") PRINT("Deleting directory finished.")
PRINT(commentsCountThreads[threadId] << " comments were found for this channel.") PRINT(channelsCountThreads[threadId] << " comments were found for this channel.")
} }
channelsAlreadyTreatedAndToTreatMutex.unlock(); channelsAlreadyTreatedAndToTreatMutex.unlock();
@ -613,6 +613,8 @@ void treatChannelOrVideo(unsigned short threadId, bool isChannel, string id, str
// This function verifies that the given hasn't already been treated. // This function verifies that the given hasn't already been treated.
void addChannelToTreat(unsigned short threadId, string channelId) void addChannelToTreat(unsigned short threadId, string channelId)
{ {
channelsPerSecondCount++;
channelsCountThreads[threadId]++;
channelsAlreadyTreatedAndToTreatMutex.lock(); channelsAlreadyTreatedAndToTreatMutex.lock();
if(channelsAlreadyTreated.find(channelId) == channelsAlreadyTreated.end() && channelsToTreatRev.find(channelId) == channelsToTreatRev.end()) if(channelsAlreadyTreated.find(channelId) == channelsAlreadyTreated.end() && channelsToTreatRev.find(channelId) == channelsToTreatRev.end())
{ {
@ -639,8 +641,6 @@ void treatComment(unsigned short threadId, json comment, string channelId)
string channelId = snippet["authorChannelId"]["value"]; string channelId = snippet["authorChannelId"]["value"];
addChannelToTreat(threadId, channelId); addChannelToTreat(threadId, channelId);
} }
commentsCountThreads[threadId]++;
commentsPerSecondCount++;
} }
string join(vector<string> parts, string delimiter) string join(vector<string> parts, string delimiter)