Compare commits
7 Commits
eb8431746e
...
0.0.2
Author | SHA1 | Date | |
---|---|---|---|
4a11ac4196 | |||
c30847c1f5 | |||
221956438d | |||
ba78223c0c | |||
e86d629597 | |||
78b2bf18fa | |||
5bfceccb8e |
29
main.cpp
29
main.cpp
@@ -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.
|
YOUTUBE_OPERATIONAL_API_INSTANCE_URL = "http://localhost/YouTube-operational-API", // Can be "https://yt.lemnoslife.com" for instance.
|
||||||
CAPTIONS_DIRECTORY = "captions/",
|
CAPTIONS_DIRECTORY = "captions/",
|
||||||
DEBUG_DIRECTORY = "debug/",
|
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;
|
bool USE_YT_LEMNOSLIFE_COM_NO_KEY_SERVICE = false;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
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(channelsToTreat.size() << " channel(s) to treat")
|
||||||
MAIN_PRINT(channelsAlreadyTreated.size() << " channel(s) already treated")
|
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.
|
// 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.
|
// 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`.
|
// 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...")
|
PRINT("Compression finished, started deleting initial directory...")
|
||||||
deleteDirectory(channelToTreatDirectory);
|
deleteDirectory(channelToTreatDirectory);
|
||||||
PRINT("Deleting directory finished.")
|
PRINT("Deleting directory finished.")
|
||||||
|
|
||||||
PRINT(channelsCountThreads[threadId] << " comments were found for this channel.")
|
PRINT(channelsCountThreads[threadId] << " channels were found for this channel.")
|
||||||
}
|
}
|
||||||
|
|
||||||
channelsAlreadyTreatedAndToTreatMutex.unlock();
|
channelsAlreadyTreatedAndToTreatMutex.unlock();
|
||||||
@@ -577,7 +585,9 @@ void treatChannelOrVideo(unsigned short threadId, bool isChannel, string id, str
|
|||||||
json data = getJson(threadId, "playlistItems?part=snippet,contentDetails,status&playlistId=" + playlistToTreat + "&maxResults=50&pageToken=" + pageToken, true, channelToTreat, returnErrorIfPlaylistNotFound);
|
json data = getJson(threadId, "playlistItems?part=snippet,contentDetails,status&playlistId=" + playlistToTreat + "&maxResults=50&pageToken=" + pageToken, true, channelToTreat, returnErrorIfPlaylistNotFound);
|
||||||
if(data.contains("error"))
|
if(data.contains("error"))
|
||||||
{
|
{
|
||||||
EXIT_WITH_ERROR("Not listing captions on videos, as `playlistItems` hasn't found the `uploads` playlist!")
|
// `UCFoBM1VginhMH7lR56GtVbQ` doesn't have videos and is in this case for instance.
|
||||||
|
PRINT("Not listing captions on videos, as `playlistItems` hasn't found the `uploads` playlist!")
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
json items = data["items"];
|
json items = data["items"];
|
||||||
for(const auto& item : items)
|
for(const auto& item : items)
|
||||||
@@ -594,7 +604,7 @@ void treatChannelOrVideo(unsigned short threadId, bool isChannel, string id, str
|
|||||||
// We are obliged to precise the video id after `--`, otherwise if the video id starts with `-` it's considered as an argument.
|
// We are obliged to precise the video id after `--`, otherwise if the video id starts with `-` it's considered as an argument.
|
||||||
string cmdCommonPrefix = "yt-dlp --skip-download ",
|
string cmdCommonPrefix = "yt-dlp --skip-download ",
|
||||||
cmdCommonPostfix = " -o '" + channelCaptionsToTreatDirectory + "_' -- " + videoId;
|
cmdCommonPostfix = " -o '" + channelCaptionsToTreatDirectory + "_' -- " + videoId;
|
||||||
string cmd = cmdCommonPrefix + "--sub-lang all,-live_chat" + cmdCommonPostfix;
|
string cmd = cmdCommonPrefix + "--write-sub --sub-lang all,-live_chat" + cmdCommonPostfix;
|
||||||
exec(threadId, cmd);
|
exec(threadId, cmd);
|
||||||
|
|
||||||
// Secondly download the automatically generated captions.
|
// Secondly download the automatically generated captions.
|
||||||
@@ -621,7 +631,8 @@ void addChannelToTreat(unsigned short threadId, string channelId)
|
|||||||
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())
|
||||||
{
|
{
|
||||||
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;
|
channelsToTreat[channelsToTreatIndex] = channelId;
|
||||||
channelsToTreatRev[channelId] = channelsToTreatIndex;
|
channelsToTreatRev[channelId] = channelsToTreatIndex;
|
||||||
|
|
||||||
@@ -669,12 +680,14 @@ void exec(unsigned short threadId, string cmd, bool debug)
|
|||||||
toString << threadId;
|
toString << threadId;
|
||||||
string initialCmd = cmd,
|
string initialCmd = cmd,
|
||||||
threadIdStr = toString.str(),
|
threadIdStr = toString.str(),
|
||||||
debugCommonFilePath = DEBUG_DIRECTORY + threadIdStr,
|
debugCommonFilePath = CURRENT_WORKING_DIRECTORY + DEBUG_DIRECTORY + threadIdStr,
|
||||||
debugOutFilePath = debugCommonFilePath + ".out",
|
debugOutFilePath = debugCommonFilePath + ".out",
|
||||||
debugErrFilePath = debugCommonFilePath + ".err";
|
debugErrFilePath = debugCommonFilePath + ".err";
|
||||||
cmd += " >> " + debugOutFilePath;
|
cmd += " >> " + debugOutFilePath;
|
||||||
cmd += " 2>> " + debugErrFilePath;
|
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());
|
system(cmd.c_str());
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,8 @@ with open('nohup.out') as f:
|
|||||||
#print(line)
|
#print(line)
|
||||||
threadId = line.split(': ')[1]
|
threadId = line.split(': ')[1]
|
||||||
channelId = line.split(infix)[1].split(' (')[0]
|
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:
|
for threadId in threads:
|
||||||
channelId = threads[threadId]
|
channelId = threads[threadId]
|
||||||
print(threadId, channelId)
|
print(threadId, channelId)
|
||||||
|
Reference in New Issue
Block a user