mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-07-04 12:47:04 +00:00
feat: extract channel error alert
This commit is contained in:
17
src/parser/classes/Alert.ts
Normal file
17
src/parser/classes/Alert.ts
Normal file
@@ -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;
|
||||||
@@ -9,6 +9,7 @@ import type Message from './classes/Message';
|
|||||||
import type LiveChatParticipantsList from './classes/LiveChatParticipantsList';
|
import type LiveChatParticipantsList from './classes/LiveChatParticipantsList';
|
||||||
import type LiveChatHeader from './classes/LiveChatHeader';
|
import type LiveChatHeader from './classes/LiveChatHeader';
|
||||||
import type LiveChatItemList from './classes/LiveChatItemList';
|
import type LiveChatItemList from './classes/LiveChatItemList';
|
||||||
|
import type Alert from './classes/Alert';
|
||||||
|
|
||||||
import MusicMultiSelectMenuItem from './classes/menus/MusicMultiSelectMenuItem';
|
import MusicMultiSelectMenuItem from './classes/menus/MusicMultiSelectMenuItem';
|
||||||
import Format from './classes/misc/Format';
|
import Format from './classes/misc/Format';
|
||||||
@@ -137,6 +138,7 @@ export default class Parser {
|
|||||||
metadata: Parser.parse(data.metadata),
|
metadata: Parser.parse(data.metadata),
|
||||||
microformat: data.microformat ? Parser.parseItem(data.microformat) : null,
|
microformat: data.microformat ? Parser.parseItem(data.microformat) : null,
|
||||||
overlay: Parser.parseItem(data.overlay),
|
overlay: Parser.parseItem(data.overlay),
|
||||||
|
alerts: Parser.parseArray<Alert>(data.alerts),
|
||||||
refinements: data.refinements || null,
|
refinements: data.refinements || null,
|
||||||
estimated_results: data.estimatedResults ? parseInt(data.estimatedResults) : null,
|
estimated_results: data.estimatedResults ? parseInt(data.estimatedResults) : null,
|
||||||
player_overlays: Parser.parse(data.playerOverlays),
|
player_overlays: Parser.parse(data.playerOverlays),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { default as AccountItemSectionHeader } from './classes/AccountItemSectio
|
|||||||
import { default as AccountSectionList } from './classes/AccountSectionList';
|
import { default as AccountSectionList } from './classes/AccountSectionList';
|
||||||
import { default as AppendContinuationItemsAction } from './classes/actions/AppendContinuationItemsAction';
|
import { default as AppendContinuationItemsAction } from './classes/actions/AppendContinuationItemsAction';
|
||||||
import { default as OpenPopupAction } from './classes/actions/OpenPopupAction';
|
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 AnalyticsMainAppKeyMetrics } from './classes/analytics/AnalyticsMainAppKeyMetrics';
|
||||||
import { default as AnalyticsRoot } from './classes/analytics/AnalyticsRoot';
|
import { default as AnalyticsRoot } from './classes/analytics/AnalyticsRoot';
|
||||||
import { default as AnalyticsShortsCarouselCard } from './classes/analytics/AnalyticsShortsCarouselCard';
|
import { default as AnalyticsShortsCarouselCard } from './classes/analytics/AnalyticsShortsCarouselCard';
|
||||||
@@ -326,6 +327,7 @@ export const YTNodes = {
|
|||||||
AccountSectionList,
|
AccountSectionList,
|
||||||
AppendContinuationItemsAction,
|
AppendContinuationItemsAction,
|
||||||
OpenPopupAction,
|
OpenPopupAction,
|
||||||
|
Alert,
|
||||||
AnalyticsMainAppKeyMetrics,
|
AnalyticsMainAppKeyMetrics,
|
||||||
AnalyticsRoot,
|
AnalyticsRoot,
|
||||||
AnalyticsShortsCarouselCard,
|
AnalyticsShortsCarouselCard,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import FeedFilterChipBar from '../classes/FeedFilterChipBar';
|
|||||||
import ChannelSubMenu from '../classes/ChannelSubMenu';
|
import ChannelSubMenu from '../classes/ChannelSubMenu';
|
||||||
import SortFilterSubMenu from '../classes/SortFilterSubMenu';
|
import SortFilterSubMenu from '../classes/SortFilterSubMenu';
|
||||||
|
|
||||||
import { InnertubeError } from '../../utils/Utils';
|
import { ChannelError, InnertubeError } from '../../utils/Utils';
|
||||||
|
|
||||||
import type { AppendContinuationItemsAction, ReloadContinuationItemsCommand } from '..';
|
import type { AppendContinuationItemsAction, ReloadContinuationItemsCommand } from '..';
|
||||||
|
|
||||||
@@ -36,6 +36,13 @@ export default class Channel extends TabbedFeed {
|
|||||||
const metadata = this.page.metadata?.item().as(ChannelMetadata);
|
const metadata = this.page.metadata?.item().as(ChannelMetadata);
|
||||||
const microformat = this.page.microformat?.as(MicroformatData);
|
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)
|
if (!metadata && !this.page.contents)
|
||||||
throw new InnertubeError('Invalid channel', this);
|
throw new InnertubeError('Invalid channel', this);
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export class MissingParamError extends InnertubeError { }
|
|||||||
export class OAuthError extends InnertubeError { }
|
export class OAuthError extends InnertubeError { }
|
||||||
export class PlayerError extends Error { }
|
export class PlayerError extends Error { }
|
||||||
export class SessionError extends Error { }
|
export class SessionError extends Error { }
|
||||||
|
export class ChannelError extends Error { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares given objects. May not work correctly for
|
* Compares given objects. May not work correctly for
|
||||||
|
|||||||
Reference in New Issue
Block a user