-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(VideoInfo.ts): reimplement
get music_tracks
(#409)
* fix(VideoInfo.ts): reimplement `get music_tracks` - Add parser classes to parse needed data - Add `CarouselLockup` - Add `EngagementPanelSectionList` - Add `InfoRow` - Add `StructuredDescriptionContent` - Add `VideoDescriptionMusicSection` - Add `VideoDescriptionHeader` - Add `Factoid` - Add `ExpandableVideoDescriptionBody` - Add `AdsEngagementPanelContent` - Add `engagement_panels` to raw and parsed next responses - Add `engagement_panels` parsing code to `parser.ts` * Check for song inside of video_lockup first before checking info_rows * Add support for pulling artist ids out of music_tracks - Add support for WRITERS InfoRow - Check for video id inside of naviagation endpoint on info_row metadata * Add `AdsEngagementPanelContent` to ignore list * Switch `map => parseItem` to `parseArray` * Use `Text` && `NavigationEndpoint` * Replace `String` with `Text` in `ExpandableVideoDescriptionBody`
- Loading branch information
1 parent
a11e596
commit e434bb2
Showing
13 changed files
with
240 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { type ObservedArray, YTNode } from '../helpers.js'; | ||
import InfoRow from './InfoRow.js'; | ||
import Parser, { type RawNode } from '../index.js'; | ||
import CompactVideo from './CompactVideo.js'; | ||
|
||
export default class CarouselLockup extends YTNode { | ||
static type = 'CarouselLockup'; | ||
|
||
info_rows: ObservedArray<InfoRow>; | ||
video_lockup?: CompactVideo; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
this.info_rows = Parser.parseArray(data.infoRows, InfoRow); | ||
const video_lockup = Parser.parseItem(data.videoLockup, CompactVideo); | ||
if (video_lockup != null) { | ||
this.video_lockup = video_lockup; | ||
} | ||
} | ||
} |
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,20 @@ | ||
import { YTNode } from '../helpers.js'; | ||
import Parser, { type RawNode } from '../index.js'; | ||
import ContinuationItem from './ContinuationItem.js'; | ||
import SectionList from './SectionList.js'; | ||
import StructuredDescriptionContent from './StructuredDescriptionContent.js'; | ||
|
||
export default class EngagementPanelSectionList extends YTNode { | ||
static type = 'EngagementPanelSectionList'; | ||
|
||
target_id: String; | ||
content?: SectionList|ContinuationItem|StructuredDescriptionContent; | ||
constructor(data: RawNode) { | ||
super(); | ||
this.target_id = data.targetId; | ||
const content = Parser.parseItem(data.content, [ SectionList, ContinuationItem, StructuredDescriptionContent ]); | ||
if (content !== null) { | ||
this.content = content; | ||
} | ||
} | ||
} |
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 { YTNode } from '../helpers.js'; | ||
import { type RawNode } from '../index.js'; | ||
import { Text } from '../misc.js'; | ||
|
||
export default class ExpandableVideoDescriptionBody extends YTNode { | ||
static type = 'ExpandableVideoDescriptionBody'; | ||
|
||
show_more_text: Text; | ||
show_less_text: Text; | ||
attributed_description_body_text: { | ||
content: String | ||
}; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
this.show_more_text = new Text(data.showMoreText); | ||
this.show_less_text = new Text(data.showLessText); | ||
this.attributed_description_body_text = { | ||
content: data.attributedDescriptionBodyText.content | ||
}; | ||
} | ||
} |
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,17 @@ | ||
import { YTNode } from '../helpers.js'; | ||
import { type RawNode } from '../index.js'; | ||
import { Text } from '../misc.js'; | ||
|
||
export default class Factoid extends YTNode { | ||
static type = 'Factoid'; | ||
label: Text; | ||
value: Text; | ||
accessibility_text: String; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
this.label = new Text(data.label); | ||
this.value = new Text(data.value); | ||
this.accessibility_text = data.accessibilityText; | ||
} | ||
} |
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,38 @@ | ||
import { YTNode } from '../helpers.js'; | ||
import Parser, { type RawNode } from '../index.js'; | ||
import { Text } from '../misc.js'; | ||
import NavigationEndpoint from './NavigationEndpoint.js'; | ||
|
||
export default class InfoRow extends YTNode { | ||
static type = 'InfoRow'; | ||
metadata_text?: Text; | ||
metadata_endpoint?: NavigationEndpoint; | ||
info_row_expand_status_key: String; | ||
title: Text; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
if ('defaultMetadata' in data && 'runs' in data.defaultMetadata) { | ||
const runs = data.defaultMetadata.runs; | ||
if (runs.length > 0) { | ||
const run = runs[0]; | ||
this.metadata_text = run?.text; | ||
if ('navigationEndpoint' in run) { | ||
this.metadata_endpoint = Parser.parseItem({ navigationEndpoint: run.navigationEndpoint }, NavigationEndpoint) || undefined; | ||
} | ||
} | ||
} | ||
if ('expandedMetadata' in data && 'runs' in data.expandedMetadata) { | ||
this.metadata_text = new Text(data.expandedMetadata); | ||
} | ||
if (this.metadata_text === undefined) { | ||
this.metadata_text = data.expandedMetadata?.simpleText | ||
? new Text(data.expandedMetadata) | ||
: data.defaultMetadata?.simpleText | ||
? new Text(data.defaultMetadata) | ||
: undefined; | ||
} | ||
this.info_row_expand_status_key = data.infoRowExpandStatusKey; | ||
this.title = new Text(data.title); | ||
} | ||
} |
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,16 @@ | ||
import { type ObservedArray, YTNode } from '../helpers.js'; | ||
import Parser, { type RawNode } from '../index.js'; | ||
import ExpandableVideoDescriptionBody from './ExpandableVideoDescriptionBody.js'; | ||
import VideoDescriptionHeader from './VideoDescriptionHeader.js'; | ||
import VideoDescriptionMusicSection from './VideoDescriptionMusicSection.js'; | ||
|
||
export default class StructuredDescriptionContent extends YTNode { | ||
static type = 'StructuredDescriptionContent'; | ||
|
||
items: ObservedArray<VideoDescriptionHeader|ExpandableVideoDescriptionBody|VideoDescriptionMusicSection>; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
this.items = Parser.parseArray(data.items, [ VideoDescriptionHeader, ExpandableVideoDescriptionBody, VideoDescriptionMusicSection ]); | ||
} | ||
} |
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,29 @@ | ||
import { type ObservedArray, YTNode } from '../helpers.js'; | ||
import Parser, { type RawNode } from '../index.js'; | ||
import { Text } from '../misc.js'; | ||
import type { Thumbnail } from '../misc.js'; | ||
import Factoid from './Factoid.js'; | ||
import NavigationEndpoint from './NavigationEndpoint.js'; | ||
|
||
export default class VideoDescriptionHeader extends YTNode { | ||
static type = 'VideoDescriptionHeader'; | ||
|
||
channel: Text; | ||
channel_navigation_endpoint?: NavigationEndpoint; | ||
channel_thumbnails: String[]; | ||
factoids: ObservedArray<Factoid>; | ||
publish_date: Text; | ||
title: Text; | ||
views: Text; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
this.title = new Text(data.title); | ||
this.channel = new Text(data.channel); | ||
this.channel_navigation_endpoint = Parser.parseItem(data.channelNavigationEndpoint, NavigationEndpoint) || undefined; | ||
this.channel_thumbnails = data.channelThumbnail.thumbnails.map((thumbnail: Thumbnail) => thumbnail.url); | ||
this.publish_date = new Text(data.publishDate); | ||
this.views = new Text(data.views); | ||
this.factoids = Parser.parseArray(data.factoid, Factoid); | ||
} | ||
} |
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,16 @@ | ||
import { type ObservedArray, YTNode } from '../helpers.js'; | ||
import CarouselLockup from './CarouselLockup.js'; | ||
import Parser, { type RawNode } from '../index.js'; | ||
import { Text } from '../misc.js'; | ||
|
||
export default class VideoDescriptionMusicSection extends YTNode { | ||
static type = 'VideoDescriptionMusicSection'; | ||
|
||
carousel_lockups: ObservedArray<CarouselLockup>; | ||
section_title: Text; | ||
constructor(data: RawNode) { | ||
super(); | ||
this.carousel_lockups = Parser.parseArray(data.carouselLockups, CarouselLockup); | ||
this.section_title = new Text(data.sectionTitle); | ||
} | ||
} |
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
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