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 e248ba5
Show file tree
Hide file tree
Showing 16 changed files with 388 additions and 50 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
4 changes: 2 additions & 2 deletions src/core/MediaInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class MediaInfo {
* @param format_filter - Function to filter the formats.
* @returns DASH manifest
*/
toDash(url_transformer?: URLTransformer, format_filter?: FormatFilter): string {
async toDash(url_transformer?: URLTransformer, format_filter?: FormatFilter): Promise<string> {
return FormatUtils.toDash(this.streaming_data, url_transformer, format_filter, this.#cpn, this.#actions.session.player);
}

Expand Down Expand Up @@ -90,7 +90,7 @@ export class MediaInfo {
/**
* Content Playback Nonce.
*/
get cpn(): string | undefined {
get cpn(): string {
return this.#cpn;
}

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(data.playAllButton, Button);
}
}
}

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
Loading

0 comments on commit e248ba5

Please sign in to comment.