-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser): Support new like and dislike nodes (#557)
- Loading branch information
Showing
6 changed files
with
132 additions
and
0 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,16 @@ | ||
import { YTNode } from '../helpers.js'; | ||
import { Parser, type RawNode } from '../index.js'; | ||
import ToggleButtonView from './ToggleButtonView.js'; | ||
|
||
export default class DislikeButtonView extends YTNode { | ||
static type = 'DislikeButtonView'; | ||
|
||
toggle_button: ToggleButtonView | null; | ||
dislike_entity_key: string; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
this.toggle_button = Parser.parseItem(data.toggleButtonViewModel, ToggleButtonView); | ||
this.dislike_entity_key = data.dislikeEntityKey; | ||
} | ||
} |
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,24 @@ | ||
import { YTNode } from '../helpers.js'; | ||
import { Parser, type RawNode } from '../index.js'; | ||
import ToggleButtonView from './ToggleButtonView.js'; | ||
|
||
export default class LikeButtonView extends YTNode { | ||
static type = 'LikeButtonView'; | ||
|
||
toggle_button: ToggleButtonView | null; | ||
like_status_entity_key: string; | ||
like_status_entity: { | ||
key: string, | ||
like_status: string | ||
}; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
this.toggle_button = Parser.parseItem(data.toggleButtonViewModel, ToggleButtonView); | ||
this.like_status_entity_key = data.likeStatusEntityKey; | ||
this.like_status_entity = { | ||
key: data.likeStatusEntity.key, | ||
like_status: data.likeStatusEntity.likeStatus | ||
}; | ||
} | ||
} |
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,56 @@ | ||
import { YTNode } from '../helpers.js'; | ||
import { Parser, type RawNode } from '../index.js'; | ||
import LikeButtonView from './LikeButtonView.js'; | ||
import DislikeButtonView from './DislikeButtonView.js'; | ||
|
||
export default class SegmentedLikeDislikeButtonView extends YTNode { | ||
static type = 'SegmentedLikeDislikeButtonView'; | ||
|
||
like_button: LikeButtonView | null; | ||
dislike_button: DislikeButtonView | null; | ||
icon_type: string; | ||
like_count_entity: { | ||
key: string | ||
}; | ||
dynamic_like_count_update_data: { | ||
update_status_key: string, | ||
placeholder_like_count_values_key: string, | ||
update_delay_loop_id: string, | ||
update_delay_sec: number | ||
}; | ||
|
||
like_count?: number; | ||
short_like_count?: string; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
this.like_button = Parser.parseItem(data.likeButtonViewModel, LikeButtonView); | ||
this.dislike_button = Parser.parseItem(data.dislikeButtonViewModel, DislikeButtonView); | ||
this.icon_type = data.iconType; | ||
|
||
if (this.like_button && this.like_button.toggle_button) { | ||
const toggle_button = this.like_button.toggle_button; | ||
|
||
if (toggle_button.default_button) { | ||
this.short_like_count = toggle_button.default_button.title; | ||
|
||
this.like_count = parseInt(toggle_button.default_button.accessibility_text.replace(/\D/g, '')); | ||
} else if (toggle_button.toggled_button) { | ||
this.short_like_count = toggle_button.toggled_button.title; | ||
|
||
this.like_count = parseInt(toggle_button.toggled_button.accessibility_text.replace(/\D/g, '')); | ||
} | ||
} | ||
|
||
this.like_count_entity = { | ||
key: data.likeCountEntity.key | ||
}; | ||
|
||
this.dynamic_like_count_update_data = { | ||
update_status_key: data.dynamicLikeCountUpdateData.updateStatusKey, | ||
placeholder_like_count_values_key: data.dynamicLikeCountUpdateData.placeholderLikeCountValuesKey, | ||
update_delay_loop_id: data.dynamicLikeCountUpdateData.updateDelayLoopId, | ||
update_delay_sec: data.dynamicLikeCountUpdateData.updateDelaySec | ||
}; | ||
} | ||
} |
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 ButtonView from './ButtonView.js'; | ||
|
||
export default class ToggleButtonView extends YTNode { | ||
static type = 'ToggleButtonView'; | ||
|
||
default_button: ButtonView | null; | ||
toggled_button: ButtonView | null; | ||
identifier?: string; | ||
is_toggling_disabled: boolean; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
this.default_button = Parser.parseItem(data.defaultButtonViewModel, ButtonView); | ||
this.toggled_button = Parser.parseItem(data.toggledButtonViewModel, ButtonView); | ||
this.identifier = data.identifier; | ||
this.is_toggling_disabled = data.isTogglingDisabled; | ||
} | ||
} |
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