#11: Add the treatment of channels' tab, but only postpone unlisted videos treatment
This commit is contained in:
parent
f114aac0cf
commit
fced9e0a3a
71
main.cpp
71
main.cpp
@ -46,9 +46,11 @@ unsigned int commentsPerSecondCount = 0;
|
||||
map<unsigned short, unsigned int> commentsCountThreads,
|
||||
requestsPerChannelThreads;
|
||||
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.
|
||||
string CHANNELS_DIRECTORY = "channels/",
|
||||
CHANNELS_FILE_PATH = "channels.txt",
|
||||
KEYS_FILE_PATH = "keys.txt",
|
||||
UNLISTED_VIDEOS_FILE_PATH = "unlistedVideos.txt",
|
||||
apiKey = "", // Will firstly be filled with `KEYS_FILE_PATH` first line.
|
||||
YOUTUBE_OPERATIONAL_API_INSTANCE_URL = "http://localhost/YouTube-operational-API"; // Can be "https://yt.lemnoslife.com" for instance.
|
||||
bool USE_YT_LEMNOSLIFE_COM_NO_KEY_SERVICE = false;
|
||||
@ -328,6 +330,75 @@ void treatChannelOrVideo(unsigned short threadId, bool isChannel, string id, str
|
||||
break;
|
||||
}
|
||||
}
|
||||
// `PLAYLISTS`
|
||||
pageToken = "";
|
||||
while(true)
|
||||
{
|
||||
json data = getJson(threadId, "channels?part=playlists&id=" + id + (pageToken == "" ? "" : "&pageToken=" + pageToken), false, id),
|
||||
items = data["items"];
|
||||
|
||||
for(const auto& item : items)
|
||||
{
|
||||
for(const auto& playlistSection : item["playlistSections"])
|
||||
{
|
||||
for(const auto& playlist : playlistSection["playlists"])
|
||||
{
|
||||
string playlistId = playlist["id"];
|
||||
//PRINT(threadId, playlistId)
|
||||
string pageToken = "";
|
||||
while(true)
|
||||
{
|
||||
json data = getJson(threadId, "playlistItems?part=contentDetails,snippet,status&playlistId=" + playlistId + "&maxResults=50&pageToken=" + pageToken, true, id),
|
||||
items = data["items"];
|
||||
for(const auto& item : items)
|
||||
{
|
||||
json snippet = item["snippet"];
|
||||
string privacyStatus = item["status"]["privacyStatus"];
|
||||
// `5-CXVU8si3A` in `PLTYUE9O6WCrjQsnOm56rMMNmFy_A-SjUx` has its privacy status on `privacyStatusUnspecified` and is inaccessible.
|
||||
// `GMiVi8xkEXA` in `PLTYUE9O6WCrgNpeSiryP8LYVX-7tOJ1f1` has its privacy status on `private`.
|
||||
// Of course `commentThreads?videoId=` doesn't work for these videos (same result on YouTube UI).
|
||||
// By hypothesis that the discovery algorithm never ends we can't postpone the treatment of these unlisted videos, because we can find such unlisted videos at any point in time (before or after the given channel treatment).
|
||||
// Maybe modifying this hypothesis would make sense, otherwise we have to treat them right-away (note that except code architecture, there is no recursion problem as documented on this function).
|
||||
if(privacyStatus != "public" && privacyStatus != "private" && snippet["title"] != "Deleted video")
|
||||
{
|
||||
string videoId = snippet["resourceId"]["videoId"],
|
||||
channelId = snippet["videoOwnerChannelId"];
|
||||
PRINT(threadId, "Found non public video (" << videoId << ") in: " << playlistId)
|
||||
string channelUnlistedVideosFilePath = CHANNELS_DIRECTORY + UNLISTED_VIDEOS_FILE_PATH;
|
||||
bool doesChannelUnlistedVideosFileExist = doesFileExist(channelUnlistedVideosFilePath);
|
||||
writeFile(threadId, channelUnlistedVideosFilePath, !doesChannelUnlistedVideosFileExist ? "w" : "a", (!doesChannelUnlistedVideosFileExist ? "" : "\n") + channelId);
|
||||
}
|
||||
if(snippet.contains("videoOwnerChannelId"))
|
||||
{
|
||||
// There isn't any `videoOwnerChannelId` to retrieve for `5-CXVU8si3A` for instance.
|
||||
string channelId = snippet["videoOwnerChannelId"];
|
||||
if(channelId != id)
|
||||
{
|
||||
addChannelToTreat(threadId, channelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(data.contains("nextPageToken"))
|
||||
{
|
||||
pageToken = data["nextPageToken"];
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!data["nextPageToken"].is_null())
|
||||
{
|
||||
pageToken = data["nextPageToken"];
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user