Skip to content

Commit

Permalink
chore: merge main into Wykerd-refactor-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Wykerd committed Mar 13, 2023
2 parents fd41463 + b82b720 commit 1308382
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 48 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const videoInfo = await youtube.getInfo('videoId');
// now convert to a dash manifest
// again - to be able to stream the video in the browser - we must proxy the requests through our own server
// to do this, we provide a method to transform the URLs before writing them to the manifest
const manifest = videoInfo.toDash(url => {
const manifest = await videoInfo.toDash(url => {
// modify the url
// and return it
return url;
Expand Down Expand Up @@ -300,6 +300,9 @@ Retrieves video info, including playback data and even layout elements such as m
- `<info>#getLiveChat()`
- Returns a LiveChat instance.

- `<info>#getTrailerInfo()`
- Returns trailer info in a new `VideoInfo` instance, or `null` if none. Typically available for non-purchased movies or films.

- `<info>#chooseFormat(options)`
- Used to choose streaming data formats.

Expand All @@ -324,6 +327,9 @@ Retrieves video info, including playback data and even layout elements such as m
- `<info>#autoplay_video_endpoint`
- Returns the endpoint of the video for Autoplay.

- `<info>#has_trailer`
- Checks if trailer is available.

- `<info>#page`
- Returns original InnerTube response (sanitized).

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function main() {

showUI(true);

const dash = info.toDash((url) => {
const dash = await info.toDash((url) => {
url.searchParams.set('__host', url.host);
url.host = 'localhost:8080';
url.protocol = 'http';
Expand Down
34 changes: 34 additions & 0 deletions src/parser/classes/GridMovie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Parser from '../index.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import { YTNode } from '../helpers.js';
import MetadataBadge from './MetadataBadge.js';

class GridMovie extends YTNode {
static type = 'GridMovie';

id: string;
title: Text;
thumbnails: Thumbnail[];
duration: Text | null;
endpoint: NavigationEndpoint;
badges: MetadataBadge[];
metadata: Text;
thumbnail_overlays;

constructor(data: any) {
super();
const length_alt = data.thumbnailOverlays.find((overlay: any) => overlay.hasOwnProperty('thumbnailOverlayTimeStatusRenderer'))?.thumbnailOverlayTimeStatusRenderer;
this.id = data.videoId;
this.title = new Text(data.title);
this.thumbnails = Thumbnail.fromResponse(data.thumbnail);
this.duration = data.lengthText ? new Text(data.lengthText) : length_alt?.text ? new Text(length_alt.text) : null;
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.badges = Parser.parseArray<MetadataBadge>(data.badges, MetadataBadge);
this.metadata = new Text(data.metadata);
this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays);
}
}

export default GridMovie;
25 changes: 25 additions & 0 deletions src/parser/classes/HorizontalMovieList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Parser from '../index.js';
import { YTNode } from '../helpers.js';
import Button from './Button.js';

class HorizontalMovieList extends YTNode {
static type = 'HorizontalMovieList';

items;
previous_button: Button | null;
next_button: Button | null;

constructor(data: any) {
super();
this.items = Parser.parseArray(data.items);
this.previous_button = Parser.parseItem<Button>(data.previousButton, Button);
this.next_button = Parser.parseItem<Button>(data.nextButton, Button);
}

// XXX: alias for consistency
get contents() {
return this.items;
}
}

export default HorizontalMovieList;
27 changes: 27 additions & 0 deletions src/parser/classes/InfoPanelContainer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { YTNode } from '../helpers.js';
import Parser, { RawNode } from '../index.js';
import InfoPanelContent from './InfoPanelContent.js';
import Menu from './menus/Menu.js';
import Text from './misc/Text.js';

export default class InfoPanelContainer extends YTNode {
static type = 'InfoPanelContainer';

icon_type?: string;
title: Text;
menu: Menu | null;
content: YTNode | null;
background: string;

constructor(data: RawNode) {
super();
this.title = new Text(data.title);
this.menu = Parser.parseItem(data.menu, Menu);
this.content = Parser.parseItem(data.content, InfoPanelContent);
this.background = data.background;

if (data.icon?.iconType) {
this.icon_type = data.icon.iconType;
}
}
}
33 changes: 33 additions & 0 deletions src/parser/classes/InfoPanelContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { YTNode } from '../helpers.js';
import { RawNode } from '../index.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';

export default class InfoPanelContent extends YTNode {
static type = 'InfoPanelContent';

title: Text;
inline_link_icon_type?: string;
source: Text;
paragraphs: Text[];
thumbnail: Thumbnail[];
source_endpoint: NavigationEndpoint;
truncate_paragraphs: boolean;
background: string;

constructor(data: RawNode) {
super();
this.title = new Text(data.title);
this.source = new Text(data.source);
this.paragraphs = data.paragraphs.map((p: RawNode) => new Text(p));
this.thumbnail = Thumbnail.fromResponse(data.thumbnail);
this.source_endpoint = new NavigationEndpoint(data.sourceEndpoint);
this.truncate_paragraphs = !!data.truncateParagraphs;
this.background = data.background;

if (data.inlineLinkIcon?.iconType) {
this.inline_link_icon_type = data.inlineLinkIcon.iconType;
}
}
}
32 changes: 32 additions & 0 deletions src/parser/classes/PlayerLegacyDesktopYpcTrailer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { YTNode } from '../helpers.js';
import { Parser, RawNode } from '../index.js';
import YpcTrailer from './YpcTrailer.js';

class PlayerLegacyDesktopYpcTrailer extends YTNode {
static type = 'PlayerLegacyDesktopYpcTrailer';

video_id: string;
title: string;
thumbnail: string;
offer_headline: string;
offer_description: string;
offer_id: string;
offer_button_text: string;
video_message: string;
trailer: YpcTrailer | null;

constructor(data: RawNode) {
super();
this.video_id = data.trailerVideoId;
this.title = data.itemTitle;
this.thumbnail = data.itemThumbnail;
this.offer_headline = data.offerHeadline;
this.offer_description = data.offerDescription;
this.offer_id = data.offerId;
this.offer_button_text = data.offerButtonText;
this.video_message = data.fullVideoMessage;
this.trailer = Parser.parseItem<YpcTrailer>(data.ypcTrailer, YpcTrailer);
}
}

export default PlayerLegacyDesktopYpcTrailer;
6 changes: 6 additions & 0 deletions src/parser/classes/Playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import Author from './misc/Author.js';
import { YTNode } from '../helpers.js';
import NavigatableText from './misc/NavigatableText.js';

class Playlist extends YTNode {
static type = 'Playlist';
Expand All @@ -20,6 +21,7 @@ class Playlist extends YTNode {
badges;
endpoint: NavigationEndpoint;
thumbnail_overlays;
view_playlist?: NavigatableText;

constructor(data: any) {
super();
Expand All @@ -39,6 +41,10 @@ class Playlist extends YTNode {
this.badges = Parser.parseArray(data.ownerBadges);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays);

if (data.viewPlaylistText) {
this.view_playlist = new NavigatableText(data.viewPlaylistText);
}
}
}

Expand Down
15 changes: 14 additions & 1 deletion src/parser/classes/SearchFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,26 @@ class SearchFilter extends YTNode {
label: Text;
endpoint: NavigationEndpoint;
tooltip: string;
status?: string;

constructor(data: RawNode) {
super();

this.label = new Text(data.label);
this.endpoint = new NavigationEndpoint(data.endpoint);
this.endpoint = new NavigationEndpoint(data.endpoint || data.navigationEndpoint);
this.tooltip = data.tooltip;

if (data.status) {
this.status = data.status;
}
}

get disabled(): boolean {
return this.status === 'FILTER_STATUS_DISABLED';
}

get selected(): boolean {
return this.status === 'FILTER_STATUS_SELECTED';
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/parser/classes/Shelf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Text from './misc/Text.js';
import Parser from '../index.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import { YTNode } from '../helpers.js';
import Button from './Button.js';

class Shelf extends YTNode {
static type = 'Shelf';
Expand All @@ -11,6 +12,7 @@ class Shelf extends YTNode {
content: YTNode | null;
icon_type?: string;
menu?: YTNode | null;
play_all_button?: Button | null;

constructor(data: any) {
super();
Expand All @@ -29,6 +31,10 @@ class Shelf extends YTNode {
if (data.menu) {
this.menu = Parser.parseItem(data.menu);
}

if (data.playAllButton) {
this.play_all_button = Parser.parseItem<Button>(data.playAllButton);
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/parser/classes/YpcTrailer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { YTNode } from '../helpers.js';
import { RawNode } from '../index.js';

class YpcTrailer extends YTNode {
static type = 'YpcTrailer';

video_message: string;
player_response;

constructor(data: RawNode) {
super();
this.video_message = data.fullVideoMessage;
this.player_response = data.unserializedPlayerResponse;
}
}

export default YpcTrailer;
2 changes: 2 additions & 0 deletions src/parser/classes/misc/Format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { RawNode } from '../../index.js';
class Format {
itag: number;
mime_type: string;
is_type_otf: boolean;
bitrate: number;
average_bitrate: number;
width: number;
Expand Down Expand Up @@ -48,6 +49,7 @@ class Format {
constructor(data: RawNode) {
this.itag = data.itag;
this.mime_type = data.mimeType;
this.is_type_otf = data.type === 'FORMAT_STREAM_TYPE_OTF';
this.bitrate = data.bitrate;
this.average_bitrate = data.averageBitrate;
this.width = data.width || undefined;
Expand Down
18 changes: 18 additions & 0 deletions src/parser/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ import { default as GridChannel } from './classes/GridChannel.js';
export { GridChannel };
import { default as GridHeader } from './classes/GridHeader.js';
export { GridHeader };
import { default as GridMovie } from './classes/GridMovie.js';
export { GridMovie };
import { default as GridPlaylist } from './classes/GridPlaylist.js';
export { GridPlaylist };
import { default as GridVideo } from './classes/GridVideo.js';
Expand Down Expand Up @@ -226,8 +228,14 @@ import { default as HorizontalCardList } from './classes/HorizontalCardList.js';
export { HorizontalCardList };
import { default as HorizontalList } from './classes/HorizontalList.js';
export { HorizontalList };
import { default as HorizontalMovieList } from './classes/HorizontalMovieList.js';
export { HorizontalMovieList };
import { default as IconLink } from './classes/IconLink.js';
export { IconLink };
import { default as InfoPanelContainer } from './classes/InfoPanelContainer.js';
export { InfoPanelContainer };
import { default as InfoPanelContent } from './classes/InfoPanelContent.js';
export { InfoPanelContent };
import { default as InteractiveTabbedHeader } from './classes/InteractiveTabbedHeader.js';
export { InteractiveTabbedHeader };
import { default as ItemSection } from './classes/ItemSection.js';
Expand Down Expand Up @@ -451,6 +459,8 @@ import { default as PlayerErrorMessage } from './classes/PlayerErrorMessage.js';
export { PlayerErrorMessage };
import { default as PlayerLegacyDesktopYpcOffer } from './classes/PlayerLegacyDesktopYpcOffer.js';
export { PlayerLegacyDesktopYpcOffer };
import { default as PlayerLegacyDesktopYpcTrailer } from './classes/PlayerLegacyDesktopYpcTrailer.js';
export { PlayerLegacyDesktopYpcTrailer };
import { default as PlayerLiveStoryboardSpec } from './classes/PlayerLiveStoryboardSpec.js';
export { PlayerLiveStoryboardSpec };
import { default as PlayerMicroformat } from './classes/PlayerMicroformat.js';
Expand Down Expand Up @@ -673,6 +683,8 @@ import { default as WatchNextEndScreen } from './classes/WatchNextEndScreen.js';
export { WatchNextEndScreen };
import { default as WatchNextTabbedResults } from './classes/WatchNextTabbedResults.js';
export { WatchNextTabbedResults };
import { default as YpcTrailer } from './classes/YpcTrailer.js';
export { YpcTrailer };
import { default as AnchoredSection } from './classes/ytkids/AnchoredSection.js';
export { AnchoredSection };
import { default as KidsCategoriesHeader } from './classes/ytkids/KidsCategoriesHeader.js';
Expand Down Expand Up @@ -779,6 +791,7 @@ const map: Record<string, YTNodeConstructor> = {
Grid,
GridChannel,
GridHeader,
GridMovie,
GridPlaylist,
GridVideo,
GuideCollapsibleEntry,
Expand All @@ -795,7 +808,10 @@ const map: Record<string, YTNodeConstructor> = {
HistorySuggestion,
HorizontalCardList,
HorizontalList,
HorizontalMovieList,
IconLink,
InfoPanelContainer,
InfoPanelContent,
InteractiveTabbedHeader,
ItemSection,
ItemSectionHeader,
Expand Down Expand Up @@ -903,6 +919,7 @@ const map: Record<string, YTNodeConstructor> = {
PlayerCaptionsTracklist,
PlayerErrorMessage,
PlayerLegacyDesktopYpcOffer,
PlayerLegacyDesktopYpcTrailer,
PlayerLiveStoryboardSpec,
PlayerMicroformat,
PlayerOverlay,
Expand Down Expand Up @@ -1014,6 +1031,7 @@ const map: Record<string, YTNodeConstructor> = {
WatchCardSectionSequence,
WatchNextEndScreen,
WatchNextTabbedResults,
YpcTrailer,
AnchoredSection,
KidsCategoriesHeader,
KidsCategoryTab,
Expand Down
Loading

0 comments on commit 1308382

Please sign in to comment.