Instead of looping on items
where we expect only one to be, we just use items[0]
This commit is contained in:
parent
59dc5676cc
commit
c17a33d181
119
main.cpp
119
main.cpp
@ -313,38 +313,32 @@ void treatChannelOrVideo(unsigned short threadId, bool isChannel, string id, str
|
||||
while(true)
|
||||
{
|
||||
json data = getJson(threadId, "channels?part=channels&id=" + id + (pageToken == "" ? "" : "&pageToken=" + pageToken), false, id),
|
||||
items = data["items"];
|
||||
for(const auto& item : items)
|
||||
channelSections = data["items"][0]["channelSections"];
|
||||
for(const auto& channelSection : channelSections)
|
||||
{
|
||||
json channelSections = item["channelSections"];
|
||||
for(const auto& channelSection : channelSections)
|
||||
for(const auto& sectionChannel : channelSection["sectionChannels"])
|
||||
{
|
||||
for(const auto& sectionChannel : channelSection["sectionChannels"])
|
||||
{
|
||||
string channelId = sectionChannel["channelId"];
|
||||
addChannelToTreat(threadId, channelId);
|
||||
}
|
||||
string channelId = sectionChannel["channelId"];
|
||||
addChannelToTreat(threadId, channelId);
|
||||
}
|
||||
if(channelSections.size() == 1)
|
||||
}
|
||||
if(channelSections.size() == 1)
|
||||
{
|
||||
json channelSection = channelSections[0];
|
||||
if(!channelSection["nextPageToken"].is_null())
|
||||
{
|
||||
json channelSection = channelSections[0];
|
||||
if(!channelSection["nextPageToken"].is_null())
|
||||
{
|
||||
pageToken = channelSection["nextPageToken"];
|
||||
}
|
||||
else
|
||||
{
|
||||
goto breakChannelsTreatment;
|
||||
}
|
||||
pageToken = channelSection["nextPageToken"];
|
||||
}
|
||||
else
|
||||
{
|
||||
goto breakChannelsTreatment;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
breakChannelsTreatment:
|
||||
;
|
||||
// `COMMUNITY`
|
||||
pageToken = "";
|
||||
while(true)
|
||||
@ -410,57 +404,54 @@ breakChannelsTreatment:
|
||||
while(true)
|
||||
{
|
||||
json data = getJson(threadId, "channels?part=playlists&id=" + id + (pageToken == "" ? "" : "&pageToken=" + pageToken), false, id),
|
||||
items = data["items"];
|
||||
playlistSections = data["items"][0]["playlistSections"];
|
||||
|
||||
for(const auto& item : items)
|
||||
for(const auto& playlistSection : playlistSections)
|
||||
{
|
||||
for(const auto& playlistSection : item["playlistSections"])
|
||||
for(const auto& playlist : playlistSection["playlists"])
|
||||
{
|
||||
for(const auto& playlist : playlistSection["playlists"])
|
||||
string playlistId = playlist["id"];
|
||||
//PRINT(threadId, playlistId)
|
||||
string pageToken = "";
|
||||
while(true)
|
||||
{
|
||||
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 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")
|
||||
{
|
||||
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("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)
|
||||
{
|
||||
string videoId = snippet["resourceId"]["videoId"],
|
||||
channelId = snippet["videoOwnerChannelId"];
|
||||
PRINT("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);
|
||||
}
|
||||
addChannelToTreat(threadId, channelId);
|
||||
}
|
||||
}
|
||||
if(data.contains("nextPageToken"))
|
||||
{
|
||||
pageToken = data["nextPageToken"];
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(data.contains("nextPageToken"))
|
||||
{
|
||||
pageToken = data["nextPageToken"];
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user