5 Commits

2 changed files with 19 additions and 7 deletions

View File

@@ -60,7 +60,8 @@ string CHANNELS_DIRECTORY = "channels/",
YOUTUBE_OPERATIONAL_API_INSTANCE_URL = "http://localhost/YouTube-operational-API", // Can be "https://yt.lemnoslife.com" for instance.
CAPTIONS_DIRECTORY = "captions/",
DEBUG_DIRECTORY = "debug/",
YOUTUBE_API_REQUESTS_DIRECTORY = "requests/";
YOUTUBE_API_REQUESTS_DIRECTORY = "requests/",
CURRENT_WORKING_DIRECTORY;
bool USE_YT_LEMNOSLIFE_COM_NO_KEY_SERVICE = false;
int main(int argc, char *argv[])
@@ -129,6 +130,13 @@ int main(int argc, char *argv[])
}
}
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
CURRENT_WORKING_DIRECTORY = string(cwd) + "/";
} else {
MAIN_EXIT_WITH_ERROR("`getcwd()` error");
}
MAIN_PRINT(channelsToTreat.size() << " channel(s) to treat")
MAIN_PRINT(channelsAlreadyTreated.size() << " channel(s) already treated")
@@ -194,13 +202,13 @@ void treatChannels(unsigned short threadId)
// As I haven't found any well-known library that compress easily a directory, I have chosen to rely on `zip` cli.
// We precise no `debug`ging, as otherwise the zipping operation doesn't work as expected.
// As the zipping process isn't recursive, we can't just rely on `ls`, but we are obliged to use `find`.
exec(threadId, "cd " + channelToTreatDirectory + " && find | zip ../" + channelToTreat + ".zip -@", false);
exec(threadId, "cd " + channelToTreatDirectory + " && find | zip ../" + channelToTreat + ".zip -@");
PRINT("Compression finished, started deleting initial directory...")
deleteDirectory(channelToTreatDirectory);
PRINT("Deleting directory finished.")
PRINT(channelsCountThreads[threadId] << " comments were found for this channel.")
PRINT(channelsCountThreads[threadId] << " channels were found for this channel.")
}
channelsAlreadyTreatedAndToTreatMutex.unlock();
@@ -623,7 +631,8 @@ void addChannelToTreat(unsigned short threadId, string channelId)
channelsAlreadyTreatedAndToTreatMutex.lock();
if(channelsAlreadyTreated.find(channelId) == channelsAlreadyTreated.end() && channelsToTreatRev.find(channelId) == channelsToTreatRev.end())
{
unsigned int channelsToTreatIndex = channelsToTreat.end()->first + 1;
// It is unclear to me why `channelsToTreat.end()->first + 1` doesn't work here.
unsigned int channelsToTreatIndex = channelsToTreat.rbegin()->first + 1;
channelsToTreat[channelsToTreatIndex] = channelId;
channelsToTreatRev[channelId] = channelsToTreatIndex;
@@ -671,12 +680,14 @@ void exec(unsigned short threadId, string cmd, bool debug)
toString << threadId;
string initialCmd = cmd,
threadIdStr = toString.str(),
debugCommonFilePath = DEBUG_DIRECTORY + threadIdStr,
debugCommonFilePath = CURRENT_WORKING_DIRECTORY + DEBUG_DIRECTORY + threadIdStr,
debugOutFilePath = debugCommonFilePath + ".out",
debugErrFilePath = debugCommonFilePath + ".err";
cmd += " >> " + debugOutFilePath;
cmd += " 2>> " + debugErrFilePath;
cmd += "; echo \"" + initialCmd + "\" | tee -a " + debugOutFilePath + " " + debugErrFilePath;
writeFile(threadId, debugOutFilePath, "a", initialCmd + "\n");
writeFile(threadId, debugErrFilePath, "a", initialCmd + "\n");
}
system(cmd.c_str());
}

View File

@@ -14,7 +14,8 @@ with open('nohup.out') as f:
#print(line)
threadId = line.split(': ')[1]
channelId = line.split(infix)[1].split(' (')[0]
threads[threadId] = channelId
if threadId.isdigit() and channelId.startswith('UC') and len(channelId) == 24:
threads[threadId] = channelId
for threadId in threads:
channelId = threads[threadId]
print(threadId, channelId)