@@ -234,19 +234,19 @@ private String getDurationTextFromOverlay(@Nonnull final JsonObject overlay) {
234234
235235 @ Override
236236 public String getUploaderName () throws ParsingException {
237- final JsonArray metadataRows = lockupMetadataViewModel .getObject ("metadata" )
238- .getObject ("contentMetadataViewModel" )
239- .getArray ("metadataRows" );
237+ final JsonObject navigationEndpoint = getUploaderNavigationEndpoint ();
238+ if (navigationEndpoint != null && navigationEndpoint .has ("showDialogCommand" )) {
239+ final String uploaderName = getFirstContributorName (navigationEndpoint );
240+ if (!isNullOrEmpty (uploaderName )) {
241+ return uploaderName ;
242+ }
243+ }
240244
241- if (metadataRows .size () > 0 ) {
242- final JsonArray metadataParts = metadataRows .getObject (0 ).getArray ("metadataParts" );
243- if (metadataParts .size () > 0 ) {
244- final String uploaderName = metadataParts .getObject (0 )
245- .getObject ("text" )
246- .getString ("content" );
247- if (!isNullOrEmpty (uploaderName )) {
248- return uploaderName ;
249- }
245+ final JsonObject uploaderText = getUploaderText ();
246+ if (uploaderText != null ) {
247+ final String uploaderName = uploaderText .getString ("content" );
248+ if (!isNullOrEmpty (uploaderName )) {
249+ return uploaderName ;
250250 }
251251 }
252252
@@ -255,13 +255,85 @@ public String getUploaderName() throws ParsingException {
255255
256256 @ Override
257257 public String getUploaderUrl () throws ParsingException {
258- return getUrlFromNavigationEndpoint (
259- lockupMetadataViewModel .getObject ("image" )
260- .getObject ("decoratedAvatarViewModel" )
261- .getObject ("rendererContext" )
262- .getObject ("commandContext" )
263- .getObject ("onTap" )
264- .getObject ("innertubeCommand" ));
258+ final JsonObject navigationEndpoint = getUploaderNavigationEndpoint ();
259+ if (navigationEndpoint != null ) {
260+ final String uploaderUrl = getUrlFromNavigationEndpoint (navigationEndpoint );
261+ if (!isNullOrEmpty (uploaderUrl )) {
262+ return uploaderUrl ;
263+ }
264+ }
265+
266+ throw new ParsingException ("Could not get uploader url" );
267+ }
268+
269+ @ Nullable
270+ private JsonObject getUploaderText () {
271+ final JsonArray metadataRows = lockupMetadataViewModel .getObject ("metadata" )
272+ .getObject ("contentMetadataViewModel" )
273+ .getArray ("metadataRows" );
274+
275+ if (metadataRows .isEmpty ()) {
276+ return null ;
277+ }
278+
279+ final JsonArray metadataParts = metadataRows .getObject (0 ).getArray ("metadataParts" );
280+ if (metadataParts .isEmpty ()) {
281+ return null ;
282+ }
283+
284+ return metadataParts .getObject (0 ).getObject ("text" );
285+ }
286+
287+ @ Nullable
288+ private JsonObject getUploaderNavigationEndpoint () {
289+ final JsonObject image = lockupMetadataViewModel .getObject ("image" );
290+ if (image == null || image .isEmpty ()) {
291+ return null ;
292+ }
293+
294+ if (image .has ("decoratedAvatarViewModel" )) {
295+ return image .getObject ("decoratedAvatarViewModel" )
296+ .getObject ("rendererContext" )
297+ .getObject ("commandContext" )
298+ .getObject ("onTap" )
299+ .getObject ("innertubeCommand" );
300+ }
301+
302+ if (image .has ("avatarStackViewModel" )) {
303+ return image .getObject ("avatarStackViewModel" )
304+ .getObject ("rendererContext" )
305+ .getObject ("commandContext" )
306+ .getObject ("onTap" )
307+ .getObject ("innertubeCommand" );
308+ }
309+
310+ return null ;
311+ }
312+
313+ @ Nullable
314+ private String getFirstContributorName (final JsonObject navigationEndpoint ) {
315+ try {
316+ final JsonArray listItems = navigationEndpoint
317+ .getObject ("showDialogCommand" )
318+ .getObject ("panelLoadingStrategy" )
319+ .getObject ("inlineContent" )
320+ .getObject ("dialogViewModel" )
321+ .getObject ("customContent" )
322+ .getObject ("listViewModel" )
323+ .getArray ("listItems" );
324+
325+ if (listItems == null || listItems .isEmpty ()) {
326+ return null ;
327+ }
328+
329+ final String uploaderName = listItems .getObject (0 )
330+ .getObject ("listItemViewModel" )
331+ .getObject ("title" )
332+ .getString ("content" , "" );
333+ return isNullOrEmpty (uploaderName ) ? null : uploaderName ;
334+ } catch (final Exception ignored ) {
335+ return null ;
336+ }
265337 }
266338
267339 @ Override
@@ -408,14 +480,50 @@ public boolean requiresMembership() throws ParsingException {
408480 @ Override
409481 public String getUploaderAvatarUrl () throws ParsingException {
410482 try {
411- return lockupMetadataViewModel .getObject ("image" )
412- .getObject ("decoratedAvatarViewModel" )
413- .getObject ("avatar" )
414- .getObject ("avatarViewModel" )
415- .getObject ("image" )
416- .getArray ("sources" )
417- .getObject (0 )
418- .getString ("url" );
483+ final JsonObject navigationEndpoint = getUploaderNavigationEndpoint ();
484+ if (navigationEndpoint != null && navigationEndpoint .has ("showDialogCommand" )) {
485+ final JsonArray sources = navigationEndpoint
486+ .getObject ("showDialogCommand" )
487+ .getObject ("panelLoadingStrategy" )
488+ .getObject ("inlineContent" )
489+ .getObject ("dialogViewModel" )
490+ .getObject ("customContent" )
491+ .getObject ("listViewModel" )
492+ .getArray ("listItems" )
493+ .getObject (0 )
494+ .getObject ("listItemViewModel" )
495+ .getObject ("leadingAccessory" )
496+ .getObject ("avatarViewModel" )
497+ .getObject ("image" )
498+ .getArray ("sources" );
499+ if (!sources .isEmpty ()) {
500+ return sources .getObject (0 ).getString ("url" );
501+ }
502+ }
503+
504+ final JsonObject image = lockupMetadataViewModel .getObject ("image" );
505+ if (image .has ("decoratedAvatarViewModel" )) {
506+ return image .getObject ("decoratedAvatarViewModel" )
507+ .getObject ("avatar" )
508+ .getObject ("avatarViewModel" )
509+ .getObject ("image" )
510+ .getArray ("sources" )
511+ .getObject (0 )
512+ .getString ("url" );
513+ }
514+
515+ if (image .has ("avatarStackViewModel" )) {
516+ return image .getObject ("avatarStackViewModel" )
517+ .getArray ("avatars" )
518+ .getObject (0 )
519+ .getObject ("avatarViewModel" )
520+ .getObject ("image" )
521+ .getArray ("sources" )
522+ .getObject (0 )
523+ .getString ("url" );
524+ }
525+
526+ return null ;
419527 } catch (final Exception e ) {
420528 return null ;
421529 }
0 commit comments