youtubei
Version:
Simple package to get information from youtube such as videos, playlists, channels, video information & comments, related videos, up next video, and more!
51 lines (50 loc) • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SearchResultParser = void 0;
const common_1 = require("../../common");
const BaseChannel_1 = require("../BaseChannel");
const PlaylistCompact_1 = require("../PlaylistCompact");
const VideoCompact_1 = require("../VideoCompact");
class SearchResultParser {
static parseInitialSearchResult(data, client) {
const sectionListContents = data.contents.twoColumnSearchResultsRenderer.primaryContents.sectionListRenderer
.contents;
return {
data: SearchResultParser.parseSearchResult(sectionListContents, client),
continuation: common_1.getContinuationFromItems(sectionListContents),
};
}
static parseContinuationSearchResult(data, client) {
const sectionListContents = data.onResponseReceivedCommands[0].appendContinuationItemsAction.continuationItems;
return {
data: SearchResultParser.parseSearchResult(sectionListContents, client),
continuation: common_1.getContinuationFromItems(sectionListContents),
};
}
static parseSearchResult(sectionListContents, client) {
const rawContents = sectionListContents
.filter((c) => "itemSectionRenderer" in c)
.at(-1).itemSectionRenderer.contents;
const contents = [];
for (const c of rawContents) {
if ("playlistRenderer" in c)
contents.push(new PlaylistCompact_1.PlaylistCompact({ client }).load(c.playlistRenderer));
else if ("videoRenderer" in c)
contents.push(new VideoCompact_1.VideoCompact({ client }).load(c.videoRenderer));
else if ("channelRenderer" in c)
contents.push(new BaseChannel_1.BaseChannel({ client }).load(c.channelRenderer));
else if ("lockupViewModel" in c) {
// new data structure for search result
const type = c.lockupViewModel.contentType;
if (type === "LOCKUP_CONTENT_TYPE_VIDEO") {
contents.push(new VideoCompact_1.VideoCompact({ client }).loadLockup(c.lockupViewModel));
}
else if (type === "LOCKUP_CONTENT_TYPE_PLAYLIST") {
contents.push(new PlaylistCompact_1.PlaylistCompact({ client }).loadLockup(c.lockupViewModel));
}
}
}
return contents;
}
}
exports.SearchResultParser = SearchResultParser;