diff --git a/YoutubeConfig.json b/YoutubeConfig.json index ec2b420a3a3073ab59504edfa7233e67beb3e2ad..e12796871986c221ac230509652e272c44e67b72 100644 --- a/YoutubeConfig.json +++ b/YoutubeConfig.json @@ -7,7 +7,7 @@ "sourceUrl": "https://plugins.grayjay.app/Youtube/YoutubeConfig.json", "repositoryUrl": "https://futo.org", "scriptUrl": "./YoutubeScript.js", - "version": 165, + "version": 166, "iconUrl": "./youtube.png", "id": "35ae969a-a7db-11ed-afa1-0242ac120002", @@ -124,7 +124,7 @@ }, "authentication": { - "userAgent": "Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.5481.153 Mobile Safari/537.36", + "userAgent": "Mozilla/5.0 (Linux; Android 12) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.230 Mobile Safari/537.36", "completionUrl": "https://m.youtube.com/youtubei/v1/guide?*", "loginUrl": "https://accounts.google.com/ServiceLogin?service=youtube&uilel=3&passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26app%3Ddesktop%26hl%3Den%26next%3Dhttps%253A%252F%252Fwww.youtube.com%252Fchannel_switcher&hl=en&ec=65620", "headersToFind": ["authorization"], diff --git a/YoutubeScript.js b/YoutubeScript.js index b57a6b49a29b5382d4293208526438d46a9ee38e..bfc793864ea5b4c819db0e696361f0611f49b950 100644 --- a/YoutubeScript.js +++ b/YoutubeScript.js @@ -2794,6 +2794,48 @@ function requestCommentPager(contextUrl, continuationToken) { } } } + + if(data?.frameworkUpdates?.entityBatchUpdate?.mutations) { + log("New comments model"); + const mutations = data.frameworkUpdates.entityBatchUpdate.mutations; + if(mutations.length > 0) { + let commentsContinuation = null; + const comments = []; + + let parentItems = []; + for(let i = 0; i < endpoints.length; i++) + parentItems.push(...(endpoints[i].reloadContinuationItemsCommand?.continuationItems ?? + endpoints[i].appendContinuationItemsAction?.continuationItems ?? + [])); + parentItems = parentItems.filter(x=>x.commentThreadRenderer); + const commentObjects = mutations.filter(x=>x?.payload?.commentEntityPayload); + + for(let commentObject of commentObjects) { + const cobj = commentObject?.payload?.commentEntityPayload ?? {}; + const parent = parentItems.find(x=>x.commentThreadRenderer?.commentViewModel?.commentViewModel?.commentKey == commentObject.entityKey); + const replyContents = parent?.commentThreadRenderer?.replies?.commentRepliesRenderer?.contents; + const replyContinuation = ((replyContents?.length ?? 0) > 0) ? replyContents[0].continuationItemRenderer?.continuationEndpoint?.continuationCommand?.token : null; + + const authorEndpoint = cobj.author?.channelCommand?.innertubeCommand?.commandMetadata?.webCommandMetadata?.url; + comments.push(new YTComment({ + contextUrl: contextUrl, + author: new PlatformAuthorLink(new PlatformID(PLATFORM, null, config.id, PLATFORM_CLAIMTYPE), cobj.author.displayName, (authorEndpoint) ? URL_BASE + authorEndpoint : "", cobj.author.avatarThumbnailUrl), + message: cobj.properties?.content?.content ?? "", + rating: new RatingLikes(extractHumanNumber_Integer(cobj.toolbar?.likeCountLiked) ?? 0), + date: (extractAgoTextRuns_Timestamp(cobj?.properties?.publishedTime) ?? 0), + replyCount: extractFirstNumber_Integer(cobj?.toolbar?.replyCount) ?? 0, + context: { replyContinuation: replyContinuation } + })); + } + + + if(comments.length > 0) { + return new YTCommentPager(comments, commentsContinuation, contextUrl); + } + } + } + + log("Comment object:\n" + JSON.stringify(data, null, " ")); throw new ScriptException("No valid comment endpoint provided by Youtube"); }