@@ -152,7 +152,7 @@ class YoutubeParser extends Parser {
152
152
153
153
const videoHTML = new DOMParser ( ) . parseFromString ( response , 'text/html' ) ;
154
154
155
- const declaration = getJavascriptDeclarationByName ( 'ytInitialDataa ' , videoHTML . querySelectorAll ( 'script' ) ) ;
155
+ const declaration = getJavascriptDeclarationByName ( 'ytInitialData ' , videoHTML . querySelectorAll ( 'script' ) ) ;
156
156
const jsonData = typeof declaration !== 'undefined' ? JSON . parse ( declaration . value ) : { } ;
157
157
158
158
const videoSchemaElement = videoHTML . querySelector ( '[itemtype*="http://schema.org/VideoObject"]' ) ;
@@ -177,6 +177,11 @@ class YoutubeParser extends Parser {
177
177
const videoViewsCount =
178
178
jsonData ?. contents ?. twoColumnWatchNextResults ?. results ?. results ?. contents ?. [ 0 ] ?. videoPrimaryInfoRenderer
179
179
?. viewCount ?. videoViewCountRenderer ?. originalViewCount ?? 0 ;
180
+ const channelId =
181
+ jsonData ?. contents ?. twoColumnWatchNextResults ?. results ?. results ?. contents ?. [ 1 ]
182
+ ?. videoSecondaryInfoRenderer ?. subscribeButton ?. subscribeButtonRenderer ?. channelId ??
183
+ videoSchemaElement ?. querySelector ( '[itemprop="channelId"]' ) ?. getAttribute ( 'content' ) ??
184
+ '' ;
180
185
181
186
return {
182
187
date : this . getFormattedDateForContent ( createdAt ) ,
@@ -193,7 +198,7 @@ class YoutubeParser extends Parser {
193
198
videoViewsCount : videoViewsCount ,
194
199
videoTags : '' ,
195
200
videoChapters : this . formatVideoChapters ( videoId , chapters ) ,
196
- channelId : videoSchemaElement ?. querySelector ( '[itemprop=" channelId"' ) ?. getAttribute ( 'content' ) ?? '' ,
201
+ channelId : channelId ,
197
202
channelURL : personSchemaElement ?. querySelector ( '[itemprop="url"]' ) ?. getAttribute ( 'href' ) ?? '' ,
198
203
channelName : personSchemaElement ?. querySelector ( '[itemprop="name"]' ) ?. getAttribute ( 'content' ) ?? '' ,
199
204
extra : null ,
0 commit comments