From fa1ce390e804d5539d2807202a85e2ec053062c5 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Sat, 6 Apr 2024 11:03:59 +0200 Subject: [PATCH] Update NewPipeExtractor --- app/build.gradle | 2 +- .../YouTube/newpipe/GetPlaylistsForChannel.java | 2 +- .../YouTube/newpipe/NewPipeService.java | 6 +++--- .../YouTube/newpipe/NewPipeUtils.java | 17 +++++++++++++++++ .../YouTube/newpipe/PlaylistPager.java | 2 +- .../YouTube/newpipe/VideoPager.java | 4 ++-- .../adapters/CommentsAdapter.java | 3 ++- 7 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c64021820..c8959257b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -176,7 +176,7 @@ dependencies { // implementation 'com.github.SkyTubeTeam.NewPipeExtractor:NewPipeExtractor:818745b7e4' // implementation 'com.github.TeamNewPipe.NewPipeExtractor:NewPipeExtractor:v0.22.6' - implementation 'com.github.SkyTubeTeam.NewPipeExtractor:NewPipeExtractor:a473ed1be8' + implementation 'com.github.SkyTubeTeam.NewPipeExtractor:NewPipeExtractor:skytube-2024-04-06' implementation ('com.github.SkyTubeTeam.components:okhttp-client:0.0.7') { exclude group: 'com.github.SkyTubeTeam.NewPipeExtractor', module: 'extractor' diff --git a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/GetPlaylistsForChannel.java b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/GetPlaylistsForChannel.java index ac2ac4bd6..2523c407f 100644 --- a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/GetPlaylistsForChannel.java +++ b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/GetPlaylistsForChannel.java @@ -71,7 +71,7 @@ private List getNextPlaylists() throws ExtractionException, IOE return infoItems.stream() .filter(PlaylistInfoItem.class::isInstance) .map(PlaylistInfoItem.class::cast).map(item -> - new YouTubePlaylist(item.getUrl(), item.getName(), "", null, item.getStreamCount(), item.getThumbnailUrl(), + new YouTubePlaylist(item.getUrl(), item.getName(), "", null, item.getStreamCount(), NewPipeUtils.getThumbnailUrl(item), channel) ).collect(Collectors.toList()); } diff --git a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/NewPipeService.java b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/NewPipeService.java index 112897313..4f6502217 100644 --- a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/NewPipeService.java +++ b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/NewPipeService.java @@ -339,8 +339,8 @@ private YouTubeChannel createInternalChannel(ChannelExtractor extractor) throws extractor.getId(), extractor.getName(), NewPipeUtils.filterHtml(extractor.getDescription()), - callParser(() -> extractor.getAvatarUrl(), null), - callParser(() -> extractor.getBannerUrl(), null), + callParser(() -> NewPipeUtils.getThumbnailUrl(extractor.getAvatars()), null), + callParser(() -> NewPipeUtils.getThumbnailUrl(extractor.getBanners()), null), callParser(() -> extractor.getSubscriberCount(), -1L), false, 0, @@ -422,7 +422,7 @@ public YouTubeVideo getDetails(String videoId) throws ExtractionException, IOExc YouTubeVideo video = new YouTubeVideo(extractor.getId(), extractor.getName(), NewPipeUtils.filterHtml(extractor.getDescription()), extractor.getLength(), new YouTubeChannel(extractor.getUploaderUrl(), extractor.getUploaderName()), - viewCount, uploadDate.instant, uploadDate.exact, extractor.getThumbnailUrl()); + viewCount, uploadDate.instant, uploadDate.exact, NewPipeUtils.getThumbnailUrl(extractor.getThumbnails())); try { video.setLikeDislikeCount(extractor.getLikeCount(), getDislikeCount(extractor, videoId)); } catch (ParsingException pe) { diff --git a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/NewPipeUtils.java b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/NewPipeUtils.java index fec5f853f..de0f46396 100644 --- a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/NewPipeUtils.java +++ b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/NewPipeUtils.java @@ -16,11 +16,19 @@ */ package free.rm.skytube.businessobjects.YouTube.newpipe; +import androidx.annotation.Nullable; + import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.safety.Safelist; +import org.schabi.newpipe.extractor.Image; +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.extractor.stream.Description; +import java.util.Comparator; +import java.util.List; + public class NewPipeUtils { private NewPipeUtils() {} @@ -38,4 +46,13 @@ public static String filterHtml(Description description) { return result; } + @Nullable + public static String getThumbnailUrl(List images) { + return images.stream().max(Comparator.comparing(Image::getWidth)).map(Image::getUrl).orElse(null); + } + + @Nullable + public static String getThumbnailUrl(InfoItem comment) { + return getThumbnailUrl(comment.getThumbnails()); + } } diff --git a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/PlaylistPager.java b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/PlaylistPager.java index d593bc356..6cb831d93 100644 --- a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/PlaylistPager.java +++ b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/PlaylistPager.java @@ -49,7 +49,7 @@ protected List extract(ListExtractor.InfoItemsPage "" /* description */, null /* publishDate */, playlistExtractor.getStreamCount(), - playlistExtractor.getThumbnailUrl(), + NewPipeUtils.getThumbnailUrl(playlistExtractor.getThumbnails()), new YouTubeChannel(channelId, playlistExtractor.getUploaderName()) ); } catch (ParsingException e) { diff --git a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/VideoPager.java b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/VideoPager.java index e5a83b372..f480514d1 100644 --- a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/VideoPager.java +++ b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/VideoPager.java @@ -110,14 +110,14 @@ protected YouTubeVideo convert(StreamInfoItem item, String id) { } private CardData convert(PlaylistInfoItem playlistInfoItem, String id) { - return new YouTubePlaylist(id, playlistInfoItem.getName(), "", null, playlistInfoItem.getStreamCount(), playlistInfoItem.getThumbnailUrl(), + return new YouTubePlaylist(id, playlistInfoItem.getName(), "", null, playlistInfoItem.getStreamCount(), NewPipeUtils.getThumbnailUrl(playlistInfoItem), null); } private CardData convert(ChannelInfoItem channelInfoItem) { String url = channelInfoItem.getUrl(); String id = getId(url); - return new YouTubeChannel(id, channelInfoItem.getName(), channelInfoItem.getDescription(), channelInfoItem.getThumbnailUrl(), null, + return new YouTubeChannel(id, channelInfoItem.getName(), channelInfoItem.getDescription(), NewPipeUtils.getThumbnailUrl(channelInfoItem), null, channelInfoItem.getSubscriberCount(), false, -1, System.currentTimeMillis(), null, Collections.emptyList()); } diff --git a/app/src/main/java/free/rm/skytube/gui/businessobjects/adapters/CommentsAdapter.java b/app/src/main/java/free/rm/skytube/gui/businessobjects/adapters/CommentsAdapter.java index 6c3b0571c..dfb2774a2 100644 --- a/app/src/main/java/free/rm/skytube/gui/businessobjects/adapters/CommentsAdapter.java +++ b/app/src/main/java/free/rm/skytube/gui/businessobjects/adapters/CommentsAdapter.java @@ -54,6 +54,7 @@ import free.rm.skytube.businessobjects.YouTube.newpipe.CommentPager; import free.rm.skytube.businessobjects.YouTube.newpipe.NewPipeException; import free.rm.skytube.businessobjects.YouTube.newpipe.NewPipeService; +import free.rm.skytube.businessobjects.YouTube.newpipe.NewPipeUtils; import free.rm.skytube.databinding.CommentBinding; import free.rm.skytube.gui.businessobjects.views.Linker; @@ -281,7 +282,7 @@ protected void updateInfo(final CommentsInfoItem comment, boolean isTopLevelComm binding.commentDateTextView.setText(comment.getTextualUploadDate()); binding.commentUpvotesTextView.setText(String.valueOf(comment.getLikeCount())); Glide.with(context) - .load(comment.getThumbnailUrl()) + .load(NewPipeUtils.getThumbnailUrl(comment)) .apply(new RequestOptions().placeholder(R.drawable.channel_thumbnail_default)) .into(binding.commentThumbnailImageView);