Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Attempt] Fix for shelf type in Library #638

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading