Skip to content

Commit

Permalink
Fix for shelf type in Library
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Apr 14, 2024
1 parent 4022d7a commit 4e5dfed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/parser/classes/ItemSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class ItemSection extends YTNode {
this.contents = Parser.parseArray(data.contents);

if (data.targetId || data.sectionIdentifier) {
this.target_id = data.target_id || data.sectionIdentifier;
this.target_id = data.targetId || data.sectionIdentifier;
}

if (data.continuations) {
Expand Down
26 changes: 16 additions & 10 deletions src/parser/youtube/Library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import PageHeader from '../classes/PageHeader.js';

import type { Actions, ApiResponse } from '../../core/index.js';
import type { IBrowseResponse } from '../types/index.js';
import { ItemSection } from '../nodes.js';

class Library extends Feed<IBrowseResponse> {
header: PageHeader | null;
Expand All @@ -22,14 +23,19 @@ class Library extends Feed<IBrowseResponse> {

this.header = this.memo.getType(PageHeader).first();

const shelves = this.page.contents_memo.getType(Shelf);
const sections = this.page.contents_memo.getType(ItemSection);

this.sections = shelves.map((shelf: Shelf) => ({
type: shelf.icon_type,
title: shelf.title,
contents: shelf.content?.key('items').array() || [],
getAll: () => this.#getAll(shelf)
}));
this.sections = sections.filter((section) => section.contents.length > 0 && section.contents.first().type === 'Shelf')
.map((section) => {
const shelf = section.contents.first().as(Shelf);

return {
type: section.target_id,
title: shelf.title,
contents: shelf.content?.key('items').array() || [],
getAll: () => this.#getAll(shelf)
};
});
}

async #getAll(shelf: Shelf): Promise<Playlist | History | Feed> {
Expand All @@ -47,7 +53,7 @@ class Library extends Feed<IBrowseResponse> {
case 'LIKE':
case 'WATCH_LATER':
return new Playlist(this.actions, page, true);
case 'WATCH_HISTORY':
case 'library-recent':
return new History(this.actions, page, true);
case 'CONTENT_CUT':
return new Feed(this.actions, page, true);
Expand All @@ -57,7 +63,7 @@ class Library extends Feed<IBrowseResponse> {
}

get history() {
return this.sections.find((section) => section.type === 'WATCH_HISTORY');
return this.sections.find((section) => section.type === 'library-recent');
}

get watch_later() {
Expand All @@ -69,7 +75,7 @@ class Library extends Feed<IBrowseResponse> {
}

get playlists_section() {
return this.sections.find((section) => section.type === 'PLAYLISTS');
return this.sections.find((section) => section.type === 'library-playlists-shelf');
}

get clips() {
Expand Down

0 comments on commit 4e5dfed

Please sign in to comment.