-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Kids): Add
blockChannel
command to easily block channels (#503)
* Add blockChannel command to support easily blocking content for supervised accounts. * Moved blockChannel functionality to the Kids client and updated API docs. * Fix whitepsace issues. * Resolve remaining linting errors. * Avoid changing interaction manager. Remove comment for ToggleButton change. * chore: clean up --------- Co-authored-by: LuanRT <[email protected]>
- Loading branch information
Showing
12 changed files
with
179 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Innertube, UniversalCache } from 'youtubei.js'; | ||
|
||
(async () => { | ||
const yt = await Innertube.create({ cache: new UniversalCache(true, './credcache') }); | ||
|
||
yt.session.on('auth-pending', (data) => { | ||
console.log(`Go to ${data.verification_url} in your browser and enter code ${data.user_code} to authenticate.`); | ||
}); | ||
yt.session.on('auth', async () => { | ||
console.log('Sign in successful'); | ||
await yt.session.oauth.cacheCredentials(); | ||
}); | ||
yt.session.on('update-credentials', async () => { | ||
await yt.session.oauth.cacheCredentials(); | ||
}); | ||
|
||
// Attempt to sign in | ||
await yt.session.signIn(); | ||
|
||
// Block Channel for all kids / profiles on the signed-in account. | ||
const resp = await yt.kids.blockChannel('UCpbpfcZfo-hoDAx2m1blFhg'); | ||
console.info('Blocked channel for ', resp.length, ' profiles.'); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { IBlocklistPickerRequest, BlocklistPickerRequestEndpointOptions } from '../../../types/index.js'; | ||
|
||
export const PATH = '/kids/get_kids_blocklist_picker'; | ||
|
||
/** | ||
* Builds a `/kids/get_kids_blocklist_picker` request payload. | ||
* @param options - The options to use. | ||
* @returns The payload. | ||
*/ | ||
export function build(options: BlocklistPickerRequestEndpointOptions): IBlocklistPickerRequest { | ||
return { blockedForKidsContent: { external_channel_id: options.channel_id } }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * as BlocklistPickerEndpoint from './BlocklistPickerEndpoint.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Text from '../misc/Text.js'; | ||
import { YTNode } from '../../helpers.js'; | ||
import Button from '../Button.js'; | ||
import Parser, { type RawNode } from '../../index.js'; | ||
import KidsBlocklistPickerItem from './KidsBlocklistPickerItem.js'; | ||
|
||
export default class KidsBlocklistPicker extends YTNode { | ||
static type = 'KidsBlocklistPicker'; | ||
|
||
title: Text; | ||
child_rows: KidsBlocklistPickerItem[] | null; | ||
done_button: Button | null; | ||
successful_toast_action_message: Text; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
this.title = new Text(data.title); | ||
this.child_rows = Parser.parse(data.childRows, true, [ KidsBlocklistPickerItem ]); | ||
this.done_button = Parser.parseItem(data.doneButton, [ Button ]); | ||
this.successful_toast_action_message = new Text(data.successfulToastActionMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Text from '../misc/Text.js'; | ||
import { YTNode } from '../../helpers.js'; | ||
import Parser, { type RawNode } from '../../index.js'; | ||
import ToggleButton from '../ToggleButton.js'; | ||
import Thumbnail from '../misc/Thumbnail.js'; | ||
import type Actions from '../../../core/Actions.js'; | ||
import { InnertubeError } from '../../../utils/Utils.js'; | ||
import { type ApiResponse } from '../../../core/Actions.js'; | ||
|
||
export default class KidsBlocklistPickerItem extends YTNode { | ||
static type = 'KidsBlocklistPickerItem'; | ||
|
||
#actions?: Actions; | ||
|
||
child_display_name: Text; | ||
child_account_description: Text; | ||
avatar: Thumbnail[]; | ||
block_button: ToggleButton | null; | ||
blocked_entity_key: string; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
this.child_display_name = new Text(data.childDisplayName); | ||
this.child_account_description = new Text(data.childAccountDescription); | ||
this.avatar = Thumbnail.fromResponse(data.avatar); | ||
this.block_button = Parser.parseItem(data.blockButton, [ ToggleButton ]); | ||
this.blocked_entity_key = data.blockedEntityKey; | ||
} | ||
|
||
async blockChannel(): Promise<ApiResponse> { | ||
if (!this.#actions) | ||
throw new InnertubeError('An active caller must be provide to perform this operation.'); | ||
|
||
const button = this.block_button; | ||
|
||
if (!button) | ||
throw new InnertubeError('Block button was not found.', { child_display_name: this.child_display_name }); | ||
|
||
if (button.is_toggled) | ||
throw new InnertubeError('This channel is already blocked.', { child_display_name: this.child_display_name }); | ||
|
||
const response = await button.endpoint.call(this.#actions, { parse: false }); | ||
return response; | ||
} | ||
|
||
setActions(actions: Actions | undefined) { | ||
this.#actions = actions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters