diff --git a/src/parser/classes/Alert.ts b/src/parser/classes/Alert.ts new file mode 100644 index 00000000..ffca5aaa --- /dev/null +++ b/src/parser/classes/Alert.ts @@ -0,0 +1,17 @@ +import Text from './misc/Text'; +import { YTNode } from '../helpers'; + +class Alert extends YTNode { + static type = 'Alert'; + + text: Text; + alert_type: string; + + constructor(data: any) { + super(); + this.text = new Text(data.text); + this.alert_type = data.type; + } +} + +export default Alert; \ No newline at end of file diff --git a/src/parser/index.ts b/src/parser/index.ts index fb57f95f..cf941545 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -9,6 +9,7 @@ import type Message from './classes/Message'; import type LiveChatParticipantsList from './classes/LiveChatParticipantsList'; import type LiveChatHeader from './classes/LiveChatHeader'; import type LiveChatItemList from './classes/LiveChatItemList'; +import type Alert from './classes/Alert'; import MusicMultiSelectMenuItem from './classes/menus/MusicMultiSelectMenuItem'; import Format from './classes/misc/Format'; @@ -137,6 +138,7 @@ export default class Parser { metadata: Parser.parse(data.metadata), microformat: data.microformat ? Parser.parseItem(data.microformat) : null, overlay: Parser.parseItem(data.overlay), + alerts: Parser.parseArray(data.alerts), refinements: data.refinements || null, estimated_results: data.estimatedResults ? parseInt(data.estimatedResults) : null, player_overlays: Parser.parse(data.playerOverlays), diff --git a/src/parser/map.ts b/src/parser/map.ts index 927ba51f..476a14bf 100644 --- a/src/parser/map.ts +++ b/src/parser/map.ts @@ -8,6 +8,7 @@ import { default as AccountItemSectionHeader } from './classes/AccountItemSectio import { default as AccountSectionList } from './classes/AccountSectionList'; import { default as AppendContinuationItemsAction } from './classes/actions/AppendContinuationItemsAction'; import { default as OpenPopupAction } from './classes/actions/OpenPopupAction'; +import { default as Alert } from './classes/Alert'; import { default as AnalyticsMainAppKeyMetrics } from './classes/analytics/AnalyticsMainAppKeyMetrics'; import { default as AnalyticsRoot } from './classes/analytics/AnalyticsRoot'; import { default as AnalyticsShortsCarouselCard } from './classes/analytics/AnalyticsShortsCarouselCard'; @@ -326,6 +327,7 @@ export const YTNodes = { AccountSectionList, AppendContinuationItemsAction, OpenPopupAction, + Alert, AnalyticsMainAppKeyMetrics, AnalyticsRoot, AnalyticsShortsCarouselCard, diff --git a/src/parser/youtube/Channel.ts b/src/parser/youtube/Channel.ts index 53f0c0c3..7d1b3ab5 100644 --- a/src/parser/youtube/Channel.ts +++ b/src/parser/youtube/Channel.ts @@ -18,7 +18,7 @@ import FeedFilterChipBar from '../classes/FeedFilterChipBar'; import ChannelSubMenu from '../classes/ChannelSubMenu'; import SortFilterSubMenu from '../classes/SortFilterSubMenu'; -import { InnertubeError } from '../../utils/Utils'; +import { ChannelError, InnertubeError } from '../../utils/Utils'; import type { AppendContinuationItemsAction, ReloadContinuationItemsCommand } from '..'; @@ -36,6 +36,13 @@ export default class Channel extends TabbedFeed { const metadata = this.page.metadata?.item().as(ChannelMetadata); const microformat = this.page.microformat?.as(MicroformatData); + if (this.page.alerts) { + const alert = this.page.alerts.first(); + if (alert?.alert_type === 'ERROR') { + throw new ChannelError(alert.text.toString()); + } + } + if (!metadata && !this.page.contents) throw new InnertubeError('Invalid channel', this); diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 12d389ab..1e0c9e31 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -25,6 +25,7 @@ export class MissingParamError extends InnertubeError { } export class OAuthError extends InnertubeError { } export class PlayerError extends Error { } export class SessionError extends Error { } +export class ChannelError extends Error { } /** * Compares given objects. May not work correctly for