|
31 | 31 | import org.schabi.newpipe.extractor.stream.Description; |
32 | 32 | import org.schabi.newpipe.extractor.stream.StreamInfoItem; |
33 | 33 | import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; |
| 34 | +import org.schabi.newpipe.extractor.utils.JsonUtils; |
34 | 35 | import org.schabi.newpipe.extractor.utils.Utils; |
35 | 36 |
|
36 | 37 | import java.io.IOException; |
@@ -61,6 +62,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { |
61 | 62 | private JsonObject playlistHeader; |
62 | 63 |
|
63 | 64 | private boolean isNewPlaylistInterface; |
| 65 | + private Boolean isCoursePlaylist = null; |
64 | 66 |
|
65 | 67 | public YoutubePlaylistExtractor(final StreamingService service, |
66 | 68 | final ListLinkHandler linkHandler) { |
@@ -175,6 +177,31 @@ private JsonObject getPlaylistHeader() { |
175 | 177 | return playlistHeader; |
176 | 178 | } |
177 | 179 |
|
| 180 | + private Boolean isCoursePlaylist() { |
| 181 | + if (isCoursePlaylist == null) { |
| 182 | + try { |
| 183 | + isCoursePlaylist = JsonUtils.getArray(getPlaylistHeader(), |
| 184 | + "onDescriptionTap.commandExecutorCommand.commands") |
| 185 | + .stream() |
| 186 | + .filter(JsonObject.class::isInstance) |
| 187 | + .map(JsonObject.class::cast) |
| 188 | + .anyMatch(object -> { |
| 189 | + try { |
| 190 | + final String tag = JsonUtils.getString(object, |
| 191 | + "showEngagementPanelEndpoint.identifier.tag"); |
| 192 | + return tag.equals("engagement-panel-course-metadata"); |
| 193 | + } catch (final ParsingException e) { |
| 194 | + return false; |
| 195 | + } |
| 196 | + }); |
| 197 | + System.out.println(isCoursePlaylist); |
| 198 | + } catch (final Exception e) { |
| 199 | + isCoursePlaylist = false; |
| 200 | + } |
| 201 | + } |
| 202 | + return isCoursePlaylist; |
| 203 | + } |
| 204 | + |
178 | 205 | @Nonnull |
179 | 206 | @Override |
180 | 207 | public String getName() throws ParsingException { |
@@ -420,30 +447,28 @@ private Page getNextPageFrom(final JsonArray contents) |
420 | 447 | private void collectStreamsFrom(@Nonnull final StreamInfoItemsCollector collector, |
421 | 448 | @Nonnull final JsonArray videos) { |
422 | 449 | final TimeAgoParser timeAgoParser = getTimeAgoParser(); |
| 450 | + final PlaylistExtractor playlistExtractor = this; |
423 | 451 | videos.stream() |
424 | 452 | .filter(JsonObject.class::isInstance) |
425 | 453 | .map(JsonObject.class::cast) |
426 | 454 | .forEach(video -> { |
427 | 455 | if (video.has(PLAYLIST_VIDEO_RENDERER)) { |
428 | | - final PlaylistExtractor playlistExtractor = this; |
429 | 456 | collector.commit(new YoutubeStreamInfoItemExtractor( |
430 | 457 | video.getObject(PLAYLIST_VIDEO_RENDERER), timeAgoParser) { |
431 | 458 | @Override |
432 | 459 | public String getUploaderName() throws ParsingException { |
433 | | - try { |
434 | | - return super.getUploaderName(); |
435 | | - } catch (final ParsingException e) { |
| 460 | + if (isCoursePlaylist()) { |
436 | 461 | return playlistExtractor.getUploaderName(); |
437 | 462 | } |
| 463 | + return super.getUploaderName(); |
438 | 464 | } |
439 | 465 |
|
440 | 466 | @Override |
441 | 467 | public String getUploaderUrl() throws ParsingException { |
442 | | - try { |
443 | | - return super.getUploaderUrl(); |
444 | | - } catch (final ParsingException e) { |
| 468 | + if (isCoursePlaylist()) { |
445 | 469 | return playlistExtractor.getUploaderUrl(); |
446 | 470 | } |
| 471 | + return super.getUploaderUrl(); |
447 | 472 | } |
448 | 473 | }); |
449 | 474 | } else if (video.has(RICH_ITEM_RENDERER)) { |
|
0 commit comments