From b13bf6e9926c19a1939e0f4b69cbd53d1af0f7c8 Mon Sep 17 00:00:00 2001 From: Daniel Wykerd <45672955+Wykerd@users.noreply.github.com> Date: Wed, 15 Mar 2023 23:25:12 +0200 Subject: [PATCH] refactor(Parser)!: general refactoring of parsers (#344) * refactor: move common info into MediaInfo * refactor: better inference on Memo * refactor: improved typesafety in parser methods * refactor: remove PlaylistAuthor in favor of Author * refactor: cleanup live chat parsers - Replace non standard author type with Author class - Remove redundant code * fix: new errors due to changes * fix: pass actions to FormatUtils#toDash * refactor!: merge NavigatableText and Text into single class --- src/Innertube.ts | 4 +- src/core/Feed.ts | 12 +- src/core/MediaInfo.ts | 103 +++++++++++++++ src/parser/classes/AccountItemSection.ts | 2 +- src/parser/classes/AccountSectionList.ts | 4 +- src/parser/classes/BackstagePost.ts | 10 +- src/parser/classes/C4TabbedHeader.ts | 14 +-- src/parser/classes/Channel.ts | 4 +- .../classes/ChannelAboutFullMetadata.ts | 4 +- src/parser/classes/ChannelAgeGate.ts | 2 +- src/parser/classes/ChipCloud.ts | 6 +- src/parser/classes/CompactChannel.ts | 4 +- src/parser/classes/ConfirmDialog.ts | 4 +- src/parser/classes/ConversationBar.ts | 2 +- src/parser/classes/CopyLink.ts | 2 +- src/parser/classes/CreatePlaylistDialog.ts | 4 +- src/parser/classes/DecoratedPlayerBar.ts | 8 +- src/parser/classes/ExpandableMetadata.ts | 6 +- src/parser/classes/GridPlaylist.ts | 6 +- src/parser/classes/GridVideo.ts | 4 +- src/parser/classes/Heatmap.ts | 4 +- src/parser/classes/HorizontalCardList.ts | 8 +- src/parser/classes/InteractiveTabbedHeader.ts | 2 +- src/parser/classes/ItemSection.ts | 2 +- src/parser/classes/ItemSectionTabbedHeader.ts | 2 +- src/parser/classes/LiveChatHeader.ts | 12 +- src/parser/classes/LiveChatItemList.ts | 4 +- src/parser/classes/LiveChatMessageInput.ts | 4 +- .../classes/LiveChatParticipantsList.ts | 4 +- src/parser/classes/MultiMarkersPlayerBar.ts | 8 +- src/parser/classes/MusicCarouselShelf.ts | 6 +- src/parser/classes/MusicShelf.ts | 2 +- src/parser/classes/Playlist.ts | 6 +- src/parser/classes/PlaylistHeader.ts | 6 +- src/parser/classes/PlaylistPanel.ts | 2 +- .../classes/PlaylistPanelVideoWrapper.ts | 4 +- src/parser/classes/PlaylistVideo.ts | 10 +- .../classes/SegmentedLikeDislikeButton.ts | 4 +- src/parser/classes/SettingsOptions.ts | 2 +- src/parser/classes/Shelf.ts | 2 +- src/parser/classes/Tab.ts | 2 +- .../classes/TwoColumnWatchNextResults.ts | 10 +- src/parser/classes/UpsellDialog.ts | 6 +- src/parser/classes/Video.ts | 2 +- src/parser/classes/VideoSecondaryInfo.ts | 4 +- src/parser/classes/WatchNextEndScreen.ts | 2 +- src/parser/classes/comments/Comment.ts | 18 +-- .../classes/comments/CommentActionButtons.ts | 14 +-- src/parser/classes/comments/CommentDialog.ts | 12 +- src/parser/classes/comments/CommentReplies.ts | 6 +- .../classes/comments/CommentReplyDialog.ts | 6 +- .../classes/comments/CommentSimplebox.ts | 6 +- src/parser/classes/comments/CommentThread.ts | 2 +- src/parser/classes/comments/CommentsHeader.ts | 4 +- .../livechat/AddBannerToLiveChatCommand.ts | 4 +- .../livechat/items/LiveChatAutoModMessage.ts | 2 +- .../classes/livechat/items/LiveChatBanner.ts | 4 +- .../livechat/items/LiveChatBannerHeader.ts | 4 +- .../livechat/items/LiveChatMembershipItem.ts | 34 +---- .../livechat/items/LiveChatPaidMessage.ts | 35 +----- .../livechat/items/LiveChatPaidSticker.ts | 33 +---- .../livechat/items/LiveChatTextMessage.ts | 56 ++++----- .../items/LiveChatTickerPaidMessageItem.ts | 35 +----- .../items/LiveChatTickerPaidStickerItem.ts | 57 +-------- .../items/LiveChatTickerSponsorItem.ts | 34 +---- .../items/LiveChatViewerEngagementMessage.ts | 7 +- src/parser/classes/misc/Author.ts | 22 ++-- src/parser/classes/misc/PlaylistAuthor.ts | 12 -- src/parser/classes/ytkids/AnchoredSection.ts | 4 +- .../classes/ytkids/KidsCategoriesHeader.ts | 8 +- src/parser/classes/ytkids/KidsHomeScreen.ts | 4 +- src/parser/helpers.ts | 9 +- src/parser/misc.ts | 1 - src/parser/parser.ts | 74 ++++++----- src/parser/youtube/LiveChat.ts | 5 +- src/parser/youtube/VideoInfo.ts | 118 ++---------------- src/parser/ytkids/VideoInfo.ts | 98 +-------------- src/parser/ytmusic/TrackInfo.ts | 84 ++----------- 78 files changed, 400 insertions(+), 737 deletions(-) create mode 100644 src/core/MediaInfo.ts delete mode 100644 src/parser/classes/misc/PlaylistAuthor.ts diff --git a/src/Innertube.ts b/src/Innertube.ts index 7bbcf7dc..2fd1a2bb 100644 --- a/src/Innertube.ts +++ b/src/Innertube.ts @@ -116,7 +116,7 @@ class Innertube { const continuation = this.actions.execute('/next', payload); const response = await Promise.all([ initial_info, continuation ]); - return new VideoInfo(response, this.actions, this.session.player, cpn); + return new VideoInfo(response, this.actions, cpn); } /** @@ -130,7 +130,7 @@ class Innertube { const cpn = generateRandomString(16); const response = await this.actions.getVideoInfo(video_id, cpn, client); - return new VideoInfo([ response ], this.actions, this.session.player, cpn); + return new VideoInfo([ response ], this.actions, cpn); } /** diff --git a/src/core/Feed.ts b/src/core/Feed.ts index 0a101314..382b8f56 100644 --- a/src/core/Feed.ts +++ b/src/core/Feed.ts @@ -72,7 +72,7 @@ class Feed { * Get all videos on a given page via memo */ static getVideosFromMemo(memo: Memo) { - return memo.getType